机器人之Cartographer


此文仅作为自身学习使用。

简介

整体而言,Local SLAM 部分负责生成较好的子图,Global SLAM 进行全局优化,将子图最佳 match 在一起。
就使用 cartographer 需要构建至少两个文件,一个是启动的 launch 文件,另一个是建图时所使用的 lua 配置参数。

传送门:ROS & Cartographer 官方文档

框架介绍

可执行节点

在cartographer中,官方提供了以下可执行功能包,其中开源的代码包含两部分:cartographer 和 cartographer_ros 。其中 cartographer 主要负责处理来自雷达、IMU 和 Odom 的数据,并基于这些数据完成地图的构建,是 cartographer 理论的底层实现。cartographer_ros 则是底层与 ros 通信的桥梁。
下面是cartographer_ws中的功能包。

# rospack list | grep cartographer

其中可执行文件如图所示,在进行建图研究时,一般运行 cartographer_node 和 cartographer_occupancy_grid_node 这两个节点。
在这里插入图片描述

建图参数

传送门:官方参数配置

  1. 进入配置文件参数设置: roscd cartographer_ros/configuration_files/
    一般会进入到
    cartographer_ws/install_isolated/share/cartographer_ros/configuration_files/
  2. 编写lua文件,最终命名为: <配置文件名>.lua

==> 其中lua文件关于坐标系的参数可以设置,

--	map_frame			:	cartographer 创建的 map 坐标系
--	tracking_frame		:	作为机器人的基坐标系就行,一般是 base_link 或 base_footprint
--	use_odometry		:	控制 cartographer 是否使用 odom 信息
--	provide_odom_frame	:	控制 cartographer 是否提供 odom 
--	odom_frame			:	当 carto 提供 odom 时有效,设置 cartographer 提供 odom 名称 
--	publish_odom_frame	:	设置 "base_footprint" 就行, map_frame -> "base_footprint"

-- 	如 1 : 无里程计,但需要odom 到 map的变换,可设置为
  	use_odometry = false,
  	provide_odom_frame = true,
  	published_frame = "base_footprint",
  	odom_frame = "odom",
-- 如 2 : 无里程计,直接输出map->base_link
  	use_odometry = false,
  	provide_odom_frame = false,
  	published_frame = "base_footprint",
  	odom_frame = "odom",

==> 完整的2D激光雷达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",
  use_odometry = false,
  provide_odom_frame = false,
  odom_frame = "odom",
  published_frame = "base_footprint",  

  --  传感器设置
  publish_frame_projected_to_2d = false,        --发布的参考系投射到2D,即 pose 限制为 2D 姿态
  use_nav_sat = false,                          --如果启用,则订阅主题“fix”上的sensor_msgs/NavSatFix。在这种情况下,必须提供导航数据,并且该信息将包含在全局SLAM中
  use_landmarks = false,                        --如果启用,则订阅主题“landmarks”上的cartographer_ros_msgs/地标列表。必须提供地标,如cartographer_ros_msgs/LandmarkList中的cartographer_ros_msgs/LandmarkEntry。
  num_laser_scans = 1,                          --要订阅的激光雷达/scan的数目,若多个则为/scan_1、scan_2
  num_multi_echo_laser_scans = 0,               --要订阅的多回波激光扫描主题的数量
  num_subdivisions_per_laser_scan = 1,          --要将每个接收的(多回波)激光扫描分成的点云数
  num_point_clouds = 0,                         --订阅的点云主题数
  
  --  发布时间设置
  lookup_transform_timeout_sec = 0.2,           --查找变换的超时时间(s)
  submap_publish_period_sec = 0.3,              --子图发布的周期(s),如0.3
  pose_publish_period_sec = 5e-3,               --发布pose的周期(s),如5e-3意味着200Hz
  --publish_to_tf=true,                         --是否发布TF
  --publish_tracked_pose=true,                  --是否发布一个 tracked pose 到 话题  “tracked_pose
  trajectory_publish_period_sec = 30e-3,        --发布轨迹的时间周期(s),30e-3意味着30ms
  
  --Fixed ratio sampling
  rangefinder_sampling_ratio = 1.,              --range finders messages 的固定比率采样
  odometry_sampling_ratio = 1.,                 --里程计消息的固定比率采样
  fixed_frame_pose_sampling_ratio = 1.,         --固定参考系消息的固定比率采样
  imu_sampling_ratio = 1.,                      --IMU消息的固定比率采样
  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.
-- 决定是否使用IMU
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 = 0
POSE_GRAPH.constraint_builder.min_score = 0.65

return options

launch文件

一般而言,launch文件的放置比较自由,所以此处仅说明 launch 文件编写方式。以下格式为参考官方的 launch 文件而来。

<launch>
    <!-- 0. 配置文件名 -->
    <arg name="config_file_name" value="xtark_robot.lua"/>

    <!-- 1. 启动cartographer_node -->
    <node   name="cartographer_node" pkg="cartographer_ros" type="cartographer_node"
            args="
                -configuration_directory $(find cartographer_ros)/configuration_files
                -configuration_basename $(arg config_file_name)"
            output="screen">
        <remap from="scan" to="/scan"/>
    </node>

    <!-- 2. 启动cartographer_occupancy_grid_node -->
    <node   name="cartographer_occupancy_grid_node" pkg="cartographer_ros" type="cartographer_occupancy_grid_node" args="-resolution 0.05"/>
</launch>

安装方法(更新中。。。)

  1. 源码安装时所需依赖
sudo apt-get install -y \
    clang \
    cmake \
    g++ \
    git \
    google-mock \
    libboost-all-dev \
    libcairo2-dev \
    libcurl4-openssl-dev \
    libeigen3-dev \
    libgflags-dev \
    libgoogle-glog-dev \
    liblua5.2-dev \
    libsuitesparse-dev \
    lsb-release \
    ninja-build \
    stow

修改服务器域名以更快的下载

sudo vi/etc/resolv.conf
# 注释掉原本的nameserver & 添加
nameserver 8.8.8.8
nameserver 8.8.4.4
# 下载完记得改回去

参考:

知乎:Cartographer建图实操

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

酸奶可乐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值