topic name inside the callback
Hi, I use callback (python) like:
def callback(self,data):
print data
topic = data._connection_header['topic']
this call back is called for more than one subscriber alternatively. I am interested to know which topic is currently calling the callback. I use data._connection_header['topic']
to get the name of the topic. I don't know for some topics I get their name but for some not. Like when callback is invoked for topic /scan
I get error like:
[ERROR] [WallTime: 1362483495.362445] bad callback: <bound method Generator.callback of <__main__.Generator object at 0x31435d0>>
Traceback (most recent call last):
File "/opt/ros/fuerte/lib/python2.7/dist-packages/rospy/topics.py", line 678, in _invoke_callback
cb(msg)
File "/home/my_workspace/my_pkg/src/callback.py", line 21, in callback
topic = data._connection_header['topic']
KeyError: 'topic'
Any Idea? Or is there any other solution for knowing which topic is calling the callback? thanks
I just tried this out and the only keys I get are ['message_definition', 'latching', 'md5sum', 'type', 'callerid']. I'm going to have to put the topic information into a text field because topic doesn't work unfortunately.