Turtlebot入门教程-激光雷达(Hokuyo)gmapping构建地图
Turtlebot入门教程-激光雷达(Hokuyo)gmapping构建地图
说明
- 介绍Turtlebot搭载激光雷达(Hokuyo)通过gmapping构建地图
准备
- 测试环境ubuntu14.04 + indigo
- 已安装Turtlebot包,具体安装:deb包安装 | 源码安装
- 依赖包:
- Turtlebot应用包,https://github.com/ncnynl/turtlebot_apps.git
- 激光雷达Hokuyo node驱动,https://github.com/ncnynl/hokuyo_node.git
已测试型号
- hokuyo URG-04LX-UG01 (网友Null)
步骤
- 建立工作空间(也可以利用现有的),编译包
$ mkdir -p ~/turtlebot_ws/src
$ cd ~/turtlebot_ws/src
## 激光雷达Hokuyo node驱动
$ git clone https://github.com/ncnynl/hokuyo_node.git
## turtlebot建图依赖包
$ git clone https://github.com/turtlebot/turtlebot_apps
#编译
$ cd ~/turtlebot_ws
$ catkin_make
- 添加环境变量,在~/.bashrc最后添加一行:
$ source /home/ubu/turtlebot_ws/devel/setup.bash
- 刷新配置
$ source ~/.bashrc
- 或
$ rospack profile
创建激光雷达的串口别名
- 确认idVendor和idProduct,ID后面的部分idVendor:idProduct
$ lsusb
Bus 001 Device 006: ID 15d1:0000
- 新建 /etc/udev/rules.d/hokuyo.rules文件,内容如下:(别名为hokuyo,实际名称为:/dev/hokuyo)
KERNEL=="ttyACM[0-9]*", ACTION=="add", ATTRS{idVendor}=="15d1", MODE="0666", GROUP="dialout", SYMLINK+="hokuyo"
- 增加当前用户对串口的默认访问权限:
$ sudo usermod -a -G dialout 用户名
- 使UDEV配置生效:(使串口的默认访问权限生效,需要重启机器)
$ sudo service udev reload
$ sudo service udev restart
制作雷达驱动启动文件
- 复制hokuyo_node的hokuyo_test.launch到hokuyo_laser.launch,并增加TF定义
$ roscd turtlebot_navigation
$ mkdir -p laser/driver
$ sudo cp ~/turtlebot_ws/src/hokuyo_node/hokuyo_test.launch laser/driver/hokuyo_laser.launch
- 打开hokuyo_laser.launch,并修改
$ rosed turtlebot_navigation hokuyo_laser.launch
- 检查frame_id是否指定为laser
<param name="frame_id" type="string" value="laser"/>
- 查看port是否指定正确端口,使用别名
- 检查端口:
<param name="port" type="string" value="/dev/hokuyo"/>
,设置好别名,或直接端口/dev/ttyACM0 - 增加TF:
<node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.18 0 0.0 0.0 base_link laser 100"/>
修改为args="0.0 0.0 0.18 0 0.0 0.0 为自己的实际安装位置。详情查看,static_transform_publisher部分
static_transform_publisher x y z qx qy qz qw frame_id child_frame_id period_in_ms
这里我假设底盘的中心点为0,雷达放在机器人托盘中心位置,X为0,高度为18CM,Z为0.18m
TF的单位使用米的,测量单位是CM
完整代码如下:
<launch>
<node name="hokuyo" pkg="hokuyo_node" type="hokuyo_node" respawn="false" output="screen">
<!-- 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="frame_id" type="string" value="laser"/>
<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.18 0 0.0 0.0 base_link laser 100"/>
</launch>
检查turtlebot_navigation包
- 增加hokuyo_gmapping_demo.launch文件,用于启动gmapping.
$ roscd turtlebot_navigation
$ touch launch/hokuyo_gmapping_demo.launch
$ rosed launch/hokuyo_gmapping_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" />
<!-- Gmapping -->
<arg name="custom_gmapping_launch_file" default="$(find turtlebot_navigation)/launch/includes/gmapping/$(arg laser_type)_gmapping.launch.xml"/>
<include file="$(arg custom_gmapping_launch_file)"/>
<!-- Move base -->
<include file="$(find turtlebot_navigation)/launch/includes/move_base.launch.xml"/>
</launch>
设置laser_type为hokuyo.
增加hokuyo_gmapping.launch.xml文件,执行gmapping建图
$ roscd turtlebot_navigation
$ touch launch/includes/gmapping/hokuyo_gmapping.launch.xml
$ rosed launch/includes/gmapping/hokuyo_gmapping.launch.xml
- 输入内容:
<launch>
<arg name="scan_topic" default="scan" />
<arg name="base_frame" default="base_footprint"/>
<arg name="odom_frame" default="odom"/>
<node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen">
<param name="base_frame" value="$(arg base_frame)"/>
<param name="odom_frame" value="$(arg odom_frame)"/>
<param name="map_update_interval" value="5.0"/>
<param name="maxUrange" value="6.0"/>
<param name="maxRange" value="8.0"/>
<param name="sigma" value="0.05"/>
<param name="kernelSize" value="1"/>
<param name="lstep" value="0.05"/>
<param name="astep" value="0.05"/>
<param name="iterations" value="5"/>
<param name="lsigma" value="0.075"/>
<param name="ogain" value="3.0"/>
<param name="lskip" value="0"/>
<param name="minimumScore" value="200"/>
<param name="srr" value="0.01"/>
<param name="srt" value="0.02"/>
<param name="str" value="0.01"/>
<param name="stt" value="0.02"/>
<param name="linearUpdate" value="0.5"/>
<param name="angularUpdate" value="0.436"/>
<param name="temporalUpdate" value="-1.0"/>
<param name="resampleThreshold" value="0.5"/>
<param name="particles" value="80"/>
<!--
<param name="xmin" value="-50.0"/>
<param name="ymin" value="-50.0"/>
<param name="xmax" value="50.0"/>
<param name="ymax" value="50.0"/>
make the starting size small for the benefit of the Android client's memory...
-->
<param name="xmin" value="-1.0"/>
<param name="ymin" value="-1.0"/>
<param name="xmax" value="1.0"/>
<param name="ymax" value="1.0"/>
<param name="delta" value="0.05"/>
<param name="llsamplerange" value="0.01"/>
<param name="llsamplestep" value="0.01"/>
<param name="lasamplerange" value="0.005"/>
<param name="lasamplestep" value="0.005"/>
<remap from="scan" to="$(arg scan_topic)"/>
</node>
</launch>
测试激光雷达gmapping构建地图
- 上网本新开端口,打开roscore
$ roscore
- 上网本新开端口,启动turtlebot
$ roslaunch turtlebot_bringup minimal.launch
- 上网本新开端口,启动gmapping,用于构建地图
$ roslaunch turtlebot_navigation hokuyo_gmapping_demo.launch
- 工作机或上网本新开端口,启动键盘操作Turtlebot
$ roslaunch turtlebot_teleop keyboard_teleop.launch
- 工作机或上网本新开端口,启动rviz,实时查看建图情况
$ roslaunch turtlebot_rviz_launchers view_navigation.launch
构建地图结束保存地图
- 上网本新开端口,建立目录,保存地图
$ mkdir -p ~/map
$ rosrun map_server map_saver -f ~/map/hokuyo_gmapping
$ ls ~/map #查看内容,包含hokuyo_gmapping.pgm hokuyo_gmapping.yaml
- 查看地图,已经生成hokuyo_gmapping.pgm文件,可以用图像浏览器(gimp, eog, gthumb, 等等)打开查看。
利用地图进行AMCL
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号