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

What is first ? Publisher or Subscriber?

asked 2021-08-03 02:00:39 -0600

Dhanaprakaash gravatar image

Which among the following nodes should be started first? Publisher or Subscriber.

What happens if start subscriber first then publisher?

Note: Subscriber is working as intended (printing the received message) when started after publisher. But it misses receiving initial messages. And, When the subscriber is started first, It doesn’t work as intended.

edit retag flag offensive close merge delete

Comments

2

What do you mean "it doesn't work as intended" when the subscriber is started first?

Jaron gravatar image Jaron  ( 2021-08-03 08:39:04 -0600 )edit

2 Answers

Sort by » oldest newest most voted
4

answered 2021-08-03 05:01:15 -0600

dornhege gravatar image

In general it should not matter. You can start publishers and subscribers at any time.

However, note that ROS is expecting messages as a constant message stream, e.g., like from a sensor. They are not buffered in some central instance.

This explains why it misses receiving inital messages. It just wasn't there to listen.

Also note that nodes take a short time to start up and connect in the background. If you start a publisher, publish 1 message, and quit. In the very short time that this code runs, in the background your node is talking to the master trying to connect to a subscriber. This won't happen until your node has already quit.

Either wait until the number of subscribers on your publisher is > 0. Or use a service or something that is meant to be used for that.

edit flag offensive delete link more
2

answered 2021-08-03 08:51:24 -0600

Jaron gravatar image

This is a common topic in IPC (interprocess communication). In general, the publish/subscribe model can be thought of like a radio broadcast where there is some time between initialization of a node and when it is functional. If you start the publisher first, then there will be a brief period of time where the node is broadcasting messages and the subscriber is not able to listen yet as it hasn't initialized fully. This can technically still happen with the subscriber starting first as the initialization time is not the same for publisher and subscribers (depends on implementation).

If you need a guarantee of successful delivery, then you should look into QoS for ROS2 DDS. There is a "reliability" setting where you can make this possible.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-08-03 02:00:39 -0600

Seen: 795 times

Last updated: Aug 03 '21