#这段代码的作用是实现在地图中随机导航。在ros下需要先加载机器人和相关配置,详请参阅 古-月 的博客http://blog.csdn.net/hcx25909/article/details/12110959
#这里主要是用于自己来理解这段代码
#!/usr/bin/env python
import rospy
import actionlib
from actionlib_msgs.msg import *
from geometry_msgs.msg import Pose, PoseWithCovarianceStamped, Point, Quaternion, Twist
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
from random import sample
from math import pow, sqrt
class NavTest():
def __init__(self):
rospy.init_node('nav_test', anonymous=True)
rospy.on_shutdown(self.shutdown)#rospyAPI:on_shutdown()
# How long in seconds should the robot pause at each location?
#在每个目标点停留的时间
self.rest_time = rospy.get_param("~rest_time", 10)#API get_param
# Are we running in the fake simulator?
#是否是在模拟环境中运行
self.fake_test = rospy.get_param("~fake_test", False)
# Goal state return values
#目标状态返回值
goal_states = ['PENDING', 'ACTIVE', 'PREEMPTED',
'SUCCEEDED', 'ABORTED', 'REJECTED',
'PREEMPTING', 'RECALLING', 'RECALLED',
'LOST']
# Set up the goal locations. Poses are defined in the map frame.
#设置目标位置,在地图坐标系中的姿态
# An easy way to find the pose coordinates is to point-and-click
#找到某一姿态的坐标,选中然后单击
# Nav Goals in RViz when running in the simulator.
#
# Pose coordinates are then displayed in the terminal
# that was used to launch RViz.
locations = dict()
#这里定义了六个定位点的姿态
locations['hall_foyer'] = Pose(Point(0.643, 4.720, 0.000), Quaternion(0.000, 0.000, 0.223, 0.975))
locations['hall_kitchen']