Multiple Subscribers in one Cpp file.
Can I subscribe to multiple topics / multiple callbacks (declaring callbacks as member functions inwith one publisher in ROS C++ code
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Can I subscribe to multiple topics / multiple callbacks (declaring callbacks as member functions inwith one publisher in ROS C++ code
It's perfectly acceptable to subscribe to multiple topics and/or publish to multiple topics from within the same ROS node. Each topic publisher or subscriber will have its own ros::Publisher or ros::Subscriber object, and each subscriber will probably have its own callback function (though this is not strictly required).
See here for a mroe detailed description of publishers/subscribers in C++.
Note that subscriber callbacks are generally called by background ROS threads. If you use the default node setup shown in most examples (using ros::spin), all callbacks are called from a single thread. See here for a more detailed explanation of multi-threaded usage of roscpp, if that's important for your application.
Edit:
Whoops! Sorry for the double-answer. I'll leave this here, in case any of this info is helpful.
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
hi
i write a multi subscriber and one publisher in on cpp, but my publish speed is verry slow... how can i fix it ???
you can increase the publishing rate by reducing the number ros::Publisher pub = nh.advertise<std_msgs::string>("topic_name", 5);
Asked: 2013-04-21 08:49:44 -0600
Seen: 18,755 times
Last updated: Apr 21 '13
Subscriber and Publisher node at once in cpp
subscribe and publish in the same class
How do I publish exactly one message?
Which ways of communicating with a controller are real-time safe?
basic question in understanding publishing and subscribing
Programmatically get ModelState from Gazebo
Problem using subscribed motor position topic