[ros-users] How to identify the subscriber or the topic name related to a callback

Markus Bader markus.bader at tuwien.ac.at
Mon Jan 31 13:46:04 UTC 2011


Hello

I have multiple subscriber calling the same callback function. How can
I determinate within my callback function the related topic name?
getPublisherName gives me the related publisher but not the topic?


for (unsigned int i = 0; i < topics.size(); i++) {
        sub[i] = n_.subscribe(topics[i], 1000, &MyClass::callback, this);
}

void callback(const ros::MessageEvent<std_msgs::String const>& event)
{
  const std::string& publisher_name = event.getPublisherName();
  #Here comes the problem
  const std::string& topic_name = event.?????????();
}

Thanks
Markus



More information about the ros-users mailing list