当前位置: 首页 > 工具软件 > Cartographer > 使用案例 >

cartographer编译与运行

周作人
2023-12-01

cartographer编译与运行

1、下载源码

  1. 详细注释版
    GitHub - xiangli0608/cartographer_detailed_comments_ws: cartographer work space with detailed comments
  2. 官方版
    GitHub - cartographer-project/cartographer: Cartographer is a system that provides real-time simultaneous localization and mapping (SLAM) in 2D and 3D across multiple platforms and sensor configurations.
  3. 官方文档
    Cartographer — Cartographer documentation

2、安装依赖

# Install the required libraries that are available as debs.
sudo apt-get update
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

# Install Ceres Solver and Protocol Buffers support if available.
# No need to build it ourselves.
if [[ "$(lsb_release -sc)" = "focal" || "$(lsb_release -sc)" = "buster" ]]
then
  sudo apt-get install -y python3-sphinx libgmock-dev libceres-dev protobuf-compiler
else
  sudo apt-get install -y python-sphinx
  if [[ "$(lsb_release -sc)" = "bionic" ]]
  then
    sudo apt-get install -y libceres-dev
  fi
fi

复制按回车键即可

3、编译并安装Ceres

git clone https://ceres-solver.googlesource.com/ceres-solver
cd ceres-solver
mkdir build
cd build
cmake .. 
make install

4、安装wstool和rosdep

sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build

5、编译并安装

  1. 官方版安装
catkin_make_isolated --install --use-ninja
source install_isolated/setup.bash
  1. 注释版安装,执行catkin_make.sh脚本即可

6、运行官方例子

在之前生成的工作目录下

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

7、常见问题

Site Unreachable

  1. 提示找不到absl(官方自带脚本)
    解决方法:
 sudo apt-get install stow
 sudo chmod +x ~/carto_ws/src/cartographer/scripts/install_abseil.sh
 cd ~/carto_ws/src/cartographer/scripts
./install_abseil.sh
  1. Proto3报错(安装了proto2冲突)
    参考:Turtlebot3中级教程-Cartographer-turtlebot 安装 – 少儿编程教程网
cartographer/mapping/proto/trajectory_node_data.proto:15:10: Unrecognized syntax identifier "proto3".  This parser only recognizes "proto2".
ninja: build stopped: subcommand failed.
<== Failed to process package 'cartographer': 
  Command '['ninja']' returned non-zero exit status 1

解决方法:

sh src/cartographer/scripts/install_proto3.sh
sudo mv /usr/bin/protoc  /usr/bin/protoc.bk 
sudo ln -s /usr/local/bin/protoc /usr/bin/protoc

  1. 提示" 无法添加符号: DSO missing from command line collect2: error: ld returned 1 exit status",如下:
al/lib/libabsl_civil_time.a /usr/local/lib/libabsl_time_zone.a -lpthread && :
/usr/bin/ld: /usr/local/lib/liblua.a(loadlib.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libdl.so.2: 无法添加符号: DSO missing from command line
collect2: error: ld returned 1 exit status
[270/384] Building CXX object CMakeFiles/cartographer.mapping.map_builder_test.dir/cartographer/mapping/map_builder_test.cc.o
ninja: build stopped: subcommand failed.
<== Failed to process package 'cartographer': 
  Command '['ninja', '-j8', '-l8']' returned non-zero exit status 1

Reproduce this error by running:
==> cd /home/nie/cartographer_detailed_comments_ws/build_isolated/cartographer && ninja -j8 -l8

解决方法:

find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
find_package(Ceres REQUIRED COMPONENTS SuiteSparse)
find_package(Eigen3 REQUIRED)
find_package(LuaGoogle REQUIRED)
set(LUA_LIBRARIES "/usr/local/lib/liblua.a;/usr/lib/x86_64-linux-gnu/libdl.so")

  1. 当解决好问题1后,编译到cartographer_rviz时提示"lua_newstate’ can not be used when making a shared object; recompile with -fPIC"的问题,如下:
absl_strings.a /usr/local/lib/libabsl_strings_internal.a /usr/local/lib/libabsl_throw_delegate.a /usr/local/lib/libabsl_base.a /usr/local/lib/libabsl_dynamic_annotations.a /usr/local/lib/libabsl_spinlock_wait.a -lpthread /usr/local/lib/libabsl_int128.a /usr/local/lib/libabsl_civil_time.a /usr/local/lib/libabsl_time_zone.a -lpthread && :
/usr/bin/ld: /usr/local/lib/liblua.a(lstate.o): relocation R_X86_64_PC32 against symbol `lua_newstate' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: 最后的链结失败: 错误的值
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
<== Failed to process package 'cartographer_rviz': 
  Command '['/home/nie/cartographer_detailed_comments_ws/install_isolated/env.sh', 'ninja', '-j8', '-l8']' returned non-zero exit status 1

Reproduce this error by running:
==> cd /home/nie/cartographer_detailed_comments_ws/build_isolated/cartographer_rviz && /home/nie/cartographer_detailed_comments_ws/install_isolated/env.sh ninja -j8 -l8

解决方法,重新安装lua5.3

curl -R -O http://www.lua.org/ftp/lua-5.3.0.tar.gz
tar zxf lua-5.3.0.tar.gz
cd lua-5.3.0
make linux CFLAGS=-fPIC
sudo make install

注意,如果要二次编译lua5.3,记得要删除src下已经编译好的.o对象文件,再进行编译

cd lua-5.3.0/src
rm *.o
 类似资料: