8

(零) 安装cartographer

 1 year ago
source link: https://charon-cheung.github.io/2022/11/22/%E6%BF%80%E5%85%89SLAM/Cartographer/%E5%8E%9F%E7%90%86%E5%92%8C%E9%85%8D%E7%BD%AE/(%E9%9B%B6)%20%E5%AE%89%E8%A3%85/#Protobuf
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

(零) 安装cartographer

(零) 安装cartographer
2022-11-22|激光SLAMCartographer原理和配置|
Word count: 1k|Reading time: 4 min

cartographer的安装非常复杂,尤其是proto脚本和各种依赖项,如果一次不成功,最好把proto或其他依赖库彻底删除重来,越改可能越乱,再也装不好了。

ros2的carto好像还是非常早期的版本,一些参数都不支持,先不必使用

# Install wstool and rosdep.
sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build

# Create a new workspace in 'catkin_ws'.
mkdir catkin_ws
cd catkin_ws
wstool init src

wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src

# 如果无法下载就打开上面的网页,下载三个文件,然后放到src中
#ceres选版本1.13以上,下载链接:https://ceres-solver.googlesource.com/ceres-solver.git,点击页面中的tgz可以下载

cd catkin_ws
# 安装proto3. 下载protobuf很可能失败,只好手动下载: git clone https://github.com/google/protobuf.git
source src/cartographer/scripts/install_proto3.sh

# The command 'sudo rosdep init' will print an error if you have already
# executed it since installing ROS. This error can be ignored.
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y

catkin_make_isolated --install --use-ninja
source install_isolated/setup.zsh

小强编译cartographer更新的lib文件在/home/xiaoqiang/Documents/ros/devel/lib/cartographer_ros

gtest问题

编译cartographer报错gtest

/usr/src/gtest/src/gtest.cc:1897:10: error: type ‘const class testing::internal::scoped_ptr<testing::internal::GTestFlagSaver>’ argument given to ‘delete’, expected pointer
delete gtest_flag_saver_;


估计是gtest的版本不兼容导致,从github上下载编译google-test,注意修改CMake支持c++14,否则连从github直接下载的源码编译也报错:

然后编译cartographer时,把几个重要的CMakeLists.txt也加上c++14的支持,否则所有的测试文件(以test.cc结尾的文件)编译都会出错

缺少liborocos-kdl库文件

默认的版本是1.3.2,这是下载地址

FindLuaGoogle

Could NOT find Lua (missing: LUA_LIBRARIES LUA_INCLUDE_DIR) 
CMake Error at cmake/modules/FindLuaGoogle.cmake:217 (MESSAGE):
Did not find Lua >= 5.2


解决: sudo apt-get install lua5.2 lua5.2-dev

absl库的问题

cartographer新版本要先安装abseil,否则报错

CI6bwA5gOhkV9LB.png
git clone https://github.com/abseil/abseil-cpp.git
cd abseil-cpp
cmake -L CMakeLists.txt && make
sudo make install

编译时会有个问题,需要加C++11,在absl文件夹里的CMakeList.txt里面添加set(CMAKE_CXX_FLAGS "-std=c++11") 或者 add_compile_options(-std=c++11)

如果还是缺少文件,就按照find_package的要求配置

缺abslTargets.cmake.png

编译cartographer_rviz出错.png


这个问题困扰我好久,最后终于发现在编译absl库时的cmake没有加 -fPIC flag,所以执行 cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON ..,这样就永久解决这个问题了。

要注意报错信息,找的是AbseilConfig.cmake 或者 abseilConfig.cmake,查看cartographer_rosCMakeLists。 我的abseil装完是在/usr/local/lib/cmake/absl/abslConfig.cmake

# 添加查找目录
set(Abseil_DIR "/usr/local/lib/cmake/absl")
find_package(Abseil REQUIRED)



后来我又用另一种方式解决了

从github下载 abseil-cpp-20190808.1,解压后执行

git clone https://github.com/abseil/abseil-cpp.git
cd abseil-cpp
git checkout 215105818dfde3174fe799600bb0f3cae233d0bf # 20211102.0
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

修改cartographer_ros/CMakeLists.txt的部分:

set(absl_DIR "/usr/local/stow/absl/lib/cmake/absl")
find_package(absl REQUIRED)

Protobuf

安装cartogapher新版本时候,编译后遇到Unrecognized syntax identifier "proto3". This parser only recognizes "proto2"。

检查protobuf版本: protoc --version 显示的是2.6版本。
使用locate protoc发现我有两个protc,在/usr/bin/usr/local/bin,分别检查版本,发现都是2.6。再次使用md5sum检查,发现两个文件完全一样

检查protoc.png

安装 Protobuf

# 版本不要太新
VERSION="v3.4.1"

# Build and install proto3.
git clone https://github.com/google/protobuf.git
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
sudo apt-get install autoconf autogen
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure
make
# 这一步可能会报错,无视就好
make check
sudo make install
sudo ldconfig # refresh shared library cache.


检查一下安装后protobuf的版本,protoc --version

编译器优先找了/usr/bin/protoc的版本, 新安装的proto3是放在/usr/local/bin/protoc下的,可以删除/usr/bin/protoc,然后把/usr/local/bin/protoc放入/usr/bin,或者建立软连接:

sudo mv /usr/bin/protoc /usr/bin/protoc.bk
sudo ln -s /usr/local/bin/protoc /usr/bin/protoc

有时编译遇到错误,只删除build_isolated/cartographer_ros/CMakeFiles即可,不用全删编译完成的文件


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK