cartographer功能包
cartographer安装
由于cartographer功能包与ROS集成,但没有提供二进制安装包,需要采用源码安装,可参考Cartographer 官网安装教程。
(1)安装工具
In order to build Cartographer ROS, we recommend using wstool and rosdep. For faster builds, we also recommend using Ninja.
$ sudo apt-get update
$ sudo apt-get install -y python-wstool python-rosdep ninja-build
(2)初始化命令空间并安装依赖
Create a new cartographer_ros 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
在进行 wstool update -t src
这一步之前,需要替换ceres-solver 源。(Ctrl+h 是否查看隐藏文件)
$ gedit catkin_ws/src/.rosinstall
将https://ceres-solver.googlesource.com/ceres-solver.git
改为https://github.com/ceres-solver/ceres-solver.git
(3)安装proto3以及相关功能包
Install cartographer_ros’ dependencies (proto3 and deb packages). The command ‘sudo rosdep init’ will print an error if you have already executed it since installing ROS. This error can be ignored.
$ src/cartographer/scripts/install_proto3.sh
$ sudo rosdep init
$ rosdep update
$ rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
正确安装完成后会出现:#All required rosdeps installed successfully
提示。
(4)编译并安装
Build and install.
$ catkin_make_isolated --install --use-ninja
$ source install_isolated/setup.bash
注意:catkin_make_isolated --install --use-ninja
一步可能出现虚拟内存耗尽问题。可扩展 swap 交换空间内存解决。
测试
2D SLAM demo
- Download the 2D backpack example bag.
$ wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
- Launch the 2D backpack demo.
$ roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag
map save
$ cd catkin_ws
$ source install_isolated/setup.bash
$ rosservice call /finish_trajectory 0
$ rosservice call /write_state "{filename: '${HOME}/Downloads/mymap.pbstream'}"
$ rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${HOME}/Downloads/mymap -pbstream_filename=${HOME}/Downloads/mymap.pbstream -resolution=0.05
3D SLAM demo
- Download the 3D backpack example bag.
$ wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/with_intensities/b3-2016-04-05-14-14-00.bag
- Launch the 3D backpack demo.
$ roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag
Revo LDS demo
- Download the Revo LDS backpack example bag.
$ wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/revo_lds/cartographer_paper_revo_lds.bag
- Launch the Revo LDS backpack demo.
$ roslaunch cartographer_ros demo_revo_lds.launch bag_filename:=${HOME}/Downloads/cartographer_paper_revo_lds.bag
安装常见问题
安装 protobuf 最新版
$ sudo apt-get install autoconf automake libtool curl make g++ unzip #安装依赖
$ git clone https://github.com/google/protobuf #下载protobuf源码
$ cd protobuf
$ ./autogen.sh
$ ./configure
$ make #编译
$ make check
$ sudo make install
$ sudo ldconfig #用于刷新共享库的缓存的
$ protoc --version #查看protobuf版本号
扩展 swap 交换空间内存
#下面以增加2G空间为例,count表示增加的块数量(文件大小=bs*count)
$ dd if =/dev/zero of=/root/swapfile bs=1M count=2048
#格式化交换分区文件
$ sudo mkswap /root/swapfile
#启用交换分区文件
$ sudo swapon /root/swapfile
#保存以上配置,重启后仍然有效,需要在文件/etc/fstab中添加下面一行
$ /root/swapfile swap swap defaults 0 0