Navigation包中的move_base和amcl实现自动驾驶

安装导航定位包,navigation: 
    sudo apt-get install ros-indigo-navigation
由于导航包在/cmd_val下发布的移动数据加速度会过于不友好,所以我们需要对速度做平滑处理,其实就是控制加速,一般通过滤波即可实现,在此我们采用turtlebot的平滑包即可安装平滑包yocs_velocity_smoother,具体的平滑算法和输入切换请自己阅读源码 :
    sudo apt-get install ros-indigo-yocs-velocity-smoother
在小车的运动控制的launch中如下添加:
 <!-- velocity smoother -->
  <include file="$(find yocs_velocity_smoother)/launch/velocity_smoother.launch">
  </include>


导航包(move_base)和定位(amcl)的启动文件:nav_amcl.launch
<launch
  <param name="use_sim_time" value="false" />
  <!-- Set the name of the map yaml file: can be overridden on the command line. -->
  <arg name="map" default="map.yaml" />
  <!--node name="map_odom" pkg="tf" type="static_transform_publisher" args="0 0 0 0 0 0 map odom 50"/-->
  <!-- Run the map server with the desired map -->
  <node name="map_server" pkg="map_server" type="map_server" args="$(find odom_tf_package)/maps/$(arg map)"/>
  <!-- The move_base node -->
  <include file="$(find odom_tf_package)/launch/move_base_amcl.launch" />
  <!--add Fire up AMCL-->
  <include file="$(find odom_tf_package)/launch/tb_amcl.launch" />
</launch>


move_base_amcl.launch:
<launch>

  <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen" clear_params="true">
    <rosparam file="$(find odom_tf_package)/config/costmap_common_params.yaml" command="load" ns="global_costmap" />
    <rosparam file="$(find odom_tf_package)/config/costmap_common_params.yaml" command="load" ns="local_costmap" />
    <rosparam file="$(find odom_tf_package)/config/local_costmap_params.yaml" command="load" />
    <rosparam file="$(find odom_tf_package)/config/global_costmap_params.yaml" command="load" />
    <rosparam file="$(find odom_tf_package)/config/base_local_planner_params.yaml" command="load" />
  </node>
  
</launch>


tb_amcl.launch:
<launch>

  <arg name="use_map_topic" default="false"/>
  <arg name="scan_topic" default="scan"/>
  <node pkg="amcl" type="amcl" name="amcl" clear_params="true">
    <param name="use_map_topic" value="$(arg use_map_topic)"/>
    <!-- Publish scans from best pose at a max of 10 Hz -->
    <param name="odom_model_type" value="diff"/>
    <param name="odom_alpha5" value="0.1"/>
    <param name="gui_publish_rate" value="10.0"/>
    <param name="laser_max_beams" value="60"/>
    <param name="laser_max_range" value="12.0"/>
    <param name="min_particles" value="500"/>
    <param name="max_particles" value="2000"/>
    <param name="kld_err" value="0.05"/>
    <param name="kld_z" value="0.99"/>
    <param name="odom_alpha1" value="0.2"/>
    <param name="odom_alpha2" value="0.2"/>
    <!-- translation std dev, m -->
    <param name="odom_alpha3" value="0.2"/>
    <param name="odom_alpha4" value="0.2"/>
    <param name="laser_z_hit" value="0.5"/>
    <param name="laser_z_short" value="0.05"/>
    <param name="laser_z_max" value="0.05"/>
    <param name="laser_z_rand" value="0.5"/>
    <param name="laser_sigma_hit" value="0.2"/>
    <param name="laser_lambda_short" value="0.1"/>
    <param name="laser_model_type" value="likelihood_field"/>
    <!-- <param name="laser_model_type" value="beam"/> -->
    <param name="laser_likelihood_max_dist" value="2.0"/>
    <param name="update_min_d" value="0.25"/>
    <param name="update_min_a" value="0.2"/>

    <param name="odom_frame_id" value="odom"/>

    <param name="resample_interval" value="1"/>
    <!-- Increase tolerance because the computer can get quite busy -->
    <param name="transform_tolerance" value="1.0"/>
    <param name="recovery_alpha_slow" value="0.0"/>
    <param name="recovery_alpha_fast" value="0.0"/>
    <remap from="scan" to="$(arg scan_topic)"/>
  </node>
</launch>


4.导航的配置参数如下:
base_local_planner_params.yaml

    controller_frequency: 2.0
    recovery_behavior_enabled: false
    clearing_rotation_allowed: false

    TrajectoryPlannerROS:
       max_vel_x: 0.3
       min_vel_x: 0.05
       max_vel_y: 0.0  # zero for a differential drive robot
       min_vel_y: 0.0
       min_in_place_vel_theta: 0.5
       escape_vel: -0.1
       acc_lim_x: 2.5
       acc_lim_y: 0.0 # zero for a differential drive robot
       acc_lim_theta: 3.2

       holonomic_robot: false
       yaw_goal_tolerance: 0.1 # about 6 degrees
       xy_goal_tolerance: 0.15  # 10 cm
       latch_xy_goal_tolerance: false
       pdist_scale: 0.8
       gdist_scale: 0.6
       meter_scoring: true

       heading_lookahead: 0.325
       heading_scoring: false
       heading_scoring_timestep: 0.8
       occdist_scale: 0.1
       oscillation_reset_dist: 0.05
       publish_cost_grid_pc: false
       prune_plan: true

       sim_time: 2.5
       sim_granularity: 0.025
       angular_sim_granularity: 0.025
       vx_samples: 8
       vy_samples: 0 # zero for a differential drive robot
       vtheta_samples: 20
       dwa: true
       simple_attractor: false


costmap_common_params.yaml

    obstacle_range: 2.5
    raytrace_range: 3.0
    robot_radius: 0.30
    inflation_radius: 0.15
    max_obstacle_height: 0.6
    min_obstacle_height: 0.0
    observation_sources: scan
    scan: {data_type: LaserScan, topic: /scan, marking: true, clearing: true, expected_update_rate: 0}

global_costmap_params.yaml
    global_costmap:
       global_frame: /map
       robot_base_frame: /base_link
       update_frequency: 1.0
       publish_frequency: 0
       static_map: true
       rolling_window: false
       resolution: 0.01
       transform_tolerance: 0.5
       map_type: costmap


local_costmap:
   global_frame: /odom
   robot_base_frame: /base_link
   update_frequency: 1.0
   publish_frequency: 1.0
   static_map: false
   rolling_window: true
   width: 6.0
   height: 6.0
   resolution: 0.01
   transform_tolerance: 0.5
   map_type: costmap

四,准备好以上所有的启动文件和配置参数后,我们开始创建地图和导航,
1.创建地图:
roslaunch ros_car_py ros_car_py.launch   //启动地盘控制器
roscd odom_tf_package/maps/
rosrun map_server map_saver -f map
然后会产生以下地图文件
map.pgm  map.yaml


2.开始导航
roslaunch ros_car_py nav_amcl.launch map:=map.yaml
然后指定导航目标,因为我的TF变换主要是里程计更新的,车体打滑或者地盘电机震荡都会积累误差,
所以我们必须添加视觉里成计或者闭环检测。
在rviz中点击菜单栏的2D Nav Goal,可以帮助我们设置导航的目标点
 

猜你喜欢

转载自blog.csdn.net/qq_34935373/article/details/88690892
今日推荐