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

Revision history [back]

As in the comment:

Maybe is it a problem of ROS spinning? Can you add a few ros::spinOnce(); and ros::Duration(1).sleep(); in the code? You should also wait to send the first point to travel until every publisher/subscriber is set up correctly.

It is connected with e.g. this question "What is first ? Publisher or Subscriber?"

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

and its answers:

  • "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 initial messages. It just wasn't there to listen."

  • "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 when 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)."