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
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);
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2013-04-21 08:49:44 -0600
Seen: 14,015 times
Last updated: Apr 21 '13
Publisher/Subscriber Node for Arduino Sensor Data
fail to publish to a different message type
Begginer Tutorial Publisher/Subscriber Server/Client in C++ boost assertion failed
Intermittent subscription to a topic with/without timer possible?
No output received for subscriber program
Python Publisher and C++ Subscriber problem
Dynamically resolve message type and subscribe to topic at runtime in roscpp ?