0
$\begingroup$

Rosanswers logo

My problem is simple: I have several topics of the same message type. I want to subscribe to all of them and have them all point to the same callback method. Since I want to have access to the topic name in the callback, I am using boost::bind:

topicSubs.push_back(nh_.subscribe<nav_msgs::Odometry>(odomTopic, 1, boost::bind(&MyClass::odometryCallback, this, _1, odomTopicName)));

I loop through the list of topic names in my launch file and make the above call for each. topicSubs is a member variable vector, so the subscriber object isn't going out of scope. If I subscribe to only one topic, the callback is successfully called for that topic. If I subscribe to two, I only get the second. In other words, it only actually subscribes to the last topic I call subscribe on. Does ROS internally do some kind of one-to-one mapping between topic types and callbacks, or is there clearly some kind of error in how I'm handling the subscription?

I already verified that the topic names are correct for each subscription. I looked for similar issues, but didn't find anything that answered this. I apologize in advance if this was answered before.

EDIT: Responding to a comment. My launch file looks like this:

<param name="odom0" value="odomTopicA"/>
<param name="odom1" value="odomTopicB"/>

The user can specify an arbitrary number of topics in the form of "odomX". The code to load them just creates string streams, appends the value (0, 1, etc.) and then grabs that parameter from the launch file. I've verified that the correct names are being loaded, and clearly subscribing works, but only for the last subscriber that gets pushed back.


Originally posted by Tom Moore on ROS Answers with karma: 13689 on 2013-08-01

Post score: 0


Original comments

Comment by thebyohazard on 2013-08-01:
Nope, I use one cb for multiple subscribers in quite a few of my nodes, so it's definitely possible. Could you explain what you mean by "loop through the list of topic names in my launch file"?

Comment by Tom Moore on 2013-08-01:
See edit. If it works for you, then it must be something else I'm doing. Do you know if the use of boost::bind is a problem, or are you also using it?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Ah, I wasn't watching rosbag. It was telling me that a topic that I thought was one type was actually another. It works now. Thanks!


Originally posted by Tom Moore with karma: 13689 on 2013-08-01

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.