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

Does a node receive messages sent by itself on a topic that it is both publishing and subscribing to?

asked 2016-04-30 04:21:31 -0500

luketheduke gravatar image

updated 2022-02-22 11:26:51 -0500

lucasw gravatar image

I am working on writing some code for a project, but I have a node that will be continuously publishing(30 Hz) to a topic while also subscribing to the same topic to listen for a different pub from a different node. Basically, node A is listening to topic X and publishing to topic X. Meanwhile another node, node B, will at some time, publish a message to topic X. Will the subscriber callback in node A be triggered every time it publishes sometime? Also, will it be able to pick up the message if node B only publishes once? Thanks, luketheduke

edit retag flag offensive close merge delete

Comments

May I suggest a title change? Your question seems to be really about whether a node receives its own messages if it publishes on a topic it also subscribes to. You can't actually 'receive callbacks', just messages.

gvdhoorn gravatar image gvdhoorn  ( 2016-05-01 01:29:16 -0500 )edit

Thanks for the suggestion! It's changed.

luketheduke gravatar image luketheduke  ( 2016-05-01 13:30:07 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
5

answered 2016-04-30 04:33:39 -0500

If a node publishes on a topic and also has a subscriber for it, it will receive "it's own" message. This is a feature, as components in the publish/subscribe system should not need to care about where a message originates from.

Even though this probably is best avoided, you can check for the origin of a message using the MessageEvent mechanism (e.g. if it originates from the same node) as in this example.

edit flag offensive delete link more

Comments

Thanks for the quick reply!

luketheduke gravatar image luketheduke  ( 2016-04-30 04:42:51 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-30 04:21:31 -0500

Seen: 1,836 times

Last updated: May 01 '16