0. 前言
最近群里有些老哥在问cartographer配置的相关问题,将我以前自己记录的文件测试后发现竟然已经失效,其原因在于cartographer官网对程序又进行了一次升级,以前的部分操作已经无法适用,这里在此记录一下。
1. 环境配置(melodic)
安装依赖包
sudo apt-get update
sudo apt-get install -y google-mock libboost-all-dev libeigen3-dev libgflags-dev libgoogle-glog-dev liblua5.2-dev libprotobuf-dev libsuitesparse-dev libwebp-dev ninja-build protobuf-compiler python-sphinx ros-melodic-tf2-eigen libatlas-base-dev libsuitesparse-dev liblapack-dev libpcl-dev pcl-tools automake
首先安装ceres solver
cd ~/Download
git clone https://github.com/Tengyun-Mo/ceres-solver.git
cd ceres-solver
mkdir build
cd build
cmake ..
make -j4
sudo make install
(默认路径为:usr/local/include)
安装protobuf 3.0
git clone https://github.com/google/protobuf.git
cd protobuf
git checkout v3.6.1
mkdir build
./autogen.sh
./configure
make -j2
sudo make install
sudo ldconfig
下面是作者在安装protobuf中遇到的一个问题
安装 cartographer
git clone https://github.com/googlecartographer/cartographer.git
cd cartographer
mkdir build
cd build
cmake ..
make -j4
sudo make install
如果出现absl找不到的情况:
git clone https://github.com/abseil/abseil-cppmkdir .git
打开abseil-cpp包里的cmakelists添加c++11支持
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -std=c++11")
build && cd build
cmake .. -DBUILD_SHARED_LIBS=ON
make
sudo make install
更改cartographer的CMakeList.txt文件(2处)和cartographer-config.cmake.in文件(1处)
CMakeList.txt 第1处:
find_package(Abseil REQUIRED) --> find_package(absl REQUIRED)
CMakeList.txt 第2处:#默认的库文件是 standalone_absl
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROTOBUF_LIBRARY}
absl::base
absl::synchronization
absl::strings
absl::flat_hash_map
absl::numeric
absl::flags)
然后重新编译即可
cartographer-config.cmake.in 1处:
find_package(Abseil ${QUIET_OR_REQUIRED_OPTION}) Abseil 改为 absl
安装cartographer_ros
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
git clone https://github.com/googlecartographer/cartographer_ros.git
cartographer_ros的CMakeList.txt,2处
cartographer_ros 和 cartographer_rviz的改法均一致:
find_package(Abseil REQUIRED) --> find_package(absl REQUIRED)
然后重新编译即可。
catkin_make
如果出现未定义应用,请注意Ceres和prtobuf 版本,并在Cmakelists里面修改
测试
运行程序 roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}``/Downloads/cartographer_paper_deutsches_museum``.bag