How can i execute a ROS2 node every 10 milli second
I have a ROS2 node in Python which is integrated with a simulation tool.
The simulation tool runs with a timestep of 10ms.
The ROS2 node first subscribes the data from the simulation tool and then publishes some control signals based on the subscribed messages (both on different topics)
For both systems to work efficiently, there timesteps should be same.
How can I make a ROS2 node execute every 10ms.
One way is using a timer_callback. But is there some alternative where i must not explicitly call the timer function for publishing and subscribing seperately and ask the node to execure at a certain time interval.
Just to confirm you're asking how to execute a block of code within a node exactly 100 times per second? You'd never want start a new node instances 100 times per secondĀ¬
Yes. You are correct. As explained, I would like to subscribe it after 10ms and publish it immediately
The rate at which you receive messages is determined by the publishing node not the receiving node. At what rate are messages being published by the simulation tool?
Yes. True. The simulation tool publishes messages at 10ms(100Hz) which is subscribed by ROS2.Calcultion based on these messges in ROS2 and then publishes the messages which is then subscribed by the simulation tool. So it works in the loop.
So if you subscribe to the messages from the simulator and process and publish the response within this callback it sounds as if it will have achieved what you want. No timers required. Am I missing something?
Unfortunately i am not publishing it within the callback. I am publishing it seperately.
Is there a reason why your not publishing it within the callback because that would solve this problem?
I'm with @PeteBlackerThe3rd: @aks: if you're looking for some sort of synchronisation with your simulation, then wouldn't publishing the response as part of processing the incoming msg immediately result in the desired behaviour?