cartographer 功能包已经与ROS集成,但是还没有提供二进制安装包,所以需要采用源码编译的方式进行安装。为了不与已有功能包冲突,最好为 cartographer专门创建一个工作空间,这里我们新创建了一个工作空间catkin_google_ws,然后使用如下步骤下载源码并完成编译,安装参考https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html。

安装工具:

wstool是用于管理ROS工作空间的工具,它通过.rosinstall文件规定工作空间的配置。
Ninja 是Google的一名程序员推出的注重速度的构建工具,一般在Unix/Linux上的程序通过make/makefile来构建编译,而Ninja通过将编译任务并行组织,大大提高了构建速度。

1.首先安装一些依赖

sudo apt-get install -y python-wstool python-rosdep ninja-build
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 apt-get install -y \
    cmake \
    g++ \
    git \
    google-mock \
    libboost-all-dev \
    libcairo2-dev \
    libeigen3-dev \
    libgflags-dev \
    libgoogle-glog-dev \
    liblua5.2-dev \
    libsuitesparse-dev \
    libwebp-dev \
    ninja-build \
    protobuf-compiler \
    python-sphinx

2.构建工作空间

 mkdir cartographer_ws
cd cartographer_ws
wstool init 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

3.安装protobuf3,卸载ros自带的proto2

VERSION=”v3.4.3”这条指令也是要输入的,这个版本非常重要,报错几乎都是跟这个版本有关,先把电脑自带的proto卸载,重新安装即可解决

$ VERSION="v3.4.3"
$ git clone protocolbuffers/protobuf
$ cd protobuf
$ git checkout tags/${VERSION}
$ 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

3.安装ceres-solver

$ VERSION="1.13.0"
$ git clone ceres-solver/ceres-solver
$ cd ceres-solver
$ git checkout tags/${VERSION}
$ mkdir build
$ cd build
$ cmake .. -G Ninja -DCXX11=ON
$ ninja
$ CTEST_OUTPUT_ON_FAILURE=1 ninja test
$ sudo ninja install

4.安装abseil-cpp

$ cd abseil-cpp
$ git checkout d902eb869bcfacc1bad14933ed9af4bed006d481
$ mkdir build
$ cd build
$ cmake -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
    -DCMAKE_INSTALL_PREFIX=/usr/local/stow/absl \
    ..
$ ninja
$ sudo ninja install
$ cd /usr/local/stow
$ sudo stow absl

5.编译cartographer

cd cartographer_ws
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=melodic -y

cd cartographer
mkdir build
cd build
cmake .. -G Ninja
ninja//需要很长时间
ninja test
sudo ninja install

6.编译安装

cd cartographer_ws
catkin_make_isolated --install --use-ninja//需要很长时间(下次编译会很快完成)
source install_isolated/setup.bash

7.测试

下载2D数据包并运行demo

wget -P ~/cartographer_ws/dataset https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
source ~/cartographer_ws/install_isolated/setup.bash
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/cartographer_ws/dataset/cartographer_paper_deutsches_museum.bag