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

Revision history [back]

click to hide/show revision 1
initial version

EDIT: If I add a small delay before the goal_publisher.publish(goal) line then the message gets published.

This is something that has come up many times and that makes me wonder whether we should add this to the wiki about Publishers and Subscibers in some form.

Setting up connections between publishers and subscibers takes time. Subscibers connect to publishers directly, not to the Master, nor does the Master buffer messages, so even if you start your subscriber before your publisher there is a non-zero amount of time needed for the two to connect.

If there are no connections, any message you publish will be dropped and won't reach anyone.

In your publisher program, you don't give any potentially interested subscribers any time to set up a connection, so it is most likely your PoseStamped message is dropped.

You have two options:

  1. publish the message periodically (so that even if there are no subscribers now, they'll receive one of the later messages published to the topic). That may or may not be appropriate for what you're trying to do (ie: for some messages / interactions it doesn't make sense to duplicate the same message)
  2. wait for subscribers to connect. With your edit you've already done that, but you did it time based. It's always nicer to do things state based, which in this case means: look at the nr of subscribers and if there is at least one (or any other number) then publish your message. You can use Topic::get_num_connections for that in rospy.