[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

TaskmanagerIo tasks in an array RSS feed
Forum Index » IoAbstraction & TaskManagerIO
Author Message
werner


Joined: Feb 23, 2022
Messages: 4
Offline
Hi,
how can I add TaskmanagerIo tasks in an array ?
I have an array of classes which includes a function controlValve().
I have tried this :

thisPiControl=PiControl[picIdx];
               
       taskIdPiControl[picIdx] = taskManager.scheduleFixedRate(VdmConfig.configFlash.valvesControlConfig.valveControlConfig[picIdx].ts*1000, [] {
                    UART_DBG.println("pic call");
                    thisPiControl.controlValve();
                });


But the call is always the same index of the class.

best regards
Werner
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
I think you've misunderstood C++ memory model here.

If thisPiControl is a global variable, then changing it changes it for every task.
However, if thisPiControl is a local variable, you're lucky the sketch hasn't crashed as you'd be accessing memory that no longer had the same purpose as it did before.

If you are using a 32 bit board that support std::function, you can enable lamba support at the cost of your tasks using a bit more memory. Given it has memory side effects it needs to be enabled by setting the compiler flag TM_ENABLE_CAPTURED_LAMBDAS. With this enabled you could capture thisPiControl each time.

The other option without needing that support is to write your tasks as classes extending from Executable, or use ExecWithParameter.

All of these are covered within the examples.
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
For your case, I would make all those classes extend Executable, and implement the exec() method, the examples show how to do this. Basically for scheduling, you just then pass a pointer to your class instance instead.
werner


Joined: Feb 23, 2022
Messages: 4
Offline
I have tried this according your example:
class CPiControl: public Executable
{
public:
  CPiControl();
  float piCtrl(float e);
  .....
}

extern CPiControl PiControl[ACTUATOR_COUNT];


But the compiler shows an error : an array of an abstract class is not allowed
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
That example is incomplete. If the class is abstract it means in this case you have not implemented the methods required by the Executable interface.

You will need to implement exec() on that class; which will be called on the schedule.
werner


Joined: Feb 23, 2022
Messages: 4
Offline
Thx, it works
 
Forum Index » IoAbstraction & TaskManagerIO
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.