重要參考:
課程鏈接:https://www.bilibili.com/video/BV1Ci4y1L7ZZ
講義鏈接:Introduction · Autolabor-ROS機器人入門課程《ROS理論與實踐》零基礎教程
?
9.3.5 導航實現05_路徑規劃
路徑規劃仍然使用 navigation 功能包集中的 move_base 功能包。
5.1編寫launch文件
關于move_base節點的調用,模板如下:
<launch><node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen" clear_params="true"><rosparam file="$(find nav)/param/costmap_common_params.yaml" command="load" ns="global_costmap" /><rosparam file="$(find nav)/param/costmap_common_params.yaml" command="load" ns="local_costmap" /><rosparam file="$(find nav)/param/local_costmap_params.yaml" command="load" /><rosparam file="$(find nav)/param/global_costmap_params.yaml" command="load" /><rosparam file="$(find nav)/param/base_local_planner_params.yaml" command="load" /></node></launch>
5.2編寫配置文件
可參考仿真實現。
1.costmap_common_params.yaml
該文件是move_base 在全局路徑規劃與本地路徑規劃時調用的通用參數,包括:機器人的尺寸、距離障礙物的安全距離、傳感器信息等。配置參考如下:
#機器人幾何參,如果機器人是圓形,設置 robot_radius,如果是其他形狀設置 footprint
robot_radius: 0.12 #圓形
# footprint: [[-0.12, -0.12], [-0.12, 0.12], [0.12, 0.12], [0.12, -0.12]] #其他形狀obstacle_range: 3.0 # 用于障礙物探測,比如: 值為 3.0,意味著檢測到距離小于 3 米的障礙物時,就會引入代價地圖
raytrace_range: 3.5 # 用于清除障礙物,比如:值為 3.5,意味著清除代價地圖中 3.5 米以外的障礙物#膨脹半徑,擴展在碰撞區域以外的代價區域,使得機器人規劃路徑避開障礙物
inflation_radius: 0.2
#代價比例系數,越大則代價值越小
cost_scaling_factor: 3.0#地圖類型
map_type: costmap
#導航包所需要的傳感器
observation_sources: scan
#對傳感器的坐標系和數據進行配置。這個也會用于代價地圖添加和清除障礙物。例如,你可以用激光雷達傳感器用于在代價地圖添加障礙物,再添加kinect用于導航和清除障礙物。
scan: {sensor_frame: laser, data_type: LaserScan, topic: scan, marking: true, clearing: true}
2.global_costmap_params.yaml
該文件用于全局代價地圖參數設置:
global_costmap:global_frame: map #地圖坐標系robot_base_frame: base_footprint #機器人坐標系# 以此實現坐標變換update_frequency: 1.0 #代價地圖更新頻率publish_frequency: 1.0 #代價地圖的發布頻率transform_tolerance: 0.5 #等待坐標變換發布信息的超時時間static_map: true # 是否使用一個地圖或者地圖服務器來初始化全局代價地圖,如果不使用靜態地圖,這個參數為false.
3.local_costmap_params.yaml
該文件用于局部代價地圖參數設置:
local_costmap:global_frame: odom #里程計坐標系robot_base_frame: base_footprint #機器人坐標系update_frequency: 10.0 #代價地圖更新頻率publish_frequency: 10.0 #代價地圖的發布頻率transform_tolerance: 0.5 #等待坐標變換發布信息的超時時間static_map: false #不需要靜態地圖,可以提升導航效果rolling_window: true #是否使用動態窗口,默認為false,在靜態的全局地圖中,地圖不會變化width: 3 # 局部地圖寬度 單位是 mheight: 3 # 局部地圖高度 單位是 mresolution: 0.05 # 局部地圖分辨率 單位是 m,一般與靜態地圖分辨率保持一致
4.base_local_planner_params.yaml
基本的局部規劃器參數配置,這個配置文件設定了機器人的最大和最小速度限制值,也設定了加速度的閾值。
TrajectoryPlannerROS:# Robot Configuration Parametersmax_vel_x: 0.5 # X 方向最大速度min_vel_x: 0.1 # X 方向最小速度max_vel_theta: 1.0 # min_vel_theta: -1.0min_in_place_vel_theta: 1.0acc_lim_x: 1.0 # X 加速限制acc_lim_y: 0.0 # Y 加速限制acc_lim_theta: 0.6 # 角速度加速限制# Goal Tolerance Parameters,目標公差xy_goal_tolerance: 0.10yaw_goal_tolerance: 0.05# Differential-drive robot configuration
# 是否是全向移動機器人holonomic_robot: false# Forward Simulation Parameters,前進模擬參數sim_time: 0.8vx_samples: 18vtheta_samples: 20sim_granularity: 0.05
5.3launch文件集成
如果要實現導航,需要集成地圖服務、amcl 、move_base 等,集成示例如下:
<launch><!-- 設置地圖的配置文件 --><arg name="map" default="nav.yaml" /><!-- 運行地圖服務器,并且加載設置的地圖--><node name="map_server" pkg="map_server" type="map_server" args="$(find nav)/map/$(arg map)"/><!-- 啟動AMCL節點 --><include file="$(find nav)/launch/amcl.launch" /><!-- 運行move_base節點 --><include file="$(find nav)/launch/move_base.launch" /></launch>
5.4測試
1.執行相關launch文件,啟動機器人并加載機器人模型:roslaunch mycar_start start.launch;
2.啟動導航相關的 launch 文件:roslaunch nav nav.launch;
3.添加Rviz組件實現導航(參考仿真實現)。
?
9.3.6 導航與SLAM建圖
與仿真環境類似的,也可以實現機器人自主移動的SLAM建圖,步驟如下:
- 編寫launch文件,集成SLAM與move_base相關節點;
- 執行launch文件并測試。
6.1編寫launc文件
當前launch文件(名稱自定義,比如:auto_slam.launch)實現,無需調用map_server的相關節點,只需要啟動SLAM節點與move_base節點,示例內容如下:
<launch><!-- 啟動SLAM節點 --><include file="$(find nav)/launch/gmapping.launch" /><!-- 運行move_base節點 --><include file="$(find nav)/launch/move_base.launch" />
</launch>
6.2測試
1.執行相關launch文件,啟動機器人并加載機器人模型:roslaunch mycar_start start.launch;
2.然后執行當前launch文件:roslaunch nav auto_slam.launch;
3.在rviz中通過2D Nav Goal設置目標點,機器人開始自主移動并建圖了;
4.最后可以使用 map_server 保存地圖。
?