Ask Your Question

Revision history [back]

To summarise the discussion, if you can ensure that the inner loops frequency will be an integer factor of the outer loops frequency then the solution recommended by @gvdhoorn is the best way to go, it will ensure timing is always consistent. If you cannot ensure an integer factor then using two timers and a multi-threaded spinner, this will be able to keep the timing more consistent than a single thread.

You will need to ensure that mutexes do not block access to any shared memory areas for too long or they may throw off the timing accuracy by delaying one of the timer callbacks.

To answer your final question, there is no mechanism I know of for two ros nodes (separate OS processes) to communicate via shared pointers. However ROS nodelets were designed for exactly this purpose, they are essentially plugin objects that can be loaded and run by the nodelet manager meaning they are executing within the same process so can share the same memory space. ROS will automatically take advantage of this to accelerate message passing. However in your case nodelets would be an overly complicated solution, I'd recommend a single node instead.

Hope this makes sense.