1 实验环境
1)硬件环境:PC (CPU:X64 64bit,Memory:4G)
2)软件环境:Ubuntu 16.04 32bit(Google建议64bit,且说32bit存在issue,不过为了不用重新安装64bit系统,我还是尝试了当前的32bit),ROS Kinetic版本
2 实验步骤
2.1 安装基本必须的库
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.2 编译并安装Ceres
git clone https://ceres-solver.googlesource.com/ceres-solver
cd ceres-solver
mkdir build
cd build
cmake .. -G Ninja
ninja
ninja test
sudo ninja install
注意:如果无法从google取出代码可以从github提取code:https://github.com/ceres-solver/ceres-solver
2.3 安装wstool和rosdep
sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build
2.4 创建workspace
mkdir google_cartographer_catkin_ws
cd catkin_ws
wstool init src
2.5 下载google cartographer源码
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src
2.6 安装deb依赖
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${kinetic} -y
2.7 编译并安装
catkin_make_isolated --install --use-ninja
source install_isolated/setup.bash
注意:我在编译时候遇到了与QT相关问题,很多QT头文件找不到,不知道是你不是由于Ubuntu 16.04自带qt4,而我又安装了qt5导致,最后通过修改CMakeLists.txt搞定了。
error log:
bmap.h:35:0,
from cartographer_rviz/moc_drawable_submap.cpp:9,
from cartographer_rviz/drawable_submap_automoc.cpp:2:
/opt/ros/kinetic/include/rviz/display_context.h:34:19: fatal error: QObject: No such file or directory
compilation terminated.
ninja: build stopped: subcommand failed.
<== Failed to process package 'cartographer_rviz':
Command '['/home/siriansu/google_cartographer_catkin_ws/install_isolated/env.sh', 'ninja', '-j2', '-l2']' returned non-zero exit status 1
Reproduce this error by running:
==> cd /home/siriansu/google_cartographer_catkin_ws/build_isolated/cartographer_rviz && /home/siriansu/google_cartographer_catkin_ws/install_isolated/env.sh ninja -j2 -l2
In file included from /home/siriansu/google_cartographer_catkin_ws/src/cartographer_ros/cartographer_rviz/cartographer_rviz/drawable_submap.h:35:0,
cartographer_rviz/../../../src/cartographer_ros/cartographer_rviz/cartographer_rviz/drawable_submap.h:35:35: fatal error: rviz/displays_context.h: No such file or directory
解决办法:修改src/cartographer_ros/cartographer_rviz/下面的CMakeLists.txt添加如下红色行
if(rviz_QT_VERSION VERSION_LESS "5")
message(STATUS "Using Qt4 based on the rviz_QT_VERSION: ${rviz_QT_VERSION}")
find_package(Qt4 ${rviz_QT_VERSION} EXACT REQUIRED QtCore QtGui)
include(${QT_USE_FILE})
else()
message(STATUS "Using Qt5 based on the rviz_QT_VERSION: ${rviz_QT_VERSION}")
find_package(Qt5 ${rviz_QT_VERSION} EXACT REQUIRED Core Widgets)
find_package(Qt5Widgets REQUIRED)
set(QT_LIBRARIES Qt5::Widgets)
include_directories(/opt/Qt5.5.1/5.5/gcc/include/QtCore /opt/Qt5.5.1/5.5/gcc/include/ /opt/Qt5.5.1/5.5/gcc/include/QtGui/)
endif()
3 运行Google Demo
Google有4个demo,我只是验证所以仅仅下载的第一个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
运行结果如下图所示: