本篇主要介绍常用的slam功能包——cartographer,为谷歌开发,在计算资源有限的情况下,可以实现机器人在二维和三维条件下的定位及建图功能。目前该算法采用基于图网络的优化方法,主要基于激光雷达来实现SLAM。
两种安装方式,编译安装和二进制文件安装。如果后期,有编译自己代码的需要,建议编译安装。编译安装,又有两种方法,即一键安装和分步安装。
执行如下命令:
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-kinetic-tf2-eigen libatlas-base-dev libsuitesparse-dev liblapack-dev
为了不与现有功能包冲突,最好为cartographer专门创建一个工作空间catkin_google_ws,执行如下命令:
mkdir -p ~/catkin_google_ws/src
cd ~/catkin_google_ws/src
catkin_init_workspace
执行如下命令:
cd ~
git clone https://github.com/serapann/ros-kinetic-cartographer.git
cd ros-kinetic-cartographer
cp -R * ~/catkin_google_ws/src
依次执行如下命令:
cd ~/catkin_google_ws
catkin_make_isolated --install --use-ninja
等待一段时间,一键编译完成,效果如下:
添加环境变量,命令如下:
sudo echo "source ~/catkin_google_ws/install_isolated/setup.bash" >> ~/.bashrc
source ~/.bashrc
依次执行如下命令:
git clone https://github.com/hitcm/ceres-solver-1.11.0.git
cd ceres-solver-1.11.0
mkdir build
cd build
cmake ..
make -j4
sudo make install
git clone https://github.com/hitcm/cartographer.git
cd cartographer
mkdir build
cd build
cmake .. -G Ninja
ninja
ninja test
sudo ninja install
#安装cartographer_ros
cd ~/catkin_google_ws/src
git clone https://github.com/hitcm/cartographer_ros.git
为了区分catkin_make和catkin_make_isolated之间的区别,这里两种编译过程都记录下。
cd ~/catkin_google_ws
catkin_make
因为上面操作将cartographer、ceres-solver、cartographer_ros都放进来了,报如下错误:
说前两者不能cmake,没有可以catkin编译的功能包,请使用catkin_ catkin_make_isolated编译。因为已经安装完前两者了,可以执行如下命令删掉:
cd ~/catkin_google_ws/src
rm -rf ceres-solver cartographer
然后再进行catkin_make编译:
cd ~/catkin_google_ws
catkin_make
编译完成后,效果如下:
添加环境变量,执行如下命令:
sudo echo "source ~/catkin_google_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
或者打开该文件,在文件尾添加如下一行:
gedit ~/.bashrc
source /home/zt/catkin_google_ws/devel/setup.bash
执行如下命令:
cd ~/catkin_google_ws
catkin_make_isolated
你会发现使用catkin_make_isolated编译的时间会明显更长,是一轮一轮编译的,catkin_make则不是。
catkin_make编译,在根目录生成build和devel 两个文件夹,而catkin_make_isolated编译,则在根目录生成build_isolated和devel_isolated两个文件夹。
编译完成后,效果如下:
添加环境变量,执行如下命令:
sudo echo "source ~/catkin_google_ws/devel_isolated/setup.bash" >> ~/.bashrc
source ~/.bashrc
ros在2019年7月份已经将cartographer集成在软件源里,可以使用如下命令直接安装:
sudo apt-get install ros-kinetic-cartographer*
我是使用的编译安装,二进制文件安装,没有尝试。
执行如下命令,下载2D数据集:
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
效果如下:
将下载好的数据集文件cartographer_paper_deutsches_museum.bag,移动到catkin_google_ws/src目录下,执行命令:
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/catkin_google_ws/src/cartographer_paper_deutsches_museum.bag
效果如下:
执行如下命令,下载3D数据集(文件较大):
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/b3-2016-04-05-14-14-00.bag
效果如下:
将下载好的数据集文件b3-2016-04-05-14-14-00.bag,移动到catkin_google_ws/src目录下,执行命令:
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/catkin_google_ws/src/b3-2016-04-05-14-14-00.bag
效果如下:
该demo使用3D雷达建模,可以调整RVIZ中的视角,看到3D雷达的信息。