如何知道move_base到达目标点
时间: 2023-04-10 14:03:25 浏览: 281
您可以使用move_base的SimpleActionClient来检查机器人是否已经到达目标点。您可以使用以下代码:
```python
import rospy
import actionlib
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
rospy.init_node('check_goal_reached')
client = actionlib.SimpleActionClient('move_base', MoveBaseAction)
client.wait_for_server()
goal = MoveBaseGoal()
goal.target_pose.header.frame_id = 'map'
goal.target_pose.pose.position.x = 1.0
goal.target_pose.pose.position.y = 2.0
goal.target_pose.pose.orientation.w = 1.0
client.send_goal(goal)
client.wait_for_result()
if client.get_state() == actionlib.GoalStatus.SUCCEEDED:
print("Goal reached!")
else:
print("Goal not reached.")
```
这个代码将机器人移动到(1,2)的位置,然后检查是否已经到达目标点。如果机器人已经到达目标点,它将打印“Goal reached!”,否则它将打印“Goal not reached.”。
阅读全文