Calling publisher at a specific rate
Hi,
I have a node that subscribes to a topic, does some computation and publishes the message on a different topic. The publish is implemented within subscriber callback function.
While the subscribed topic arrives at a different rate (and hence the callback), I would like to publish at a specific rate (100Hz). My implementation is in C++ and I am running Kinetic on Ubuntu 16.04. Please let me know the best way to handle this
thank you
Thank you I have couple of follow-up questions
I am publishing within the subscriber callback (when I receive a topic, I call a callback, do some computation and publishing within the callback itself). How do I not modify the subscriber loop rate, but only change the publisher rate? Adding ros::Rate in main will affect both subscriber and publisher?
On using timer, what should be the timeCallback? If I use the subscriber callback for this, this will not subscribe to a topic at a rate it is arriving which is different than my publisher's required rate
There are several ways you can do that: Enclose the subscriber in the spin loop:
or set a Timer to publish every 100secs: