def execute(self, userdata):
global waypoints
self.initialize_path_queue()
self.path_ready = False
# Start thread to listen for when the path is ready (this function will end then)
def wait_for_path_ready():
"""thread worker function"""
data = rospy.wait_for_message('/path_ready', Empty)
rospy.loginfo('Recieved path READY message')
self.path_ready = True
ready_thread = threading.Thread(target=wait_for_path_ready)
ready_thread.start()
topic = "/initialpose"
rospy.loginfo("Waiting to recieve waypoints via Pose msg on topic %s" % topic)
rospy.loginfo("To start following waypoints: 'rostopic pub /path_ready std_msgs/Empty -1'")
# Wait for published waypoints
while not self.path_ready:
try:
pose = rospy.wait_for_message(topic, PoseWithCovarianceStamped, timeout=1)
except rospy.ROSException as e:
if 'timeout exceeded' in e.message:
continue # no new waypoint within timeout, looping...
else:
raise e
rospy.loginfo("Recieved new waypoint")
waypoints.append(pose)
# publish waypoint queue as pose array so that you can see them in rviz, etc.
self.poseArray_publisher.publish(convert_PoseWithCovArray_to_PoseArray(waypoints))
# Path is ready! return success and move on to the next state (FOLLOW_PATH)
return 'success'
评论列表
文章目录