ROS与SLAM入门教程-激光雷达(neato xv-11)hector_slam构建地图
Turtlebot入门教程-激光雷达(neato xv-11)hector_slam构建地图
说明
- 介绍Turtlebot搭载激光雷达(neato xv-11)通过hector_slam构建地图
准备
- 测试环境ubuntu14.04 + indigo
- 已安装Turtlebot包,具体安装:deb包安装 | 源码安装
- 依赖包:
- Turtlebot应用包,https://github.com/ncnynl/turtlebot_apps.git
- neato xv-11驱动包,https://github.com/ncnynl/xv_11_laser_driver.git
步骤
- 建立工作空间(也可以利用现有的),编译包
$ mkdir -p ~/turtlebot_ws/src
$ cd ~/turtlebot_ws/src
## 激光雷达neato xv-11 驱动
$ git clone https://github.com/ncnynl/xv_11_laser_driver.git
## turtlebot建图依赖包
$ git clone https://github.com/turtlebot/turtlebot_apps
## hector_slam包,indigo桌面版已包含,如没,如下方式安装
$sudo apt-get install ros-indigo-hector-slam
#编译
$ cd ~/turtlebot_ws
$ catkin_make
- 添加环境变量,在~/.bashrc最后添加一行:
$ source /home/ubu/turtlebot_ws/devel/setup.bash
- 刷新配置
$ source ~/.bashrc
- 或
$ rospack profile
创建激光雷达(neato xv-11)的串口别名
- 确认idVendor和idProduct,ID后面的部分idVendor:idProduct
$ lsusb
Bus 001 Device 006: ID 138a:0011 Validity Sensors, Inc. VFS5011 Fingerprint Reader
- 新建 /etc/udev/rules.d/neato.rules文件,内容如下:(别名为neatolaser,实际名称为:/dev/neatolaser)
KERNEL=="ttyUSB*", ATTRS{idVendor}=="138a", ATTRS{idProduct}=="0011", MODE:="0666", GROUP:="dialout", SYMLINK+="neatolaser"
- 增加当前用户对串口的默认访问权限:
$ sudo usermod -a -G dialout 用户名
- 使UDEV配置生效:(使串口的默认访问权限生效,需要重启机器)
$ sudo service udev reload
$ sudo service udev restart
制作雷达驱动启动文件
- 查看neato_laser_publisher.cpp
$ rosed xv_11_laser_driver neato_laser_publisher.cpp
- 检查frame_id是否指定为laser
priv_nh.param("frame_id", frame_id, std::string("laser"));
- 增加neato_laser.launch
$ roscd turtlebot_navigation
$ mkdir -p laser/driver
$ touch laser/driver/neato_laser.launch
$ rosed laser/driver/neato_laser.launch
- 输入内容:
<launch>
<node pkg="xv_11_laser_driver" type="neato_laser_publisher" name="neato_laser_publisher" output="screen">
<param name="firmware_version" value="2" />
<param name="port" value="/dev/neatolaser" />
<param name="baud_rate" value="115200" />
</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>
- 检查端口:
<param name="port" value="/dev/neatolaser" />
,设置好别名,或直接端口/dev/ttyUSB0 - 检查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
检查turtlebot_navigation包
- 增加neato_hector_mapping_demo.launch文件
$ roscd turtlebot_navigation
$ touch launch/neato_hector_mapping_demo.launch
$ rosed launch/neato_hector_mapping_demo.launch
- 输入内容:
<launch>
<!-- Define laser type-->
<arg name="laser_type" default="neato" />
<!-- XV-11 laser -->
<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/hector_mapping/$(arg laser_type)_hector_mapping.launch.xml"/>
<include file="$(arg custom_gmapping_launch_file)"/>
<!-- Move base -->
<include file="$(find turtlebot_navigation)/launch/includes/move_base.launch.xml"/>
</launch>
- 增加neato_hector_mapping.launch.xml文件
$ roscd turtlebot_navigation
$ touch launch/includes/gmapping/neato_hector_mapping.launch.xml
$ rosed launch/includes/gmapping/neato_hector_mapping.launch.xml
- 输入内容:
<launch>
<node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">
<!-- Frame names -->
<param name="pub_map_odom_transform" value="true"/>
<param name="map_frame" value="map" />
<param name="scan_topic" value="scan" />
<param name="base_frame" value="base_footprint"/>
<param name="odom_frame" value="odom"/>
<!-- Tf use -->
<param name="use_tf_scan_transformation" value="true"/>
<param name="use_tf_pose_start_estimate" value="false"/>
<!-- Map size / start point -->
<param name="map_resolution" value="0.05"/>
<param name="map_size" value="2048"/>
<param name="map_start_x" value="0.5"/>
<param name="map_start_y" value="0.5" />
<param name="laser_z_min_value" value = "-1.0" />
<param name="laser_z_max_value" value = "1.0" />
<param name="map_multi_res_levels" value="2" />
<param name="map_pub_period" value="2" />
<param name="laser_min_dist" value="0.4" />
<param name="laser_max_dist" value="5.5" />
<param name="output_timing" value="false" />
<param name="pub_map_scanmatch_transform" value="true" />
<!--<param name="tf_map_scanmatch_transform_frame_name" value="scanmatcher_frame" />-->
<!-- Map update parameters -->
<param name="update_factor_free" value="0.4"/>
<param name="update_factor_occupied" value="0.7" />
<param name="map_update_distance_thresh" value="0.2"/>
<param name="map_update_angle_thresh" value="0.06" />
<!-- Advertising config -->
<param name="advertise_map_service" value="true"/>
<param name="scan_subscriber_queue_size" value="5"/>
</node>
</launch>
测试激光雷达hector构建地图
- 上网本新开端口,打开roscore
$ roscore
- 上网本新开端口,启动turtlebot
$ roslaunch turtlebot_bringup minimal.launch
- 上网本新开端口,启动hector_mapping,用于构建地图
$ roslaunch turtlebot_navigation neato_hector_mapping_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/neato_hector_mapping
$ ls ~/map #查看内容,包含neato_hector_mapping.pgm neato_hector_mapping.yaml
- 查看地图,已经生成neato_hector_mapping.pgm文件,可以用图像浏览器(gimp, eog, gthumb, 等等)打开查看。
利用地图进行AMCL
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号