Can lost time when using 'waitfor(rate)' function be used for other tasks?
1 view (last 30 days)
Show older comments
The 'rosrate' object can be used to contol the rate of execution of a block of code. This is typically done by including the code in a loop and invoking the 'waitfor(rate)' function to insert delays to achieve the target rate of execution. Can the time delay be used to execute other parts of the code?
0 Comments
Accepted Answer
Cam Salzberger
on 4 Jan 2021
Hello Mohan,
Generally the way to use rosrate is to put it at the end of a "control loop" - code that you execute every iteration. In this way, the "waitfor" will act as a sort of "sponge" - any remaining time left over after you've run all the code you want to run will be absorbed in rosrate. There currently isn't any kind of "while waiting, run this low-priority code, but kill it if it hits the wait limit" functionality.
One thing to note is that rosrate can be treated similiarly to a simple "pause". If you have code that runs on a timer or as part of a callback, this code will continue executing even while the main program is "paused". The same thing can apply to rosrate. So if you want to have some code running in that background that continues while waitfor is waiting, you could work up some kind of callback.
-Cam
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!