1. 程式人生 > 實用技巧 >三、模擬環境下移動機器人的導航

三、模擬環境下移動機器人的導航

1、導航功能包簡介

導航的關鍵包含機器人定位和路徑規劃兩大部分,針對這兩部分核心內容,ROS提供了以下兩個功能包:

(1)move_base: 實現機器人導航中最優路徑規劃。

(2)amcl: 實現二維地圖中的機器人定位。

在上述兩個功能包的基礎上,ROS提供一套完整的導航功能框架,如下圖所示:

導航框架所包含的功能包很多,可以直接利用以下指令進行完整安裝:

sudo apt-get install ros-kinetic-navigation

2、建立move_base啟動檔案move_base.launch,其內容如下:

 1 <launch>
 2 
 3     <
param name="use_sim_time" value="true" /> 4 5 <!-- 設定地圖的配置檔案 --> 6 <arg name="map" default="gmapping_map.yaml" /> 7 8 <!-- 執行地圖伺服器,並且載入設定的地圖--> 9 <node name="map_server" pkg="map_server" type="map_server" args="$(find slam_robot)/maps/$(arg map)"/> 10 11
12 <!-- fake_move_base.launch中的內容,用來載入地圖的配置檔案 --> 13 <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen" clear_params="true"> 14 <rosparam file="$(find slam_robot)/config/fake/costmap_common_params.yaml" command="load" ns="global_costmap"
/> 15 <rosparam file="$(find slam_robot)/config/fake/costmap_common_params.yaml" command="load" ns="local_costmap" /> 16 <rosparam file="$(find slam_robot)/config/fake/local_costmap_params.yaml" command="load" /> 17 <rosparam file="$(find slam_robot)/config/fake/global_costmap_params.yaml" command="load" /> 18 <rosparam file="$(find slam_robot)/config/fake/base_local_planner_params.yaml" command="load" /> 19 </node> 20 21 <!-- 執行虛擬定位,相容AMCL輸出 --> 22 <node pkg="fake_localization" type="fake_localization" name="fake_localization" output="screen" /> --> 23 24 25 <!-- 加入amcl啟動檔案,此處有了上面的節點,因此不用開啟,此處註釋掉 26 <include file = "$(find mrobot_navigation)/launch/amcl.launch" /> 27 --> 28 29 <!-- 對於虛擬定位,需要設定一個/odom與/map之間的靜態座標變換 --> 30 <node pkg="tf" type="static_transform_publisher" name="map_odom_broadcaster" args="0 0 0 0 0 0 /map /odom 100" /> 31 32 33 </launch>
move_base.launch

其中需要載入幾個導航過程的配置檔案,其檔案內容分別為:

(a)base_local_planner_params.yaml:

 1 controller_frequency: 3.0
 2 recovery_behavior_enabled: false
 3 clearing_rotation_allowed: false
 4 
 5 TrajectoryPlannerROS:
 6    max_vel_x: 0.5
 7    min_vel_x: 0.1
 8    max_vel_y: 0.0  # zero for a differential drive robot
 9    min_vel_y: 0.0
10    max_vel_theta: 1.0
11    min_vel_theta: -1.0
12    min_in_place_vel_theta: 0.4
13    escape_vel: -0.1
14    acc_lim_x: 1.5
15    acc_lim_y: 0.0  # zero for a differential drive robot
16    acc_lim_theta: 1.2
17 
18    holonomic_robot: false
19    yaw_goal_tolerance: 0.1 # about 6 degrees
20    xy_goal_tolerance: 0.05  # 5 cm
21    latch_xy_goal_tolerance: false
22    pdist_scale: 0.4
23    gdist_scale: 0.8
24    meter_scoring: true
25 
26    heading_lookahead: 0.325
27    heading_scoring: false
28    heading_scoring_timestep: 0.8
29    occdist_scale: 0.05
30    oscillation_reset_dist: 0.05
31    publish_cost_grid_pc: false
32    prune_plan: true
33 
34    sim_time: 1.0
35    sim_granularity: 0.05
36    angular_sim_granularity: 0.1
37    vx_samples: 8
38    vy_samples: 0  # zero for a differential drive robot
39    vtheta_samples: 20
40    dwa: true
41    simple_attractor: false
base_local_planner_params.yaml

(b)costmap_common_params.yaml:

 1 obstacle_range: 2.5
 2 raytrace_range: 3.0
 3 #footprint: [[0.175, 0.175], [0.175, -0.175], [-0.175, -0.175], [-0.175, 0.175]]
 4 #footprint_inflation: 0.01
 5 robot_radius: 0.3
 6 inflation_radius: 0.4
 7 max_obstacle_height: 0.6
 8 min_obstacle_height: 0.0
 9 observation_sources: scan
10 scan: {data_type: LaserScan, topic: /scan, marking: true, clearing: true, expected_update_rate: 0}
costmap_common_params.yaml

(c)global_costmap_params.yaml:

 1 global_costmap:
 2    global_frame: map
 3    robot_base_frame: base_footprint
 4    update_frequency: 1.0
 5    publish_frequency: 1.0
 6    static_map: true
 7    rolling_window: false
 8    resolution: 0.01
 9    transform_tolerance: 1.0
10    map_type: costmap
global_costmap_params.yaml

(d)local_costmap_params.yaml:

 1 local_costmap:
 2    global_frame: map
 3    robot_base_frame: base_footprint
 4    update_frequency: 3.0
 5    publish_frequency: 1.0
 6    static_map: true
 7    rolling_window: false
 8    width: 6.0
 9    height: 6.0
10    resolution: 0.01
11    transform_tolerance: 1.0
local_costmap_params.yaml

3、啟動move_base.launch檔案:

sudo roslaunch slam_robot move_base.launch

4、開啟rviz