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

Find which node published in a topic in ros2

asked 2022-12-14 05:29:11 -0600

fernando gravatar image

I have a program where multiple nodes publish to the same topic. Is there a way to know which Node write which message? Or is there a way to echo just the messages sent by a certain node?

Example: Node1, Node2 and Node3 publish to Topic. How I can just read the messages written by Node1 in Topic (without reading the ones sent by Node 2 and Node3)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-12-14 08:24:44 -0600

ljaniec gravatar image

updated 2022-12-14 08:27:38 -0600

As far as I know, there is no such option - but you can achieve a similar result with a custom message composed of NodeID and original message.

Other approach like filtering based on the timestamps or headers can "work", but it will be unreliable and quite messy.

Related Q&A:

edit flag offensive delete link more


I agree with @ljaniec - the correct design is that you put some kind of sender_id in the message.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-12-14 10:37:23 -0600 )edit

I would suggest to take a step back and ask yourself why there is an apparent need to know the identity of the publisher of a message. It seems to go against the idea of anonymous publish-subscribe.

I've seen people state they must know the identity of the sender, while in reality they wanted to filter messages based on some other characteristic (such as the location of a specific sensor). There would be better ways to achieve those kind of things than looking at node identities.

gvdhoorn gravatar image gvdhoorn  ( 2022-12-14 13:03:30 -0600 )edit

Question Tools


Asked: 2022-12-14 05:29:11 -0600

Seen: 399 times

Last updated: Dec 14 '22