谷歌cartographer算法手持二维激光雷达建图(不使用里程计及IMU)

记录一下自己使用cartographer算法的建图经历,重点讲述一些调整参数时容易遇到的坑和一些容易忽视但很重要的细节,下一篇文章讲二维激光雷达融合IMU如何建图(博主刚刚做完整个流程中途遇到了很多坑,还好最后慢慢解决了,仔细的记录一下一些小白容易忽视的细节,亲测有效哦)。

我的激光雷达型号是思岚s1,思岚s1有提供ros启动包下载好启动就可以了,如果有用思岚激光雷达的小伙伴可以参考这个网址。(只要可以实现点云信息的发布就好。)ROS与激光雷达入门教程-ROS中使用激光雷达(思岚S1) - 创客智造

在开始调整cartographer包参数之前最重要的一步是知道你雷达的话题名称及frame_id。首先启动雷达,你雷达的frame_id就是图中画红圈的,我的是laser。

roslaunch rplidar_ros view_rplidar_s1.launch  

 接下来就是查看雷达的话题名称,打开终端输入:

rostopic list

可以看到雷达topic名称一般都是scan。同时还有另一种方法查询雷达的fram_id,就是在终端输入:

rostopic echo /topic | grep frame_id

其中topic名称输入你雷达的话题名称就可,我的话题名称是scan所以输入:

rostopic echo /scan | grep frame_id

 这样就能查到话题scan的fram_id啦。通过以上操作我得知了我的雷达话题是scan、fram_id是laser。

 接下来就是调整cartographer的参数,首先修改~/google_ws/src/cartographer_ros/cartographer_ros/configuration_files目录下的revo_lds.lua文件,修改好的文件如下所示

-- Copyright 2016 The Cartographer Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

include "map_builder.lua"
include "trajectory_builder.lua"

options = {
  map_builder = MAP_BUILDER,
  trajectory_builder = TRAJECTORY_BUILDER,
  map_frame = "map",
  tracking_frame = "laser",
  published_frame = "laser",
  odom_frame = "odom",
  provide_odom_frame = true,
  publish_frame_projected_to_2d = false,
  use_pose_extrapolator = true,
  use_odometry = false,
  use_nav_sat = false,
  use_landmarks = false,
  num_laser_scans = 1,
  num_multi_echo_laser_scans = 0,
  num_subdivisions_per_laser_scan = 1,
  num_point_clouds = 0,
  lookup_transform_timeout_sec = 0.2,
  submap_publish_period_sec = 0.3,
  pose_publish_period_sec = 5e-3,
  trajectory_publish_period_sec = 30e-3,
  rangefinder_sampling_ratio = 1.,
  odometry_sampling_ratio = 1.,
  fixed_frame_pose_sampling_ratio = 1.,
  imu_sampling_ratio = 1.,
  landmarks_sampling_ratio = 1.,
}

MAP_BUILDER.use_trajectory_builder_2d = true

TRAJECTORY_BUILDER_2D.submaps.num_range_data = 35
TRAJECTORY_BUILDER_2D.min_range = 0.3
TRAJECTORY_BUILDER_2D.max_range = 8.
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 1.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_search_window = 0.1
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.translation_delta_cost_weight = 10.
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.rotation_delta_cost_weight = 1e-1

POSE_GRAPH.optimization_problem.huber_scale = 1e2
POSE_GRAPH.optimize_every_n_nodes = 35
POSE_GRAPH.constraint_builder.min_score = 0.65

return options

其中比较关键的是

 tracking_frame = "laser",
  published_frame = "laser",

一定要设置为自己雷达的fram_id。

接下来就对 ~/google_ws/src/cartographer_ros/cartographer_ros/launch目录下的demo_revo_lds.launch  文件进行修改,修改后如下所示

<!--
  Copyright 2016 The Cartographer Authors
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
       http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
 
<launch>
  <param name="/use_sim_time" value="true" />
 
  <node name="cartographer_node" pkg="cartographer_ros"
      type="cartographer_node" args="
          -configuration_directory $(find cartographer_ros)/configuration_files
          -configuration_basename revo_lds.lua"
      output="screen">
    <remap from="scan" to="scan" />
  </node>
 
  <node name="rviz" pkg="rviz" type="rviz" required="true"
      args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />
  
</launch>

主要修改的地方就是<remap from="scan" to="scan" />scan是雷达的话题名称。

还有args=" -configuration_directory $(find cartographer_ros)/configuration_files -configuration_basename revo_lds.lua"里的revo_lds.lua一定要对应我们之前修改的lua文件的名称。

一切设置完毕后就是分别运行激光雷达和demo_revo_lds.launch文件啦。 

roslaunch rplidar_ros view_rplidar_s1.launch  

记得运行cartographer算法的时候要catkin_make_isolated --install --use-ninja。

source install_isolated/setup.bash
catkin_make_isolated --install --use-ninja
roslaunch google_ws demo_revo_lds.launch  

算法运行成功大概就是这样,接下来就可以移动雷达去建图啦。

如果觉着分开启动很麻烦可以把雷达和cartographer的启动文件写在一个launch文件里,不过得把雷达的ros包放在cartographer包同一个工作空间中,

 雷达和cartographer在一个launch文件的启动如下文件所示:

<!--
  Copyright 2016 The Cartographer Authors

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

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

  <node name="rplidarNode"          pkg="rplidar_ros"  type="rplidarNode" output="screen">
  <param name="serial_port"         type="string" value="/dev/ttyUSB0"/>  
  <param name="serial_baudrate"     type="int"    value="256000"/>
  <param name="frame_id"            type="string" value="laser"/>
  <param name="inverted"            type="bool"   value="false"/>
  <param name="angle_compensate"    type="bool"   value="true"/>
  </node>

  <node name="cartographer_node" pkg="cartographer_ros"
      type="cartographer_node" args="
          -configuration_directory $(find cartographer_ros)/configuration_files
          -configuration_basename revo_sc.lua"
      output="screen">
    <remap from="scan" to="scan" />
  </node>

  <node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"
      type="cartographer_occupancy_grid_node" args="-resolution 0.05" />

  <node name="rviz" pkg="rviz" type="rviz" required="true"
      args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />
 
</launch>

其中比较容易出错的点是<param name="/use_sim_time" value="true" />要改为<param name="/use_sim_time" value="false" />剩下的就没什么啦,建立完launch文件直接启动就可以啦。

source install_isolated/setup.bash
catkin_make_isolated --install --use-ninja
roslaunch google_ws demo_revo_lds.launch  

分别用cartographer算法分别在室内与室外分别测试了一下,发现室内的建图效果还是不错的不结合里程计也能建的比较精确了。但在室外会出现回环点匹配不精确的问题导致图的位置发生漂移。在一下篇文章博主会记录一下融合IMU与cartographer算法进行slam建图的过程。(希望这篇文章能够帮到大家,助大家生活愉快,学业顺利。(*^▽^*))

 实验室内

室外

  • 20
    点赞
  • 103
    收藏
    觉得还不错? 一键收藏
  • 21
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值