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

How to get the publisher name from a received message in rospy?

asked 2011-06-21 07:03:52 -0600

pparescasellas gravatar image

Hey everybody,

I can't find anywhere how to get the publisher name from a received message using python. In C++ I just have to do the following:

void
callback( const ros::MessageEvent< cola2_common::BhResponse const >& event )
{
    const std::string& publisher_name = event.getPublisherName() ;
}

What's the equivalent in python? Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2011-06-21 07:12:47 -0600

bhaskara gravatar image

updated 2017-08-02 15:08:54 -0600

gvdhoorn gravatar image

See here:

http://www.ros.org/wiki/rospy/Overvie...


Edit (by @jayess ):

Just so you don't have to go clicking around for the answer (from @bhaskara's link):

A subscriber can get access to a "connection header", which includes debugging information such as who sent the message, as well information like whether or not a message was latched. This data is stored as the _connection_header field of a received message.

e.g.

print m._connection_header
{'callerid': '/talker_38321_1284999593611',
 'latching': '0',
 'md5sum': '992ce8a1687cec8c8bd883ec73ca41d1',
 'message_definition': 'string data\n\n',
 'topic': '/chatter',
 'type': 'std_msgs/String'}

We do not recommend using callerid information beyond debugging purposes, as it can lead to brittle code in an anonymous publish/subscribe architecture.

edit flag offensive delete link more

Comments

@jayess: I've merged your additional answer with the one by @bhaskara.

gvdhoorn gravatar image gvdhoorn  ( 2017-08-02 15:09:28 -0600 )edit

@gvdhoorn, great. Even better than two answers.

jayess gravatar image jayess  ( 2017-08-02 15:53:06 -0600 )edit

Question Tools

Stats

Asked: 2011-06-21 07:03:52 -0600

Seen: 2,172 times

Last updated: Aug 02 '17