安装hector-slam需要ros系统,首先通过官方教程进行安装,需要根据系统找好对应的ros系统版本,Ubuntu16.04对应Kinetic版本,安装教程如下():
ROS Kinetic ONLY supports Wily (Ubuntu 15.10), Xenial (Ubuntu 16.04) and Jessie (Debian 8) for debian packages.
-
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
-
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
-
curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -
-
sudo apt-get update
-
sudo apt-get install ros-kinetic-desktop-full
安装完成ros之后开始安装hector-slam:
首先创建工作目录以及配置环境
- echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
- source ~/.bashrc
- mkdir -p catkin_ws/src
- cd catkin_ws
- catkin_make
- echo "source /home/robot/catkin_ws/devel/setup.bash" >> ~/.bashrc
下载安装hector-slam
- cd src
- sudo apt install git
- git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam
- cd ../
- catkin_make
编译过程中报错
c++: internal compiler error: Killed (program cc1plus)
是因为系统内存不够导致的,参考这篇文章
https://blog.csdn.net/me1171115772/article/details/105111299
执行完之后重新运行catkin_make
至此编译完成
Hector-slam使用
hector-slam针对高频率激光设备效果较好,低频建图基本不太准确。
hector-slam官方介绍有三种使用方式:
-
Use in place of gmapping(通过gmapping发布map到odom的tf变换)
-
Use without odom frame(不使用odom里程计信息)
-
Use without Broadcasting of transformations(不使用任何tf数据)
因为我使用机器人录制了一下厂房的数据包,其中包括了激光数据和odom数据,这里暂时不使用odom(其实是没看出来在哪里使用/(ㄒoㄒ)/~~)。
数据包地址以及相关的launch文件:https://download.csdn.net/download/me1171115772/12271884
首先进入hector_slam的launch目录下,查看一下launch文件:
- roscd hector_slam_launch/launch
默认的是使用tutorial.launch ,打开文件查看文件内容:
这里开到它包含了mapping_default.launch文件,查看文件内容:
在这个文件里面看到了base_frama | odom_frame | scan_topic 这几个参数,首先base_frame不需要改,这个程序默认的,然后odom_frame也不需要改,程序会自己发布,最后scan_topic根据自己的激光主题发布,因为这里发布的主题就是scan所以不做改动。
更改文件之后运行报错,提示
这说明没有laser scan 到base_frame的tf变换,添加下行到launch文件中,发布一个静态变换:
- <node pkg="tf" type="static_transform_publisher" name="base_frame_laser" args="0 0 0 0 0 0 /base_footprint /velodyne 100" />
这里提示一下,laser scan对应的不应该是scan的主题,而是scan的frama_id,因为我使用的是velodyne激光,所以这里对应的改成/velodyne.
改完之后的两个文件:
<?xml version="1.0"?>
<launch>
<arg name="geotiff_map_file_path" default="$(find hector_geotiff)/maps"/>
<param name="/use_sim_time" value="true"/>
<node pkg="tf" type="static_transform_publisher" name="base_frame_laser" args="0 0 0 0 0 0 /base_footprint /velodyne 100" />
<!--node pkg="tf" type="static_transform_publisher" name="map_to_odom" args="0.0 0.0 0.0 0 0 0.0 /odom /base_footprint 100" /-->
<node pkg="rosbag" type="play" name="bagplayer" args="--clock /home/robot/rosbag/whole-room_2020-02-27-11-31-12.bag"/>
<node pkg="rviz" type="rviz" name="rviz"
args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/><include file="$(find hector_mapping)/launch/whole_room_mapping.launch"/>
<include file="$(find hector_geotiff)/launch/geotiff_mapper.launch">
<arg name="trajectory_source_frame_name" value="scanmatcher_frame"/>
<arg name="map_file_path" value="$(arg geotiff_map_file_path)"/>
</include></launch>
hector_slam/hector_slam_launch/launch/whole_room.launch
<?xml version="1.0"?>
<launch>
<arg name="tf_map_scanmatch_transform_frame_name" default="scanmatcher_frame"/>
<arg name="base_frame" default="base_footprint"/>
<arg name="odom_frame" default="odom"/>
<arg name="pub_map_odom_transform" default="true"/>
<arg name="scan_subscriber_queue_size" default="5"/>
<arg name="scan_topic" default="scan"/>
<arg name="map_size" default="2048"/><node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">
<!-- Frame names -->
<param name="map_frame" value="map" />
<param name="base_frame" value="$(arg base_frame)" />
<param name="odom_frame" value="$(arg odom_frame)" /><!-- Tf use -->
<param name="use_tf_scan_transformation" value="true"/>
<param name="use_tf_pose_start_estimate" value="false"/>
<param name="pub_map_odom_transform" value="$(arg pub_map_odom_transform)"/><!-- Map size / start point -->
<param name="map_resolution" value="0.050"/>
<param name="map_size" value="$(arg map_size)"/>
<param name="map_start_x" value="0.5"/>
<param name="map_start_y" value="0.5" />
<param name="map_multi_res_levels" value="2" /><!-- Map update parameters -->
<param name="update_factor_free" value="0.4"/>
<param name="update_factor_occupied" value="0.9" />
<param name="map_update_distance_thresh" value="0.4"/>
<param name="map_update_angle_thresh" value="0.06" />
<param name="laser_z_min_value" value = "-1.0" />
<param name="laser_z_max_value" value = "1.0" /><!-- Advertising config -->
<param name="advertise_map_service" value="true"/><param name="scan_subscriber_queue_size" value="$(arg scan_subscriber_queue_size)"/>
<param name="scan_topic" value="$(arg scan_topic)"/><!-- Debug parameters -->
<!--
<param name="output_timing" value="false"/>
<param name="pub_drawings" value="true"/>
<param name="pub_debug_output" value="true"/>
-->
<param name="tf_map_scanmatch_transform_frame_name" value="$(arg tf_map_scanmatch_transform_frame_name)" />
</node>
<!--<node pkg="tf" type="static_transform_publisher" name="map_nav_broadcaster" args="0 0 0 0 0 0 map nav 100"/>-->
</launch>"/home/robot/catkin_ws/src/hector_slam/hector_mapping/launch/whole_room_mapping.launch"
建图结果:
节点之间的订阅关系如下: