程序员

cartographer仿真建图实现

作者:admin 2021-06-16 我要评论

最近我参加了航天智慧物流的线上赛成绩还没出来。我负责的是cartograher建图部分。我现在总结一下自己的一些学习和遇到的坑方便大家学习cartographer。 怎么安装...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

最近,我参加了航天智慧物流的线上赛,成绩还没出来。我负责的是cartograher建图部分。我现在总结一下自己的一些学习和遇到的坑,方便大家学习cartographer。
怎么安装cartograher我就不说了,网上都有详细的教程。在我的百度网盘里也有现成的包,链接:https://pan.baidu.com/s/1IL1rBxCwxqoYnz_jtQ9eyg
提取码:sirb
大家下下来,直接编译就可以了。。我想讲的是怎么实现cartographer仿真建图并且保证成功。 当然你需要有学习过ros的一些基础。
我只写在仿真环境中的建图,因为实际建图是雷达不同,launch文件的配置不同。如果不会配置可以大家交流。我的手持雷达建图配置如下:

<launch>


 <node pkg="tf" type="static_transform_publisher" name="base_link_to_laser4" 
    args="0.0 0.0 0.2 0.0 0.0  0.0 /base_link /velodyne 40" />

  <include file="$(find my_navigation)/launch/cartographer_demo.launch"/>
  <include file="$(find velodyne_pointcloud)/launch/VLP16_points.launch"/>


</launch>

下面是是仿真实现的具体内容,我默认大家是有一个仿真环境的,并且有一辆可移动小车。 如果没有我已经上传到百度网盘上了:链接:https://pan.baidu.com/s/1rug9U0etBWP2_KboPbww6Q
提取码:sirb
下载后记得编译。

It’s show time.
一:我在cartographer_ws/src/cartographer_ros/cartographer_ros/launch/cartographer_demo.launch下创建了cartographer_demo.launch文件。具体内容如下:

<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 lidar.lua"
      output="screen"> 
    <remap from="scan" to="scan" />  
  </node>  

  <!-- cartographer_occupancy_grid_node -->
  <node pkg="cartographer_ros" type="cartographer_occupancy_grid_node"
        name="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>

其实这个文件下面有很多demo文件,你可以改来用。你需要注意的是以下几点:

1.在demo中添加`

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

这个是实现建图必不可少的部分。

2.代码<param name="/use_sim_time" value="true" />在仿真时value 为true,但当你需要实际建图时,一定要改为false。不然它会报错,其实就是时间戳的问题,这里我就不过多赘述。
3.我们需要注意代码
<node name="cartographer_node" pkg="cartographer_ros" type="cartographer_node" args=" -configuration_directory $(find cartographer_ros)/configuration_files -configuration_basename lidar.lua"中lidar.lua,你需要改为自己的lua文件。不用怕不懂,我下面会对这个lua文件进行介绍。

二:下面是我的lidar.lua文件的具体内容,这个文件至关重要。网上有很多教程配置,大家一定要去看看。值得一提的是每次修改后,你需要重新编译。因为lua文件,它调用了别的文件,参数修改后会有一个整体的影响。一些重要代码的作用我已经标出。

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

options = {
  map_builder = MAP_BUILDER,
  trajectory_builder = TRAJECTORY_BUILDER,
  map_frame = "map",
  tracking_frame = "base_footprint", #改为自己激光雷达的frame_id,通常情况都是laser
  published_frame = "base_footprint", #改为自己激光雷达的frame_id,通常情况都是laser
  odom_frame = "odom",
  provide_odom_frame = true,
  publish_frame_projected_to_2d = false,
  use_odometry = true, #是否使用Odom数据在这里决定,改变之后记得编译
  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
use_pose_extrapolator = on
TRAJECTORY_BUILDER.collate_landmarks = on

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

return options

如果你下载的是我的包,首先对两个工作空间间进行编译。
在 cartographer_ws 下,执行 catkin_make_isolated --install --use-ninja
在 new_ws 下,执行 catkin_make
在.bashrc 文件底部加入:source ~/cartographer_ws/install_isolated/setup.bash 和
source ~/new_ws/devel/setup.bash
下面的三个launch文件都在new_ws下:
运行 1:roslaunch my_gazebo robot_laser_gazebo.launch
2:rosrun teleop_twist_keyboard teleop_twist_keyboard.py
3:roslaunch my_navigation cartographer_demo.launch
如果第二步不能成功,运行 sudo apt-get install ros-melodic-teleop-twist-keyboard
上述工作完成后就能移动键盘进行仿真建图啦。
下面附上建图效果:
在这里插入图片描述

在这里插入图片描述

;原文链接:https://blog.csdn.net/qq_52537255/article/details/115606432

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 从零学 Go:原生数据类型

    从零学 Go:原生数据类型

  • 从零学 Go:基本语法介绍之变量的声明

    从零学 Go:基本语法介绍之变量的声明

  • Go 语言入门系列:Go 语言环境安装

    Go 语言入门系列:Go 语言环境安装

  • hook入门学习心得

    hook入门学习心得

腾讯云代理商
海外云服务器