ROS-noetic中MoveBase导航功能包参数设置
move_base是ros中关于机器人路径规划的功能包,通过订阅激光雷达、map地图、amcl等位数据等,然后规划处全局和全局路径,再将路径转换为机器人的速度信息,最终实现机器人导航。
1. move_base的框架
move_base主要由amcl、map_server、goal_planner、local_planner、recovery_behaviors、global_costmap以及loc_costmap等组成构成。在本博客中我们仅简单介绍各个组件的功能,具体内容可以参考:
https://blog.youkuaiyun.com/xtark_robot/article/details/115207212
- amcl里程计(adaptive Monte Corlo Locatization),可为机器人提供定位服务;
- map_server作为服务节点,可以为机器人提供地图数据;
- goal_planner全局路径规划器,move_base提供了常见的Dijsktra以及 A*算法,需要自己配置;
- local_planner局部路径规划器,move_base中提供了常用的DWA, Teb算法,同样需要自己根据需求进行配置;
- recovery_behaviors动作恢复机制,在机器人发生碰撞后会尝试通过recovery_behaviors恢复之前的运动,这部分move_base提供conservative_reset, move_slow_and_clear, clear_rotation等恢复行为,此外还可以自己定义恢复行为插件;
- global_costmap全局代价地图,为全局路径规划提供参考;
- local_costmap路径代价地图,为局部路径规划提供参考,关于global_costmap和local_costmap可参考:https://blog.youkuaiyun.com/JDWell/article/details/88359098
2. 参数配置 Dijsktra+DWA
1. move_base通过launch文件启动,具体如下
<node pkg="move_base" type="move_base" respawn="false" name="move_base_node" >
<remap from="map" to="/map" />
<rosparam file="$(find park_project)/configs/costmap_common_params.yaml" command="load" ns="global_costmap" />
<rosparam file="$(find park_project)/configs/costmap_common_params.yaml" command="load" ns="local_costmap" />
<rosparam file="$(find park_project)/configs/local_costmap_params.yaml" command="load" />
<rosparam file="$(find park_project)/configs/global_costmap_params.yaml" command="load" />
<rosparam file="$(find park_project)/configs/move_base_params.yaml" command="load" />
<rosparam file="$(find park_project)/configs/dwa_local_planner_params.yaml" command="load" />
<rosparam file="$(find park_project)/configs/global_planner_params.yaml" command="load" />
<!-- <rosparam file="$(find park_project)/configs/base_local_planner_params.yaml" command="load" /> -->
<param name="global_costmap/robot_base_frame" value="$(arg robot_id)/base_link"/>
<param name="local_costmap/global_frame" value="$(arg robot_id)/odom"/>
<param name="local_costmap/robot_base_frame" value="$(arg robot_id)/base_link"/>
</node>
需要加载move_base功能包并导入各个参数配置,这里需要注意的是我的代码是在多机器人仿真环境下的,在使用的时候需要注意一下命名空间的设置。
2. costmap_common_params.yaml
footprint: [[-0.2, -0.2], [-0.2, 0.2], [0.2, 0.2], [0.2, -0.2]]
footprint_padding: 0.1
costmap_common_params是指global_costmap和local_costmap共同参数配置,这里你可以配置膨胀层、静态层以及障碍物层的一些参数。但是由于在我的代码中有些参数配置不一样,这里只定义了机器人的大小参数。其余参数分别在global_costmap_params.yaml以及local_costmap_params.yaml给出参数配置。
3. local_costmap_params.yaml
local_costmap:
global_frame: odom
robot_base_frame: base_link
update_frequency: 5.0
publish_frequency: 0.0
# static_map: false
rolling_window: true
width: 8.0
height: 8.0
resolution: 0.08
transform_tolerance: 0.5
#障碍物层
obstacle_layer:
enabled: true
obstructed_range: 5
raytrace_range: 5.5
max_obstacle_height: 2.0
unknown_threshold: 15
mark_threshold: 0
combination_method: 1
track_unknown_space: true
# origin_z: 0.0
# z_resolution: 0.2
# z_voxels: 2
publish_voxel_map: false
observation_sources: base_scan
base_scan:
data_type: LaserScan
topic: base_scan
marking: true
clearing: true
min_obstacle_height: 0.0
max_obstacle_height: 2.0
inf_is_valid: true
#膨胀层
inflation_layer:
enabled: true
cost_scaling_factor: 2.58 # 由于在公式中cost_scaling_factor被乘了一个负数,所以增大比例因子反而会降低代价 (default: 10)#2.58
inflation_radius: 0.40 # 代价膨胀半径 (default: 0.55) #0.4
plugins:
- {name: obstacle_layer, type: "costmap_2d::ObstacleLayer"}
- {name: inflation_layer, type: "costmap_2d::InflationLayer"}
需要注意的是,如果使用plugins插件,一定要把static_map: false注释掉,不然会报warm。此外,local_costmap不需要考虑静态层。在local_costmap_params.yaml文件中你可以配置inflation_layer和obstacle_layer的参数,设置动态窗口的大小(width*height),动态窗口越大,仿真速度越快,但是对计算资源要求会更高。
4. global_costmap_params.yaml
global_costmap:
global_frame: map
robot_base_frame: base_link
update_frequency: 5.0 #全局地图,通常会设定一个相对较小、在1.0到5.0之间的值。 单位为赫兹
publish_frequency: 0 #对于静态的全局地图来说,不需要不断发布
transform_tolerance: 0.5
#障碍物层
obstacle_layer:
enabled: true
obstructed_range: 5
raytrace_range: 5.5
max_obstacle_height: 2.0
unknown_threshold: 15
mark_threshold: 0
combination_method: 1
track_unknown_space: true
origin_z: 0.0
z_resolution: 0.2
z_voxels: 2
publish_voxel_map: false
observation_sources: base_scan
base_scan:
data_type: LaserScan
topic: base_scan
marking: true
clearing: true
min_obstacle_height: 0.0
max_obstacle_height: 2.0
inf_is_valid: true
#膨胀层
inflation_layer:
enabled: true
cost_scaling_factor: 2.58 # 由于在公式中cost_scaling_factor被乘了一个负数,所以增大比例因子反而会降低代价 (default: 10)
inflation_radius: 1.0 # 代价膨胀半径 (default: 0.55)
#静态层
static_layer:
enabled: true
plugins:
- {name: static_layer, type: "costmap_2d::StaticLayer"}
- {name: obstacle_layer, type: "costmap_2d::VoxelLayer"}
- {name: inflation_layer, type: "costmap_2d::InflationLayer"}
global_costmap需要加载static_layer。
5. move_base_params.yaml
shutdown_costmaps: false
controller_frequency: 5.0
planner_frequency: 5.0
controller_patience: 10.0
planner_patience: 15.0
oscillation_timeout: 10.0
oscillation_distance: 0.2
conservative_reset_dist: 3.0
base_global_planner: "global_planner/GlobalPlanner"
base_local_planner: "dwa_local_planner/DWAPlannerROS"
recovery_behavior_enabled: true #是否启动恢复机制
clearing_rotation_allowed: false #是否启动旋转的恢复,必须是recovery_behavior_enabled在使能的基础上才能生效
recovery_behaviors: # 自恢复行为
- name: 'conservative_reset'
type: 'clear_costmap_recovery/ClearCostmapRecovery'
- name: "stepback_recovery"
type: "stepback_recovery/StepbackRecovery"
- name: 'move_slow_and_clear'
type: 'move_slow_and_clear/MoveSlowAndClear'
- name: 'clearing_rotation'
type: 'rotate_recovery/RotateRecovery'
#保守清除,用户指定区域之外的障碍物将从机器人地图中清除
conservative_reset:
reset_distance: 0.5
layer_names: [obstacle_layer]
#另一种恢复行为,需要注意该行为只能与具有动态设置速度限制功能的局部路径规划器适配,例如dwa
move_slow_and_clear:
clearing_distance: 1.0
limited_trans_speed: 0.1
limited_rot_speed: 0.4
limited_distance: 1
planner_namespace: "DWAPlannerROS"
controller_frequency 为底盘控制频率,planner_frequency为规划频率,base_global_planner选择使用的全局规划器,base_local_planner选择使用的局部规划器,recovery_behavior_enabled是否启动恢复机制,clearing_rotation_allowed是否启动旋转恢复机制。stepback_recovery是我自定义的,可忽略。
6. global_planner_params.yaml
GlobalPlanner:
allow_unknown: false
default_tolerance: 0.2 #目标容差
visualize_potential: false
use_dijkstra: true
use_quadratic: true
use_grid_path: false
old_navfn_behavior: true ########
lethal_cost: 253 #致命代价值,默认是设置为253,可以动态来配置该参数.
neutral_cost: 55 #中等代价值,默认设置是50,可以动态配置该参数.
cost_factor: 3 #代价地图与每个代价值相乘的因子 #3
publish_potential: true #是否发布costmap的势函数.
orientation_mode: 0
orientation_window_size: 1
allow_unknown是否允许穿过未知区域;visualize_potential是否可视化势函数;use_dijkstra:true采用dijkstra算法作为全局路径规划器,false采用A*;old_navfn_behavior必要的时候是否采用原始的navfn导航。
7. dwa_local_planner_params.yaml
DWAPlannerROS:
max_vel_trans: 3.0
min_vel_trans: 0.01
max_vel_x: 3.0 #maximum linear speed
min_vel_x: -3.0 #minimum linear speed
max_vel_y: 0
min_vel_y: 0
max_theta_vel: 5 #maximum rotate speed
min_theta_vel: -5 #minimum rotate speed
acc_lim_x: 20.0 #maximum linear acceleration in x
acc_lim_y: 0
acc_lim_theta: 20.0 #maximum rotational acceleration
acc_lim_trans: 20.0
prune_plan: true #whether to clear the trajectory 1m behind it
xy_goal_tolerance: 0.1
yaw_goal_tolerance: 0.05
trans_stopped_vel: 0.1
theta_stopped_vel: 0.1
latch_xy_goal_tolerance: false #设置为true,如果到达容错距离内,机器人就会原地旋转,即使转动是会跑出容错距离外.
#Forward Simulation Parameters
sim_time: 1.5 #simluation time 1.2
sim_granularity: 0.02 #resolution of the simulation in meters 0.02
angular_sim_granularity: 0.025 #smaller values result in a finer granularity
vx_samples: 20 #number of samples to use when exploring the forward velocities space
vy_samples: 0 #number of samples to use when exploring the sideways velocities space
vth_samples: 40 #number of samples to use when exploring the angular velocities space
controller_frequency: 10 #controller frequency in Hz
#Trajectory Scoring Parameters
path_distance_bias: 32.0 #weight for the path distance cost function
goal_distance_bias: 10.0 #weight for the goal distance cost function
occdist_scale: 0.30 #scaling factor for the maximum distance from an obstacle allowed for the robot to be considered in collision. The value should typically be between 0 and 1. A lower value will make the robot more conservative in terms of collision avoidance.#0.02 #定义控制器躲避障碍物的程度
forward_point_distance: 0.325 #the distance threshold to create a new point in meters 0.325
stop_time_buffer: 0.2 #the buffer time to prevent robot from rotating between forward and backward in seconds
scaling_speed: 0.25 #the scaling factor for the robot's velocity
max_scaling_factor: 0.2 #the maximum scaling factor for the robot's velocity
#Oscillation Prevention Parameters
oscillation_reset_dist: 0.05
oscillation_reset_angle: 0.2
use_dwa: true
restore_defaults: true
上述代码仅供参考,本人ROS新手,有问题欢迎大家一起探讨,后续有时间可能会更新具体参数配置问题。