Hi,
I'm would like to set up two loops at different frequencies on a system (like raspberry pi3). I'm trying to decide the optimal way to set up my code with the least latency in data transfer between the two loops and least computation. Here are two options I thought of,
Two different ros-nodes each with different loop rates and using ros-msgs to communicate between these loops. -With the ros-nodes options, the loop rates are pretty consistent but there is latency in the data transfer.
A class with two functions run at different loop rates using ros::Timers. Class variables used to transfer the data between the functions. -Using the ros::Timers, even though no latency in the data transfer, loop rates are not quite consistent.
What is the better option, or are there any other better options? Is multi-threading a better option?
Also, it is possible to share data between two ros-nodes without using rosmsgs/rosservice but by sharing variables/pointers between them?
Thank you
- prasanth
Originally posted by praskot on ROS Answers with karma: 257 on 2019-07-07
Post score: 1
Original comments
Comment by gvdhoorn on 2019-07-08:
To avoid an xy-problem: what is it that you actually want to do (ie: why do you feel you need "two loops at different frequencies")?
Comment by PeteBlackerThe3rd on 2019-07-08:
I would have thought a single node with two timers and multi-threaded spinner would be best. You'd have to make sure your mutexes were setup sensibly so that blocking didn't effect your loop rate too much.
Comment by praskot on 2019-07-08:
@gvdhoorn: I'm setting up a control architecture with two-different loops, an inner loop running (high frequency) and an outer loop (with lower frequency).
@PeteBlackerThe3rd: thank you, will give it a try.
Comment by gvdhoorn on 2019-07-08:
In that case, you might want to consider a single loop with a divider for the lower-frequency one.
That would avoid: scheduling jitter due to multi-threading, use of locks, potential for aliasing and some other complexities that come with multithreading.
But it all depends on what the frequencies and the data-dependencies are.
Comment by praskot on 2019-07-08:
I am looking at 100-200Hz for outer loop and 800-1000Hz for the inner loop.