Unable to publish PoseStamped message
I am trying to publish a PoseStamped
message via a node running in Python. I am listening for this message on another tab in my terminal.
Python node:
import rospy
from geometry_msgs.msg import PoseStamped
rospy.init_node("mynode")
goal_publisher = rospy.Publisher("move_base_simple/goal", PoseStamped, queue_size=5)
goal = PoseStamped()
goal.header.seq = 1
goal.header.stamp = rospy.Time.now()
goal.header.frame_id = "map"
goal.pose.position.x = 1.0
goal.pose.position.y = 2.0
goal.pose.position.z = 0.0
goal.pose.orientation.x = 0.0
goal.pose.orientation.y = 0.0
goal.pose.orientation.z = 0.0
goal.pose.orientation.w = 1.0
goal_publisher.publish(goal)
rospy.spin()
So this my order of doing things:
- In the first tab of terminal run
roscore
- In the second tab run
rostopic echo /move_base_simple/goal
- In the third tab run the Python node which publishes a message
However no message is printed in the 2nd tab. What am I doing wrong? I am not getting any error messages.
EDIT: If I add a small delay before the goal_publisher.publish(goal)
line then the message gets published.
rospy.sleep(1)
goal_publisher.publish(goal)