0

I want to make a subscriber subscribe to two topics synchronously. I am following through the tutorial implementing a publisher and a subscriber in ROS2 C++ (in Linux Ubuntu). The tutorial only shows how to let a subscriber subscribe 1 topic, but how about two topics at the same time?

For example, how do I modify the code from the tutorial such that the subscriber takes in an integer from a topic and another integer from another topic (at the same time) and add those two values as an output.

Thank you.

1 Answers1

1

Each ros::Subscriber subscribes to one topic and has one callback function. You can create as many subscribers as you need. The callback functions can be regular functions or class methods. For more details, see the ROS Subscriber API.

Nejc Galof
  • 2,538
  • 3
  • 31
  • 70