其实一直以来都感觉纯视觉SLAM很难落地产品,所以一直在找机会学习激光slam,之前也在深蓝学院上买了一个激光salm的课程,惭愧,至今也没开始学呢,年底之前,我想工作之余研究一下激光slam和ros,我感觉这两个东西对我来说很重要,所以这两天先抽时间把google的cartographer工程配置了一下,期间也遇到了一些问题,不过我逐一解决,最终配置成功。接下来就开始研究激光slam技术,以及cartographer的代码。希望能帮上和我一起想开始学习cartographer的小伙伴,如果有什么问题,可以随时想我提问,大家一起学习。
更新:注意:我之前安装了conda,conda里面的python版本是3.7的,我在安装cartographer_ros的时候没有关闭conda所以出现了错误,因为ros只能在python2.7版本下才能正常工作,所以我就conda deactivate base.这样就恢复到了原来的python2.7的版本。
参考文献如下
https://google-cartographer.readthedocs.io/en/latest/
https://blog.csdn.net/xmy306538517/article/details/81455625
https://www.cnblogs.com/hitcm/p/5939507.html
step1:安装一些依赖库
# 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" ]]
thensudo apt-get install -y python3-sphinx libgmock-dev libceres-dev protobuf-compiler
elsesudo apt-get install -y python-sphinxif [[ "$(lsb_release -sc)" = "bionic" ]]thensudo apt-get install -y libceres-devfi
fi
step2: 安装abseil, 注意,在最后一步执行sudo stow absl之前要先执行sudo apt-get install stow安装stow
git clone https://github.com/abseil/abseil-cpp.git
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
step3: 这个下载链接是google的资源,如果你没有设置全局翻墙,在terminal不可翻墙,就不能下载成功,解决方法是在github里搜索ceres-solver,然后采用git clone的方式下载,如果在网页上直接Download下载下来的工程中灭有.git文件,无法完成git checkout tags/${VERSION}
VERSION="1.13.0"# Build and install Ceres.
git clone https://ceres-solver.googlesource.com/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
step4: 安装protobuf.使用下面的下载链接下载时如果一直出现early EOF的超时错误时,就使用
git clone --depth=1 https://github.com/google/protobuf.git 进行下载,--depth=1是约束了只下载最新git log的版本。
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
step5: 安装cartographer
# Build and install Cartographer.git clone git@github.com:cartographer-project/cartographer.git
cd cartographer
mkdir build
cd build
cmake .. -G Ninja
ninja
CTEST_OUTPUT_ON_FAILURE=1 ninja test
sudo ninja install
step6:安装cartographer_ros
注意:创建ros工程的workspace时,根据你自己的路径来就可以,还有在将工程的devel中的setup.bash的路径写入到.bashrc中时也要注意你的路径。这样做的好处你,你新打开一个窗口进行操作时,不需要重新执行source YOUR_PATH/devel/setup.bash了就。
sudo apt-get install -y python-wstool python-rosdep ninja-buildmkdir -p /code/ROS/catkin_ws_cartographer/src
cd /code/ROS/catkin_ws_cartographer/src
git clone --recursive https://github.com/googlecartographer/cartographer_ros.gitcd /code/ROS/catkin_ws_cartographer
catkin_make_isolated --install --use-ninja -Dcartographer_DIR="/usr/local/share/cartographer/"
source /code/ROS/catkin_ws_cartographer/devel_isolated/setup.bash
echo "source /code/ROS/catkin_ws_cartographer/devel_isolated/setup.bash" >> ~/.bashrc
step7:下载数据集
2d数据集:
https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
3d数据集:
https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/b3-2016-04-05-14-14-00.bag
step8: 运行程序
注意:修改成你自己的存放数据集的路径。
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/cartographer_3d_deutsches_museum.bag
step9: 测试结果展示