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

Revision history [back]

You can pass extra argument to a callback function, I think you could pass the topic_name. See this from the Subscriber Class:

class Subscriber Found at: rospy.topics

class Subscriber(Topic):
"""
Class for registering as a subscriber to a specified topic, where
the messages are of a given type.
"""
def __init__(self, name, data_class, callback=None, callback_args=None, 
    queue_size=None, buff_size=DEFAULT_BUFF_SIZE, tcp_nodelay=False):
    """
    [...]

    @param callback_args: additional arguments to pass to the
      callback. This is useful when you wish to reuse the same
      callback for multiple subscriptions.

You With rospy, you can pass extra argument to a callback function, I think you could pass the topic_name. See this from the Subscriber Class:

class Subscriber Found at: rospy.topics

class Subscriber(Topic):
"""
Class for registering as a subscriber to a specified topic, where
the messages are of a given type.
"""
def __init__(self, name, data_class, callback=None, callback_args=None, 
    queue_size=None, buff_size=DEFAULT_BUFF_SIZE, tcp_nodelay=False):
    """
    [...]

    @param callback_args: additional arguments to pass to the
      callback. This is useful when you wish to reuse the same
      callback for multiple subscriptions.

I think with roscpp something similar exists