2021-03-19

ubuntu18.04+hokuyo激光雷达实现amcl导航

首先需要文件配置

1.打开一个新终端,配置一次环境变量

source ~/catkin_ws/devel/setup.bash

2.修改激光雷达串口权限,每次插拔激光雷达都要运行此步骤

sudo chmod a+rw /dev/ttyACM0

3.手动打开hokuyo_laser.launch文件(路径:/home/yourname/turtlebot_ws/src/turtlebot_apps/turtlebot_navigation/laser/driver)

在该路径下输入:

sudo gedit hokuyo_laser.launch

添加tf变换

<node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.22 0 0.0 0.0 base_link laser 100"/>
  <node pkg="tf" type="static_transform_publisher" name="map_to_odom" args="0.0 0.0 0.22 0 0 0.0 /map /odom 1000"/>

完整代码为:

<!-- 

This launch file shows how to start a hokuyo node. 

You may have to change the port parameter if your laser is not at
/dev/ttyACM0.

If you have rviz built, you can uncomment the rviz node to visualize the
laser data.

Otherwise, you can use rostopic to see the data:
rostopic echo /scan

-->

<launch>
  <node name="hokuyo" pkg="hokuyo_node" type="hokuyo_node" respawn="false" output="screen">
    <param name="frame_id" type="string" value="laser"/>
  
    <!-- Starts up faster, but timestamps will be inaccurate. --> 
    <param name="calibrate_time" type="bool" value="false"/> 
    
    <!-- Set the port to connect to here -->
    <param name="port" type="string" value="/dev/hokuyo"/> 
  
    <param name="intensity" type="bool" value="false"/>
  </node>
  
  <node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.22 0 0.0 0.0 base_link laser 100"/>
  <node pkg="tf" type="static_transform_publisher" name="map_to_odom" args="0.0 0.0 0.22 0 0 0.0 /map /odom 1000"/>
  <!-- 
     <node name="rviz" pkg="rviz" type="rviz" respawn="false" output="screen" args="-d $(find hokuyo_node)/hokuyo_test.vcg"/>
-->
  
</launch>

4.创建 hokuyo_amcl_demo.launch文件,并打开。

roscd  turtlebot_navigation
touch  launch/hokuyo_amcl_demo.launch
sudo gedit hokuyo_amcl_demo.launch

添加如下代码:

<launch>

<!-- Define laser type-->
  <arg name="laser_type" default="hokuyo" />

  <!-- laser driver -->
  <include file="$(find turtlebot_navigation)/laser/driver/$(arg laser_type)_laser.launch"/>

  <!-- Map server -->
  <arg name="map_file" default="$(env TURTLEBOT_MAP_FILE)"/>
  <node name="map_server" pkg="map_server" type="map_server" args="$(arg map_file)" />

  <!-- AMCL -->
  <arg name="custom_amcl_launch_file" default="$(find turtlebot_navigation)/launch/includes/amcl/$(arg laser_type)_amcl.launch.xml"/>
  <arg name="initial_pose_x" default="0.0"/> <!-- Use 17.0 for willow's map in simulation -->
  <arg name="initial_pose_y" default="0.0"/> <!-- Use 17.0 for willow's map in simulation -->
  <arg name="initial_pose_a" default="0.0"/>
  <include file="$(arg custom_amcl_launch_file)">
    <arg name="initial_pose_x" value="$(arg initial_pose_x)"/>
    <arg name="initial_pose_y" value="$(arg initial_pose_y)"/>
    <arg name="initial_pose_a" value="$(arg initial_pose_a)"/>
  </include>

  <!-- Move base -->
  <arg name="custom_param_file" default="$(find turtlebot_navigation)/param/$(arg laser_type)_costmap_params.yaml"/>
  <include file="$(find turtlebot_navigation)/launch/includes/move_base.launch.xml">
  </include>

</launch>

5.找到文件 hokuyo_amcl.launch.xml文件的位置,没有的话创建它(我的路径为/home/qmw/turtlebot_ws/src/turtlebot_apps/turtlebot_navigation/launch/includes/amcl/hokuyo_amcl.launch.xml)

并添加如下内容:

<launch>
  <arg name="use_map_topic"   default="false"/>
  <arg name="scan_topic"      default="scan"/> 
  <arg name="initial_pose_x"  default="0.0"/>
  <arg name="initial_pose_y"  default="0.0"/>
  <arg name="initial_pose_a"  default="0.0"/>
  <arg name="odom_frame_id"   default="odom"/>
  <arg name="base_frame_id"   default="base_footprint"/>
  <arg name="global_frame_id" default="map"/>

  <node pkg="amcl" type="amcl" name="amcl">
    <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="$(arg odom_frame_id)"/> 
    <param name="base_frame_id"             value="$(arg base_frame_id)"/> 
    <param name="global_frame_id"           value="$(arg global_frame_id)"/>
    <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"/>
    <param name="initial_pose_x"            value="$(arg initial_pose_x)"/>
    <param name="initial_pose_y"            value="$(arg initial_pose_y)"/>
    <param name="initial_pose_a"            value="$(arg initial_pose_a)"/>
    <remap from="scan"                      to="$(arg scan_topic)"/>
  </node>
</launch>

现在开始导航运行

1.上网本新开端口

roscore

2.上网本新开端口,运行turtlebot

roslaunch turtlebot_bringup minimal.launch

3.上位机打开终端运行amcl

roslaunch turtlebot_navigation hokuyo_amcl_demo.launch map_file:=/home/qmw/map/lab.yaml

具体位置需要更改用户名,看各人存储位置。

如果出现odom recreived!说明运行成功,此时有warning依旧可以运行,个人运行效果还可以

4.再打开个新终端,运行rviz,可以实时查看并指定导航位置。

roslaunch turtlebot_rviz_launchers view_navigation.launch --screen

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值