rplidar & hector slam without odometry
接上一篇:1.rplidar测试
方式一:测试使用rplidar A2跑一下手持的hector slam,参考文章:用hector mapping构建地图
但是roslaunch exbotxi_bringup 2dsensor.launch 和 roslaunch exbotxi_nav hector_mapping_demo.launch
这两个文件都没有搜索到。需要更新exbot_xi开发包。https://github.com/yuanboshe/exbot_xi/tree/hydro/exbotxi_bringup/launch
cd ~/catkin_ws/src/exbot_xi git pull
如果出现 Already up-to-date. 的提示,则更新成功。如果对包有所修改,可能有些情况下无法更新,那么可以使用
git reset --hard
reset一下,然后再使用 git pull 更新。
之后编译。
cd ~/catkin_ws/ catkin_make
修改rplidar_2d_sensor.launch.xml 文件,/home/exbot/catkin_ws/src/exbot_xi/exbotxi_bringup/launch/includes/rplidar_2d_sensor.launch.xml,修改
<node name="exbot_rplidar" pkg="rplidar_ros" type="rplidarNode" output="screen">
完整文件:(奇怪,端口<arg name="laser_port" default="/dev/ttyUSB1" />似乎也应该改啊,改成/dev/ttyUSB0,没改居然也没问题)
1 <launch> 2 <arg name="scan_topic" default="scan" /> 3 <arg name="laser_frame" default="laser_link" /> 4 <arg name="laser_port" default="/dev/ttyUSB1" /> 5 6 <node name="exbot_rplidar" pkg="rplidar_ros" type="rplidarNode" output="screen"> 7 <param name="com_path" type="string" value="$(arg laser_port)" /> 8 <param name="com_baudrate" type="int" value="115200" /> 9 <param name="frame_id" type="string" value="$(arg laser_frame)" /> 10 <param name="range_min" type="double" value="0.18" /> 11 <param name="range_max" type="double" value="6.0" /> 12 <remap from="scan" to="$(arg scan_topic)"/> 13 </node> 14 </launch>
修改hector_mapping.launch.xml文件,/home/exbot/catkin_ws/src/exbot_xi/exbotxi_nav/launch/includes/hector_mapping.launch.xml
<param name="base_frame" value="base_frame" /> <param name="odom_frame" value="base_frame" />
完整文件:
1 <launch> 2 3 <arg name="scan_topic" default="scan" /> 4 5 <node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen"> 6 <param name="pub_map_odom_transform" value="true"/> 7 <param name="map_frame" value="map" /> 8 <param name="base_frame" value="base_frame" /> 9 <param name="odom_frame" value="base_frame" /> 10 <param name="map_resolution" value="0.05" /> 11 <param name="map_size" value="1024" /> 12 <param name="laser_max_dist" value="3.9" /> 13 <param name="tf_map_scanmatch_transform_frame_name" value="odom_laser" /> 14 <remap from="scan" to="$(arg scan_topic)"/> 15 </node> 16 </launch>
编译之后按照 用hector mapping构建地图 文章中的步骤:
roscore roslaunch exbotxi_bringup fake_exbotxi.launch roslaunch exbotxi_bringup 2dsensor.launch roslaunch exbotxi_nav hector_mapping_demo.launch roslaunch exbotxi_rviz view_navigation.launch
新建5个终端,让rplidar水平移动,会出现建图结果。
另外的实现方式:从原始代码编译hector_slam,参考 http://blog.csdn.net/eaibot/article/details/51044718
编译hector_slam过程中出现Cmake Error,好像是找不到Find cmake_modules.cmake什么的。猜想是cmake_modules包没有安装。
解决方法。
exbot@ubuntu:~$ cd ~/catkin_ws/src exbot@ubuntu:~/catkin_ws/src$ git clone https://github.com/ros/cmake_modules.git Cloning into 'cmake_modules'... remote: Counting objects: 344, done. remote: Total 344 (delta 0), reused 0 (delta 0), pack-reused 344 Receiving objects: 100% (344/344), 61.88 KiB | 34 KiB/s, done. Resolving deltas: 100% (191/191), done. exbot@ubuntu:~/catkin_ws/src$ cd ..\ > exbot@ubuntu:~/catkin_ws$ catkin_make --pkg cmake_modules
之后按照参考文献的步骤,可以实现同样的结果。
在rplidar_ros/launch/目录下添加hector_mapping_demo.launch文件,内容如下:
<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="base_frame" value="base_link" /> <param name="odom_frame" value="base_link" /> <!-- 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"/> <param name="scan_topic" value="scan"/> </node> <node pkg="tf" type="static_transform_publisher" name="base_to_laser_broadcaster" args="0 0 0 0 0 0 /base_link /laser 100"/> <node pkg="rviz" type="rviz" name="rviz" args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/> </launch>
ros命令
roslaunch rplidar_ros hector_mapping_demo.launch roslaunch rplidar_ros rplidar.launch