使用Google Cartographer算法在Turtlebot等移动平台上跑SLAM

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011736771/article/details/72824782

使用Google Cartographer算法在Turtlebot等移动平台上跑SLAM

本人系统为 Ubuntu 14.04.5,ROS 版本为 Indigo,使用到的平台有 Turtlebot,Guardian,使用到的传感器有深度相机(Kinect,Asus Xtion Live Pro),激光雷达(Hokuyo URG-04LX,UTM-30LX)

Cartographer是Google的实时室内建图项目,最初用在带有传感器的谷歌背包(backpack)上面,可以生成分辨率为 5cm 的 2D 格网地图。

Cartographer 获得的每一帧 laser scan 数据,利用 scan match 在最佳估计位置处插入子图(submap)中,且 scan matching 只跟当前 submap 有关。在生成一个 submap 后,会进行一次局部的回环(loop close),利用分支定位和预先计算的网格,所有 submap 完成后,会进行全局的回环[1]。

理论的东西我就搞不懂了……先看看怎么用再说吧……

1. 系统要求及准备

参考官方说明文档[2],对于系统有如下要求:

System Requirements:
· 64-bit, modern CPU (e.g. 3rd generation i7)
· 16 GB RAM
· Ubuntu 14.04 (Trusty) and 16.04 (Xenial)
· gcc version 4.8.4 and 5.4.0
· ROS version Indigo and Kinetic

先安装一些需要的库和依赖包:

sudo apt-get update
sudo apt-get install -y cmake g++ git google-mock libboost-all-dev libcairo2-dev libeigen3-dev libgflags-dev libgoogle-glog-dev liblua5.2-dev libprotobuf-dev libsuitesparse-dev libwebp-dev ninja-build protobuf-compiler python-sphinx

2. 安装Cartographer

看了很多资料,比如:
谷歌开源SLAM库cartographer在Turltlebot的应用
创客智造-ROS与SLAM入门教程-cartographer在Turltlebot的应用

目前多采用两种方式安装,一是用官方的方法(需要翻墙),二是用来自hitcm的安装方法(不需要翻墙)。由于官方的源码一直在更新,我比较推荐用官方方法来安装。hitcm的方法比较早就出现了,不过现在距离代码发布都过了大半年了,不知道是不是因为代码更新的原因,反正我用hitcm的方法安装了几次是没有成功过……用官方方法安装也可以不用翻墙,下文中将会介绍。

用官方方法不翻墙安装Cartographer:

# 安装编译工具
sudo apt-get install -y python-wstool python-rosdep ninja-build

# 创建工作空间
mkdir google_carto_ws
cd google_carto_ws
wstool init src

# 安装源码包
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_turtlebot/master/cartographer_turtlebot.rosinstall
wstool update -t src    # 执行本步骤若出错请看下文的说明

# 安装源码包的依赖
rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y

# 编译并安装
catkin_make_isolated --install --use-ninja
source install_isolated/setup.bash

说明:
如果你挂了 VPN ,一般不会出错。
如果你没有翻墙,会出现无法下载 ceres-solver 的问题,我们可以修改其下载地址[3]:
1) 修改 google_carto_ws/src/.rosinstall 文件
2) 修改 google_carto_ws/src/cartographter_ros/cartographter_ros.rosinstall 文件
将两个文件中的 ceres-solver 路径改为从 github 下载
https://github.com/ceres-solver/ceres-solver.git

下面是我的 .rosinstall 文件的内容:

# THIS IS AN AUTOGENERATED FILE, LAST GENERATED USING wstool ON 2017-05-28
- git:
    local-name: cartographer
    uri: https://github.com/googlecartographer/cartographer.git
- git:
    local-name: cartographer_ros
    uri: https://github.com/googlecartographer/cartographer_ros.git
- git:
    local-name: ceres-solver
    uri: https://github.com/ceres-solver/ceres-solver.git
    version: 1.12.0rc4
- git:
    local-name: cartographer_turtlebot
    uri: https://github.com/googlecartographer/cartographer_turtlebot.git   
- git:
    local-name: cartographer_fetch
    uri: https://github.com/googlecartographer/cartographer_fetch.git  

下面是我的 cartographter_ros.rosinstall 文件的内容:

- git: {local-name: cartographer, uri: 'https://github.com/googlecartographer/cartographer.git'}
- git: {local-name: cartographer_ros, uri: 'https://github.com/googlecartographer/cartographer_ros.git'}
- git: {local-name: ceres-solver, uri: 'https://ceres-solver.googlesource.com/ceres-solver.git', version: '1.12.0rc4'}
- git: {local-name: cartographer_turtlebot, uri: 'https://github.com/googlecartographer/cartographer_turtlebot.git'}
- git: {local-name: cartographer_fetch, uri: 'https://github.com/googlecartographer/cartographer_fetch.git'}

可以看出来它下载了 cartographer, cartographer_ros , cartographer_turtlebot 和 ceres-solver 源码。这里我还添加了 cartographer_fetch 包的路径(未来实验室要买一台 Fetch ,到时候可以用上啦)

到这里编译成功,我们就可以愉快地使用啦!

3. 测试 Cartographer(跑虚拟实验)

要跑虚拟实验就得先下载官方提供的几个 bag:
(更多bags的下载可以见参考资料[4])

# cartographer_paper_deutsches_museum.bag (2d数据,493M)
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag

# cartographer_paper_deutsches_museum.bag (3d数据,8G左右)
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/b3-2016-04-05-14-14-00.bag

# cartographer_turtlebot_demo.bag(跑Turtlebot的仿真,4.5G)
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/turtlebot/cartographer_turtlebot_demo.bag

# cartographer_freight_simulation_demo.bag.(跑Fetch的仿真)
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/fetch/cartographer_freight_simulation_demo.bag

数据量太大,可以直接进入上面代码中的网址用迅雷下载。
下载好 bags 后,可以开始测试了:

## 跑Backpack:
# 2D demo
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=~/Downloads/cartographer_paper_deutsches_museum.bag
# 3D demo
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=~/Downloads/b3-2016-04-05-14-14-00.bag

## 跑Turtlebot:
# Launch the 2D LIDAR demo.(2D雷达DEMO)
roslaunch cartographer_turtlebot demo_lidar_2d.launch bag_filename:=~/Downloads/cartographer_turtlebot_demo.bag

# Launch the 2D depth camera demo.(2D深度相机DEMO)
roslaunch cartographer_turtlebot demo_depth_camera_2d.launch bag_filename:=~/Downloads/cartographer_turtlebot_demo.bag

# Launch the 3D depth camera demo.(3D深度相机DEMO)
roslaunch cartographer_turtlebot demo_depth_camera_3d.launch bag_filename:=~/Downloads/cartographer_turtlebot_demo.ba

## 跑 Fetch 2D 例子
roslaunch cartographer_fetch demo.launch bag_filename:=~/Downloads/cartographer_freight_simulation_demo.bag

4. 在 Turtlebot 等机器人移动平台上跑 SLAM

在 Turtlebot 上跑 SLAM 比较简单,cartographer_turtlebot 包里都有配置好的文件了。不管是用深度相机还是激光雷达,到 launch 文件里找吧。
接上 Turtlebot ,执行以下命令即可:

# 用深度相机:
roslaunch cartographer_turtlebot turtlebot_depth_camera_2d.launch
roslaunch cartographer_turtlebot turtlebot_depth_camera_3d.launch
# 用 Hokuyo 激光雷达:
roslaunch cartographer_turtlebot turtlebot_urg_lidar_2d.launch

在 Guardian 上跑我还没有配置出来,因为参数要自己设置,比较麻烦,而且自己对 Guardian 还不够了解,所以还在研究中。不过该算法直接用雷达就能跑,可以参考这两篇博客:
Only_uuu的博客——Cartographer连接激光-hokuyo UTM-30LX
wen_hust的博客——hokuyo激光雷达跑cartographer

5. 关于 Cartographer 的配置文件

Cartographer 支持不同的平台和不同的传感器,配置合理的话理论上都可以实现。关于配置文件中各种参数的说明,可以见官方文档(参考资料[5])。不过我目前也处于摸索的阶段,Guardian 的都还没配出来呢,有新的进展我会及时更新博客,欢迎共同探讨。

参考资料
[1] http://blog.csdn.net/u012700322/article/details/52953768
[2] https://google-cartographer.readthedocs.io/en/latest/#
[3] http://blog.csdn.net/sean_xyz/article/details/53048605
[4] https://google-cartographer-ros.readthedocs.io/en/latest/
[5] http://google-cartographer-ros.readthedocs.io/en/latest/configuration.html

推荐阅读:
google源码cartographer分析一
知乎-如何看待谷歌在 10 月 6 日开源的 SLAM 算法 cartographer?

猜你喜欢

转载自blog.csdn.net/u011736771/article/details/72824782