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

rospy publisher and subscriber in the same node, filter out "own" messages

asked 2016-04-11 10:24:48 -0500

peci1 gravatar image

Hey ROS folks

I have a node in Python, in which I subscribe to a topic, and I also want to simultaneously publish on it. And this node is not the only one doing that. In the subscriber, I want to filter out messages which are generated by my node.

Is there any API/package to do that?

In C++, I can imagine publishing/subscribing shared pointers, remembering a few last published messages, and comparing the memory address of the received message with the remembered addresses.

In Python, this is obviously not possible. Or is it?

If the messages have Header fields in them, it might be possible to filter them based on timestamp. Unfortunately, my messages do not have a header, and I can't alter the message definition.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-04-11 10:52:46 -0500

lucasw gravatar image

updated 2016-04-11 11:07:04 -0500

How about looking at the _connection_header callerid [Publishers and Subscribers] shown in ( ) ?

It says 'We do not recommend using callerid information beyond debugging purposes, as it can lead to brittle code in an anonymous publish/subscribe architecture.'- but it seems like you could reliably get the name of your own node- I did a check and rospy.get_name() and callerid do match up when publishing and subscribing to the same topic in the same node.

edit flag offensive delete link more


Thanks! Exactly what I was looking for.

peci1 gravatar image peci1  ( 2016-04-11 11:15:32 -0500 )edit

Question Tools



Asked: 2016-04-11 10:24:48 -0500

Seen: 529 times

Last updated: Apr 11 '16