Ubuntu20安装并使用Cartographer建图导航

根据官网安装结合我实际安装的过程进行补充,仅供参考。这里的安装适合于新安装的ubuntu,使用时间长的ubuntu可能环境之间有冲突

一、安装Cartographer

官网安装链接:https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html

1、首先安装依赖
sudo apt-get update
sudo apt-get install -y python3-wstool python3-rosdep ninja-build stow
2、建立工作空间并下载Cartographer源码包
mkdir cartographer_ws
cd cartographer_ws
mkdir src
cd src
git clone https://github.com/googlecartographer/cartographer_ros.git
git clone https://github.com/googlecartographer/cartographer.git
git clone https://github.com/ceres-solver/ceres-solver.git

在src目录下你就会看到下面三个文件

3、安装cartographer的依赖
sudo rosdepc init
rosdepc update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
在执行最后一步的时候出现了一个错误
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
cartographer: [libabsl-dev] defined as "not available" for OS version [focal]
解决:最后一句可以看出没有libabsl-dev;所以找到cartographer下的package.xml文件将有关libabsl-dev的删掉
4、安装abseil-cpp(注意它和src是同一级目录)
src/cartographer/scripts/install_abseil.sh
5、编译
catkin_make_isolated --install --use-ninja

最后编译成功后

6、刷新环境的命令
source ~/cartographer_ws/install_isolated/setup.bash

至此,Cartographer安装成功

二、使用Cartographer进行建图

打开cartographer_ros/cartographer_ros/launch文件夹,新建一个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 demo01.lua" 
      output="screen">    <!-- 注意这里demo01.lua,改为自己的lua文件 -->
    <remap from="scan" to="scan" />
    <remap from="odom" to="odom" />
  </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>

打开configuration_files文件夹,新建.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更改为我们机器人的基坐标tf,一般是base_link,
    tracking_frame = "base_footprint",
  
    -- 以下四个参数与里程计有关,在下面进行单独说明
    odom_frame = "odom",
    published_frame = "base_footprint",
    provide_odom_frame = false,
    use_odometry = true,
  
    publish_frame_projected_to_2d = false,
    use_pose_extrapolator = true,
    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.
  -- 决定是否使用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 = 35
  POSE_GRAPH.constraint_builder.min_score = 0.65
  
  return options

然后进行编译(第一次编译慢,后面非常快)

catkin_make_isolated --install --use-ninja
 刷新环境
source ~/cartographer_ws/install_isolated/setup.bash

启动仿真小车,并运行刚刚在cartographer中写的launch文件进行建图

 保存地图

1、首先进入cartographer工作空间下,然后刷新环境变量,然后执行下面语句,完成轨迹, 停止进一步的数据
    rosservice call /finish_trajectory 0
2、将当前地图信息保存为后缀名为.pbstream
    rosservice call /write_state "{filename: '<绝对路径存放地图信息>/<地图保存的名字>.pbstream'}"
3、将后缀名为.pbstream的地图信息,转化成ros地图信息
    rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=<保存地图的绝对路径>/<地图命名> -pbstream_filename=<存放pbstream地图的绝对路径>/<filename>.pbstream -resolution=0.05

 

 至此地图保存完成。

三、使用Cartographer探索式建图

在启动建图的时候,直接启动move_base就行。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

没入&浅出

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

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

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

打赏作者

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

抵扣说明:

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

余额充值