Skip to content

rospy publisher publishing not work immediately after creation #74

Open
@jacknlliu

Description

@jacknlliu
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:

  • add latch=True when create the publisher
pub = rospy.Publisher("my_topic_name", String, latch=True)
msg = String()
msg.data = "Open"
pub.publish(msg)
  • add sleep seconds after creation
pub = rospy.Publisher("my_topic_name", String)

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. —— ros/ros_comm#176 (comment)

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions