Google Cartographer安装与测试(demo)
cartographer 二维/三维的数据接入:
2D:LIDAR、Odometry、IMU(可选)、GPS(尚且没有实现)
3D:LIDAR、Odometry、IMU(必须)、GPS(已实现)
GPS在2d模式下,数据接入没有问题,但是在全局优化的时候,没有GPS的输入。
2D模式的pose_graph.cc
void PoseGraph2D::AddFixedFramePoseData(
const int trajectory_id,
const sensor::FixedFramePoseData& fixed_frame_pose_data) {
LOG(FATAL) << "Not yet implemented for 2D.";
}
3D模式的pose_graph.cc
void PoseGraph3D::AddFixedFramePoseData(
const int trajectory_id,
const sensor::FixedFramePoseData& fixed_frame_pose_data) {
AddWorkItem([=]() LOCKS_EXCLUDED(mutex_) {
absl::MutexLock locker(&mutex_);
if (CanAddWorkItemModifying(trajectory_id)) {
optimization_problem_->AddFixedFramePoseData(trajectory_id,
fixed_frame_pose_data);
}
return WorkItem::Result::kDoNotRunOptimization;
});
}
准备工作
从github上下载最新版本的cartographer、cartographer_ros、ceres以及protobuf(3.0)四个文件(必须的)
note:直接在cartographer的scripts下运行install_ceres.sh,install_proto3.sh,会出现错误
1.安装系列依赖
sudo apt-get install -y \
clang \
g++ \
git \
google-mock \
libboost-all-dev \
libcairo2-dev \
libcurl4-openssl-dev \
libeigen3-dev \
libgflags-dev \
libgoogle-glog-dev \
liblua5.2-dev \
libsuitesparse-dev \
ninja-build \
python-sphinx
2.编译安装Ceres
在从github中下载的ceres,解压出来
mkdir build
cd build
cmake .. -G Ninja -DCXX11=ON
ninja
CTEST_OUTPUT_ON_FAILURE=1 ninja test
sudo ninja install
3.编译安装Protobuf
在从github中下载的Protobuf,解压出来
mkdir build
cd build
cmake -G Ninja \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=Release \
-Dprotobuf_BUILD_TESTS=OFF \
../cmake
ninja
sudo ninja install
4.编译安装Cartographer
mkdir build
cd build
cmake .. -G Ninja
ninja
CTEST_OUTPUT_ON_FAILURE=1 ninja test
sudo ninja install
5.编译Cartographer_ros
1.新建工作空间Cartographer_catkin_ros/src,将cartographer_ros包拷贝至src目录下。
2.cd …至Cartographer_catkin_ros下,运行:
catkin_make_isolated --install --use-ninja
至此,完成了cartographer所有编译与安装工作。
ps:在安装编译的过程中提示错误,一般是缺少依赖,通过sudo apt-get install 或sudo apt-get install ros-kinetic-即可快速安装
6.运行Cartographer_ros,测试2D数据
6.1 第一种:demo_backpack_2d.launch
source devel/setup.bash
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME
}/2D_demo/cartographer_paper_deutsches_museum.bag
节点状态图如下:
经上述指令,即可出图。
6.2 第二种:offline_backpack_2d.launch 离线模式
source devel/setup.bash
6.2.1 启动开始建图,生成.pbstream文件
roslaunch cartographer_ros offline_backpack_2d.launch bag_filenames:=${
HOME}/2D_demo/cartographer_paper_deutsches_museum.bag
大约一个小时左右,在数据目录有cartographer_paper_deutsches_museum.bag.pbstream
6.2.2 提取地图,将.pbstream转为栅格地图输出
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${HOME}/Downloads/mymap -pbstream_filename=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag.pbstream -resolution=0.05
会生成建立的地图文件(包括pgm和yaml)文件。可以用map_server加载使用