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

Revision history [back]

click to hide/show revision 1
initial version

There is no guarantee that the connection header you're trying to use will have a topic, however, you can work around this by passing the topic name to the callback function as an argument when you set up the subscriber.

For example:

def callback(self,data,topic):
    #do something with the topic
    print data

and then when you hook up your subscriber, do it like this:

rospy.Subscriber(my_topic,My_data_type,callback = callback_odom, callback_args =  my_topic)

For some reason, passing it as a lambda function, i.e.:

rospy.Subscriber(my_topic,My_data_type,lambda top: callback_odom(top, my_topic))

doesn't work.

There is no guarantee that the connection header you're trying to use will have a topic, however, you can work around this by passing the topic name to the callback function as an argument when you set up the subscriber.

For example:

def callback(self,data,topic):
callback(self, data, topic):
 #do # do something with the topic
    print data

and then when you hook up your subscriber, do it like this:

rospy.Subscriber(my_topic,My_data_type,callback = callback_odom, callback_args =  my_topic)
rospy.Subscriber(my_topic, My_data_type, callback=callback_odom, callback_args=my_topic)

For some reason, passing it as a lambda function, i.e.:

rospy.Subscriber(my_topic,My_data_type,lambda rospy.Subscriber(my_topic, My_data_type, lambda top: callback_odom(top, my_topic))

doesn't work.