ros2_documentation icon indicating copy to clipboard operation
ros2_documentation copied to clipboard

Tutorial on the use of timers and publisher callbacks

Open IamPhytan opened this issue 3 years ago • 3 comments
trafficstars

Hello,

I recently had to migrate a motor driver node in ROS2, where the node:

  • subscribes to Twist messages from a teleop node
  • publishes a Odometry message at a higher frequency than the Twist messages

After searching extensively, I found out that there were not a lot of online examples that had this kind of publish-subscribe with different frequencies, as most examples have subscriber callback functions that publish messages in the body of the function.

My colleagues and I finally found out that we could use a publish method as a timer callback, and I think it could be great to add a tutorial on the use of timers for that, as it is a problem that is fairly common. Here is an example node that I made in order to find solutions to our problem.

Thanks

IamPhytan avatar Nov 03 '22 20:11 IamPhytan

https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html#write-the-publisher-node has an example of using publish in a timer callback. Is that enough of an example?

clalancette avatar Nov 04 '22 12:11 clalancette

Yes, it's a good example for using a publish in a timer callback But what about an example for republishing ? It's kinda common to have a node that subscribes to some topics and republishes on other topics.

Such kind of republishing node could be part of ros2/demos instead

IamPhytan avatar Nov 08 '22 14:11 IamPhytan

IMO, I would like to keep examples and demos as simple as possible to how to call or demonstrate ROS 2 APIs or Features, not so much related to how to write the application.

fujitatomoya avatar Nov 08 '22 18:11 fujitatomoya