Hector-SLAM初使用

Hector-SLAM初使用

首先把二维雷达的包拷贝到笔记本上,编译一次通过,连接也没有问题,rviz中可以看到原始激光

想演示一下二维激光雷达的SLAM建图,Hector-SLAM相对比较容易,主要参考了下面的几篇博客

SLAM-hector_slam 简介与使用

hector-slam安装与使用 (ubuntu 16.04)(使用数据包运行hector-slam)

激光雷达初体验 - Ubuntu 18.04 + 思岚科技 RPLIDAR A1M8 + hector_slam 建图

Rplidar A1/A2使用及Hector_SLAM建图

用下面的launch文件,可以演示建图效果,但是没有绿色的轨迹线

<launch>
    <node pkg= "hector_mapping" type= "hector_mapping" name= "hector_mapping" output= "screen">
        <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" />

        <param name= "use_tf_scan_transformation" value= "true" />
        <param name= "use_tf_pose_start_estimate" value= "false" />

        <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= "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" />

        <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>

差不多是上面这种效果,但下面的效果更好一些


Hector-SLAM初使用_第1张图片

有一些问题,明天看看能否优化解决

  • 激光本身的参数如laser_min_distlaser_max_dist需要确定下
  • 建图的一些参数可能也需要优化一下
  • tf变换没有考虑,/laser坐标系到/base_link的变化,以及/base_link到/map的变换等等

又参考了下面几篇博客

SLAM实现之hector_slm

使用数据集跑Hector_slam

自动驾驶系列(五)hector_slam建地图

其实基本都参照了官方的launch文件,改动并不大,先看官方的

tutorial.launch

<?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="rviz" type="rviz" name="rviz"
    args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/>

  <include file="$(find hector_mapping)/launch/mapping_default.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>

mapping_default.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="nav"/>
  <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>

geotiff_mapper.launch

<?xml version="1.0"?>

<launch>
  <arg name="trajectory_source_frame_name" default="/base_link"/>
  <arg name="trajectory_update_rate" default="4"/>
  <arg name="trajectory_publish_rate" default="0.25"/>
  <arg name="map_file_path" default="$(find hector_geotiff)/maps"/>
  <arg name="map_file_base_name" default="hector_slam_map"/>

  <node pkg="hector_trajectory_server" type="hector_trajectory_server" name="hector_trajectory_server" output="screen">
    <param name="target_frame_name" type="string" value="/map" />
    <param name="source_frame_name" type="string" value="$(arg trajectory_source_frame_name)" />
    <param name="trajectory_update_rate" type="double" value="$(arg trajectory_update_rate)" />
    <param name="trajectory_publish_rate" type="double" value="$(arg trajectory_publish_rate)" />
  </node>

  <node pkg="hector_geotiff" type="geotiff_node" name="hector_geotiff_node" output="screen" launch-prefix="nice -n 15">
    <remap from="map" to="/dynamic_map" />
    <param name="map_file_path" type="string" value="$(arg map_file_path)" />
    <param name="map_file_base_name" type="string" value="$(arg map_file_base_name)" />
    <param name="geotiff_save_period" type="double" value="0" />
    <param name="draw_background_checkerboard" type="bool" value="true" />
    <param name="draw_free_space_grid" type="bool" value="true" />
    <param name="plugins" type="string" value="hector_geotiff_plugins/TrajectoryMapWriter" />
  </node>

</launch>

综合学习后我的launch文件

hector_mapping.launch

<launch>
    <arg name="tf_map_scanmatch_transform_frame_name" default="scanmatcher_frame" />

    <node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">
        <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" />

        <param name="use_tf_scan_transformation" value="true" />
        <param name="use_tf_pose_start_estimate" value="false" />

        <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="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" />

        <param name="advertise_map_service" value="true" />
        <param name="scan_subscriber_queue_size" value="5" />
        <param name="scan_topic" value="scan" />

        <param name="tf_map_scanmatch_transform_frame_name" value="$(arg tf_map_scanmatch_transform_frame_name)" />
    </node>
</launch>

hector_test.launch

<?xml version="1.0"?>
<launch>
    <arg name="geotiff_map_file_path" default="$(find hector_geotiff)/maps" />

    <param name="/use_sim_time" value="false" />

    <node pkg="rviz" type="rviz" name="rviz"
        args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz" />

    <include file="$(find lms1xx)/launch/hector_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>

    <node pkg="tf" type="static_transform_publisher" name="map_to_odom" args="0.0 0.0 0.0 0.0 0.0 0.0 /odom /base_link 10"/>
    <node pkg="tf" type="static_transform_publisher" name="base_frame_laser" args="0.0 0.0 0.0 0.0 0.0 0.0 /base_link /laser 10"/>
</launch>

变化并不大,主要有4处:

  • base_frame和odom_frame都是base_link
    在这里插入图片描述
  • Map update parameters较官方有所变化,但未测试变化前后的区别 Hector-SLAM初使用_第2张图片
  • 将时间同步设置为false在这里插入图片描述
  • 通过TF坐标变换将/odom、/base_link、/laser三个坐标系固定在一起,视作一个坐标系 在这里插入图片描述

效果还不错,跑的时候既有TF坐标,也有绿色轨迹线,使用map_server保存地图

sudo apt-get install ros-melodic-map-server

rosrun map_server map_saver -f ~/catkin_ws/src/LMS1xx/map/my_map

Hector-SLAM初使用_第3张图片

在实验楼大厅跑了一下,可以看到立柱和标识牌

你可能感兴趣的:(SLAM,自动驾驶)