ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Several subscriptions pointing to one callback

asked 2013-08-01 04:21:20 -0600

Tom Moore gravatar image

updated 2013-08-01 04:38:03 -0600

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.

edit retag flag offensive close merge delete

Comments

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"?

thebyohazard gravatar image thebyohazard  ( 2013-08-01 04:28:50 -0600 )edit

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?

Tom Moore gravatar image Tom Moore  ( 2013-08-01 04:40:05 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-08-01 04:48:57 -0600

Tom Moore gravatar image

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!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-08-01 04:21:20 -0600

Seen: 682 times

Last updated: Aug 01 '13