是用于向move_base节点发送目标点位置信息的消息类型,包含目标点的位置和姿态信息。当move_base节点收到该消息后,会规划机器人的路径并执行导航任务,到达目标点

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import rospy
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
import actionlib
 
def move_to_goal(x, y):
    # Initialize node
    rospy.init_node('move_to_goal', anonymous=False)
 
    # Create a MoveBaseAction object
    move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction)
 
    # Wait for the action server to come up
    while not move_base.wait_for_server(rospy.Duration(5)):
        rospy.loginfo("Waiting for move_base action server...")
 
    # Define a goal
    goal = MoveBaseGoal()
    goal.target_pose.header.frame_id = "map"
    goal.target_pose.pose.position.x = x
    goal.target_pose.pose.position.y = y
    goal.target_pose.pose.orientation.w = 1.0
 
    # Send the goal and wait for completion
    move_base.send_goal(goal)
    move_base.wait_for_result()
 
    # Print the result
    if move_base.get_state() == actionlib.GoalStatus.SUCCEEDED:
        rospy.loginfo("Goal reached!")
        return True
    else:
        rospy.loginfo("Failed to reach goal.")
        return False
 
if __name__ == '__main__':
    try:
        move_to_goal(1.0, 2.0) # Set the goal position x and y coordinates
    except rospy.ROSInterruptException:
        pass

  它接收x和y坐标参数,并将这些坐标作为目标位置发送给move_base节点。具体来说,我们通过创建一个MoveBaseAction对象,然后在其中设置我们的目标位置信息。接下来,我们使用move_base.send_goal函数将目标位置发送给move_base节点。等待机器人完成目标位置时,我们使用move_base.wait_for_result函数,等待move_base节点返回一个结果。最后,我们检查返回的结果来确认机器人是否到达目标位置

 

posted on   黑逍逍  阅读(811)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!



点击右上角即可分享
微信分享提示