jacknlliu / development-issues

Some issues from my development
MIT License
7 stars 1 forks source link

rospy publisher publishing not work immediately after creation #74

Open jacknlliu opened 5 years ago

jacknlliu commented 5 years ago
pub = rospy.Publisher("my_topic_name", String)
msg = String()
msg.data = "Open"
pub.publish(msg)

the above code will not work in which the publisher only publishing once after the publisher creation.

Solution:

rospy.sleep(2.0) msg = String() msg.data = "Open" pub.publish(msg)



> You should design your nodes in a way that they either do not rely on each message to arrive or consider using latched topics to at least get the last message when the connections is established after it was initially published. —— https://github.com/ros/ros_comm/issues/176#issuecomment-13930136

## Reference
- [rospy.Publisher.publish() should wait for the publisher to be ready #286](https://github.com/ros/ros_comm/issues/286)
- [Publishing message immediately after topic creation with rospy is never sent. #176](https://github.com/ros/ros_comm/issues/176)
- [When is it safe to publish after declaring a rospy.Publisher?](https://answers.ros.org/question/107521/when-is-it-safe-to-publish-after-declaring-a-rospypublisher/)