目录
一、前提条件
二、开始安装
三、验证
1-下载官方数据集
2-结果演示
3-地图保存
4-Cartographer先验地图的纯定位验证
根据SLAM学习之路(五)Ubuntu18.04系统安装ROS melodic博文中首先确定已经完成Melodic的安装并解决 rosdep init与rosdep update的问题(不解决在安装Cartographer时某一布会报错,但不影响Cartographer的使用。TIPS:最好解决一下)
最好插个网线(不然贼慢)。
1-更新系统软件库(习惯使用apt)
sudo apt update
2-安装工具
由于Cartographer编译是通过Google-ninja工具,需要进行安装
sudo apt install -y python-wstool python-rosdep ninja-build
3-创建工作空间
这里采用递归创建,即:
mkdir -p cart_ws/src
cd src
wstool init src
wstool:用于多版本的系统来维护项目的工作空间,详情可以查看wstool ros空间管理工具。运行wstool init src后显示update complele,即workspace更新完成。
4-下载cartographer功能包,并更新src
wstool merge -t src https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src
若出现ERROR in config: Unable to download URL [https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall]:
5-更改下载cartographer的下载地址
由于cartographer源码在raw.githubusercontent.com中,无法访问,则更改源码的下载地址。打开对应的 cart_ws/src 显示隐藏文件.rosintall
将其中内容更改为
# THIS IS AN AUTOGENERATED FILE, LAST GENERATED USING wstool ON 2022-08-04
- git:
local-name: cartographer
uri: https://github.com/googlecartographer/cartographer.git
version: 1.0.0
- git:
local-name: cartographer_ros
uri: https://github.com/googlecartographer/cartographer_ros.git
version: 1.0.0
- git:
local-name: ceres-solver
uri: https://github.com/ceres-solver/ceres-solver.git
version: 1.13.0
第5步后执行第四步,若还无法下载,直接进行第6步(更改DNS配置我就不作了,各位大佬可以试一试)
6-如果还下载失败,可以自行下载解压至src中
cartographer下载地址
cartographer_ros下载地址
ceres_solver下载地址
7-添加依赖
src/cartographer/scripts/install_abseil.sh
在这一步 最后如果出现
cd /usr/local/stow
sudo stow absl
sudo: stow:找不到命令
则自行安装stow,然后执行以下操作:
sudo apt install stow
cd /usr/local/stow/
sudo stow absl
8-执行依赖操作
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y -i -r
最后一行代码出现 #All required rosdeps installed successfully 即完成一大段了。
9-编译
catkin_make_isolated --install --use-ninja
此时等待安装完成即可,时间比较久。
TIPS:编译时遇到了[163:xxx]这里忘记截图了,这个把workspace,即 cart_ws 中的 abeil_cpp 文件删掉即可。
10-配置环境变量
echo 'source ~/cart_ws/install_isolated/setup.bash' >> ~/.bashrc
source ~/.bashrc
至此,cartographer安装部分已经完成,下一步开始跑官方的数据集,来验证是否安装成功。
这里下载的是3D_demo数据集
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/with_intensities/b3-2016-04-05-14-14-00.bag
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag
这个是官方的2D_demo数据集
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag
3D_demo:
2D_demo:
首先停止建图
rosservice call /finish_trajectory 0
保存地图至pbstream格式(自行对比改文件路径与文件名称)
rosservice call /write_state "{filename: '${HOME}/cart_ws/src/Mapping/carto_map.pbstream'}"
rosservice call /write_state "{filename: '${HOME}/文件路径/文件名称.pbstream'}"
将pbstream格式地图转为pgm与yaml
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${HOME}/cart_ws/src/Mapping/carto_map -pbstream_filename=${HOME}/cart_ws/src/Mapping/carto_map.pbstream -resolution=0.02
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem${HOME}/文件路径/文件名称 -pbstream_filename=${HOME}/文件路径/文件名称.pbstream -resolution=分辨率值
在进行纯定位的官方demo我们需要下载两个bag,其中一个用于官方的先验地图构建,另一个作为纯定位的bag复现
先验地图构建:
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/b2-2016-04-05-14-44-52.bag
纯定位bag复现:
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/b2-2016-04-27-12-31-41.bag
首先我们先进行建图,来满足先验地图这个前提,运行:
roslaunch cartographer_ros offline_backpack_2d.launch bag_filenames:=${HOME}/Downloads/b2-2016-04-05-14-44-52.bag
运行完成后在官方的demo中已经进行了地图的保存,运行完成后,Ctrl+C中止进程,在Downloads下可以看到 b2-2016-04-05-14-44-52.bag.pbstream 地图,运行:
roslaunch cartographer_ros demo_backpack_2d_localization.launch \
load_state_filename:=${HOME}/Downloads/b2-2016-04-05-14-44-52.bag.pbstream \
bag_filename:=${HOME}/Downloads/b2-2016-04-27-12-31-41.bag
即可看看官方demo的纯定位功能验证,效果如图: