Cartographer ROS上的编译安装和配置

Cartographer是google推出的基于激光雷达的SLAM算法。

Cartographer官方的编译安装步骤可以在https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html#上查看。但是在国内由于网络的原因,这个步骤并不适用。这里介绍它在国内网络环境下的安装和配置。

首先需要安装ROS,这里就不涉及,可以参考ROS的文档进行。ROS具体的版本没有影响,可以是Kinetic或者Melodic。

1 编译安装

Step 1 安装依赖

1)  sudo apt-get update

2) sudo apt-get install -y python-wstool python-rosdep ninja-build

Step 2 创建目录carto_ws, 并初始化

  $ mkdir carto_ws

  $ cd carto_ws

  $ wstool init src

  输出如下:

robin@ubuntu:/home/bearpaw/carto_ws$ wstool init src

Writing /home/bearpaw/carto_ws/src/.rosinstall

update complete.

Step 3 新建一个文件/home/bearpaw/carto_ws/source.file

    https://github.com/cartographer-project/cartographer_ros/blob/master/cartographer_ros.rosinstall 文件中的内容复制到此文件

Step 4 执行 wstool merge -t src /home/bearpaw/carto_ws/source.file

输出如下:

robin@ubuntu:/home/bearpaw/carto_ws$ wstool merge -t src /home/bearpaw/carto_ws/source.file

     Performing actions:

     Add new elements:

  cartographer,  cartographer_ros,  ceres-solver

Config changed, maybe you need run wstool update to update SCM entries.

Overwriting /home/bearpaw/carto_ws/src/.rosinstall

update complete.

Step 5 执行完以上命令后,/home/bearpaw/carto_ws/src/.rosinstall中的内容为:

    # THIS IS AN AUTOGENERATED FILE, LAST GENERATED USING wstool ON 2020-07-01 

       - git: 

                local-name: cartographer 

                uri: https://github.com/cartographer-project/cartographer.git 

                version: 1.0.0 

        - git: 

                local-name: cartographer_ros 

               uri: https://github.com/cartographer-project/cartographer_ros.git 

               version: 1.0.0 

        - git: 

                local-name: ceres-solver 

                uri: https://ceres-solver.googlesource.com/ceres-solver.git

                version: 1.13.0

将最后一个git 替换为https://github.com/ceres-solver/ceres-solver.git

Step 6 执行wstool update -t src

输出如下:

 robin@ubuntu:/home/bearpaw/carto_ws$ wstool update -t src 

[cartographer] Fetching https://github.com/cartographer-project/cartographer.git (version 1.0.0) to /home/bearpaw/carto_ws/src/cartographer 

Cloning into '/home/bearpaw/carto_ws/src/cartographer'... 

remote: Enumerating objects: 21, done. 

remote: Counting objects: 100% (21/21), done. 

remote: Compressing objects: 100% (19/19), done. 

remote: Total 14043 (delta 5), reused 8 (delta 2), pack-reused 14022 Receiving objects: 100% (14043/14043), 5.44 MiB | 10.00 KiB/s, done. 

Resolving deltas: 100% (11187/11187), done. 

[cartographer] Done. 

[cartographer_ros] Fetching https://github.com/cartographer-project/cartographer_ros.git (version 1.0.0) to /home/bearpaw/carto_ws/src/cartographer_ros 

Cloning into '/home/bearpaw/carto_ws/src/cartographer_ros'... 

remote: Enumerating objects: 13, done. remote: Counting objects: 100% (13/13), done. 

remote: Compressing objects: 100% (12/12), done. 

remote: Total 4302 (delta 2), reused 1 (delta 1), pack-reused 4289 

Receiving objects: 100% (4302/4302), 4.09 MiB | 28.00 KiB/s, done. 

Resolving deltas: 100% (3140/3140), done. 

[cartographer_ros] Done. 

[ceres-solver] Fetching https://github.com/ceres-solver/ceres-solver.git (version 1.13.0) to /home/bearpaw/carto_ws/src/ceres-solver 

Cloning into '/home/bearpaw/carto_ws/src/ceres-solver'... 

remote: Enumerating objects: 8, done. 

remote: Counting objects: 100% (8/8), done. 

remote: Compressing objects: 100% (8/8), done. 

remote: Total 14355 (delta 0), reused 2 (delta 0), pack-reused 14347 

Receiving objects: 100% (14355/14355), 13.25 MiB | 30.00 KiB/s, done. 

Resolving deltas: 100% (9215/9215), done. 

[ceres-solver] Done.

Step 7 执行 src/cartographer/scripts/install_proto3.sh 

下载编译合适的proto3

输出如下:

robin@ubuntu:/home/bearpaw/carto_ws$ src/cartographer/scripts/install_proto3.sh

VERSION="v3.4.1"

# Build and install proto3.

git clone https://github.com/google/protobuf.git

Cloning into 'protobuf'...

remote: Enumerating objects: 12, done.

remote: Counting objects: 100% (12/12), done.

remote: Compressing objects: 100% (11/11), done.

注意:

1)第67步,实际上是下载几个github的包,如果网速慢,会经常下载失败,这时,可以直接从githubdownload zip包然后解压到相应的目录即可。

 github地址为:

   https://github.com/cartographer-project/cartographer      v1.0.0

   https://github.com/cartographer-project/cartographer_ros  v1.0.0

   https://github.com/ceres-solver/ceres-solver  v1.13.0

   https://github.com/google/protobuf   v3.4.1

目录结构如下布置:

robin@ubuntu:/home/bearpaw/carto_ws$ ls

     protobuf   src

robin@ubuntu:/home/bearpaw/carto_ws$ ls ./src/

     cartographer  cartographer_ros  ceres-solver

 2)protobuf下载完之后,将src/cartographer/scripts/install_proto3.sh的内容修改如下:

        $cat install_proto3.sh

       #!/bin/sh

       set -o errexit

       set -o verbose

      VERSION="v3.4.1"

      # Build and install proto3.

      cd protobuf

      mkdir build

      cd build

      cmake -G Ninja \

       -DCMAKE_POSITION_INDEPENDENT_CODE=ON \

       -DCMAKE_BUILD_TYPE=Release \

       -Dprotobuf_BUILD_TESTS=OFF \

      ../cmake

       ninja

       sudo ninja install

Step 8 执行下面三个命令,安装依赖

sudo rosdep init (以前执行过此命令,会报错, 忽略即可)

rosdep update

rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y

Step 9 编译安装

 >   catkin_make_isolated --install --use-ninja

 

2配置

2.1 配置文件

安装之后,配置文件位于/home/bearpaw/carto_ws/install_isolated/share/cartographer_ros/configuration_files

在此目录创建自己的配置文件, 我的名为bearpaw.lua,内容如下:

$ cat bearpaw.lua

-- Copyright 2016 The Cartographer Authors

include "map_builder.lua"

include "trajectory_builder.lua"

options = {

  map_builder = MAP_BUILDER,

  trajectory_builder = TRAJECTORY_BUILDER,

  map_frame = "map",

  tracking_frame = "base_footprint",

  published_frame = "base_footprint",

  odom_frame = "odom_combined",

  provide_odom_frame = true,

  publish_frame_projected_to_2d = false,

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

  fixed_frame_pose_sampling_ratio = 1.,

  odometry_sampling_ratio = 1.,

  imu_sampling_ratio = 1.,

  landmarks_sampling_ratio = 1.,

}

MAP_BUILDER.use_trajectory_builder_2d = true

TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true

TRAJECTORY_BUILDER_2D.use_imu_data = false

TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_search_window = 0.15

TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.angular_search_window = math.rad(35.)

POSE_GRAPH.optimization_problem.huber_scale = 1e2

标红色的内容需要根据自己的实际情况配置。

2.2 Launch file

配置文件之后,编写launch file,内容如下:

$ cat demo_bearpaw.launch

 

      type="cartographer_node" args="

          -configuration_directory

              $(find cartographer_ros)/configuration_files

          -configuration_basename bearpaw.lua"

      output="screen">

 

 

      type="cartographer_occupancy_grid_node" args="-resolution 0.05" />

 

下面就可以用这个launch 文件启动cartographer了。

你可能感兴趣的:(ROS+移动机器人)