Dear community,
- When the robot has done a complete lap, it has to finish and return the list of odometry recorded
How can we stop the robot? Where should define it?
For easier debugging, I uploaded the package to a github repo, here is the link.
Once finishing a lap, I break the goal_callback loop in the action server, define is_goal_successful
method in the action client class, and stop the robot in the odom_monitor_thread
method in the wall_follower.py.
However, it still cannot be stopped.
Another question regarding the action section:
I separate the moving logic and client/server logic, use the main thread for the wall_follow movement and the 2nd thread for monitoring the feedback from the record odom action server, is that the correct way to do the task?
Thanks a lot for your help!
Here are relevant functions:
def goal_callback(self, goal):
rospy.loginfo(f"Action server {self.name} has been called")
self._recorder.start_recording()
success = True
while not rospy.is_shutdown():
if self._as.is_preempt_requested():
rospy.loginfo(f"Action server {self.name} is preempted")
self._as.set_preempted()
success = False
self._recorder.stop_recording()
return
self._feedback.current_total = self._recorder.get_total_distance()
self._as.publish_feedback(self._feedback)
# Check if the robot has completed a lap
if self._recorder.has_completed_lap():
rospy.loginfo("Lap completed, need to stop the robot")
break
self.rate.sleep()
def is_goal_successful(self):
state_result = self.client.get_state()
rate = rospy.Rate(10)
if state_result == GoalStatus.SUCCEEDED:
rospy.loginfo("Goal is completed successfully")
return True
else:
return False
def odom_monitor_thread(self, action_client, wall_follower):
rate = rospy.Rate(1)
while not rospy.is_shutdown():
if action_client.is_goal_successful():
rospy.loginfo("Goal has been completed for a lap, stop the robot...")
wall_follower.stop()
break
rate.sleep()
result = action_client.check_goal_status()
rospy.loginfo(f"Recording finished with result: {result}")