ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
As @gvdhoorn and @knxa noted, this is expected behavior (though perhaps surprising), because the advertise() call returns before the subscriber has made the socket connection to the publisher (which takes maybe 300ms).
If you are writing a command-line app that has to publish something to a listener that is already running, there are two things you have to do:
Insert the following code snippet between advertise() and publish()
while (0 == chatter_pub.getNumSubscribers()) { ROS_INFO("Waiting for subscribers to connect"); ros::Duration(0.1).sleep(); }
Call ros::shutdown before your program exits, to flush the published message to the subscriber
2 | No.2 Revision |
As @gvdhoorn and @knxa noted, this is expected behavior (though perhaps surprising), because the advertise() call returns before the subscriber has made the socket connection to the publisher (which takes maybe 300ms).
If you are writing a command-line app that has to publish something to a listener that is already running, there are two things you have to do:
while (0 == chatter_pub.getNumSubscribers()) { ROS_INFO("Waiting for subscribers to connect"); ros::Duration(0.1).sleep(); }
3 | No.3 Revision |
As @gvdhoorn and @knxa noted, this is expected behavior (though perhaps surprising), because the advertise() call returns before the subscriber has made the socket connection to the publisher (which takes maybe 300ms).
If you are writing a command-line app that has to publish something to a listener that is already running, there are two things you have to do:
while (0 == chatter_pub.getNumSubscribers()) { ROS_INFO("Waiting for subscribers to connect"); ros::Duration(0.1).sleep(); }
4 | No.4 Revision |
As @gvdhoorn and @knxa noted, this is expected behavior (though perhaps surprising), because the advertise() call returns before the subscriber has made the socket connection to the publisher (which takes maybe 300ms).
If you are writing a command-line app that has to publish something to a listener that is already running, there are two things you have to do:
while (0 == chatter_pub.getNumSubscribers()) {
ROS_INFO("Waiting for subscribers to connect");
ros::Duration(0.1).sleep();