Node synchronization
I have several instances of the same node (type A) which execute their code at a predefined common frequency using ros::Timer
structures. Each node publishes a message on a common topic every time the timer triggers (after simple computation). A different node (type B) is subscribed to that topic and has the purpose of gathering those messages together and send them back on another topic where all the other nodes are subscribed to.
This is a quick overview of my system and I can't change this configuration because it is mimicking a hardware implementation.
Now the question: the createTimer(ros::Duration(rate), timerCallback)
method sets up the loop frequency, but how to synchronize all the timers to trigger at about the same time (e.g. from 12:00:00.000 forever every 100 ms)? Normally, the time depends on the instant on which the method is called and this could be considerably different in a multi-thread environment.
To solve the problem I have thought about a remarkable delay in each constructor to make it wake up at a specific time and then initialize the timer. Of course I have to wait for some natural deadline, e.g. hh:mm:s0.000 or something similar. I do not need a perfect synchronization, do you think that this could be enough? Does still exist something to synchronize nodes? I have already looked at message_filters/approximate_time_policy
but it works with distinct topics and I have all the messages on the same one.
Thank you all.