转载自:hitcm 感谢大神的无私分享。
谷歌自己提供了安装方法,但是比较慢,我做了一定的修改代码放到个人github上,https://github.com/hitcm/
更多细节,可以看看知乎的问题https://www.zhihu.com/question/51348391/answer/125560951?from=profile_answer_card
个人理解错误的地方还请不吝赐教,转载请标明出处,内容如有改动更新,请看原博:http://www.cnblogs.com/hitcm/,
代码放到个人github上,https://github.com/hitcm/
如下,需要安装3个软件包,ceres solver、cartographer和cartographer_ros
0.安装所有依赖项
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-indigo-tf2-eigen libatlas-base-dev libsuitesparse-dev liblapack-dev
1.首先安装ceres solver,选择的版本是1.11,路径随意。
git clone https://github.com/hitcm/ceres-solver-1.11.0.git
cd ceres-solver-1.11.0/build
cmake ..
make –j
sudo make install
PS:根据原博主的方法,ceres solver可能安装不上。具体安装方法可以参考google的官方指导
http://ceres-solver.org/building.html
2.然后安装 cartographer,路径随意。
①. git clone https://github.com/hitcm/cartographer.git
②. cd cartographer/build
③. cmake .. -G Ninja
④. ninja
⑤. ninja test
⑥. sudo ninja install
{
由于cartographer官方代码持续更新中,因此可能会出现安装出错的情况。
如果上述第三步操作出错,可以忽略③-⑥,改用如下方法:
③. CMakeList.txt中添加
SET(CMAKE_C_FLAGS "-02 -pipe -fPIC -Wall -fmessage-length=0")
SET(CMAKE_CXX_FLAGS "-02 -pipe -fPIC -Wall -fmessage-length=0")
④. cmake ..
这里需确保build目录中生成gmock目录,若未生成,尝试 sudo cmake ..
⑤. make
⑥. sudo make install
}
3.安装cartographer_ros,谷歌官方提供的安装方法比较繁琐,我对原来的文件进行了少许的修改,核心代码不变,只是修改了编译文件
下载到catkin_ws下面的src文件夹下面
git clone https://github.com/hitcm/cartographer_ros.git
然后到catkin_ws下面运行catkin_make即可。
PS1:在这里直接catkin_make 会报错:Unknown CMAKE_BUILD_TYPE:Release修改如下:在文件cartigrapher_ros cartigrapher_rviz cartigrapher_ros_msgs文件下的CMakeList.txt 文件中,在24行加入:set(CMAKE_BUILD_TYPE “Release”)
PS2: 若报CMP0002错误,在usr/src/gmock/gtest/CMakeList.txt中添加 cmake_policy(SET CMP0002 OLD)
PS3: 保存地图 rosservice call /finish_trajectory "stem: 'test'" 地图保存路径为: ~/.ros/test.pgm (home/YOUR_PC/.ros/test.pgm)
4.数据下载测试
2d数据,大概500M,用迅雷下载
https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
3d数据,8G左右,同样用迅雷下载
https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/cartographer_3d_deutsches_museum.bag
然后运行launch文件即可。
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/cartographer_3d_deutsches_museum.bag
如下图,左侧为2d,右侧为3d.
Good luck!关于代码的原理解析,接下来的文章可能会详细探讨。
ps:我第一次按照hitcm 的博客安装时,出现跑出来的数据是歪的。如下图所示:
然后我就把之前的安装全部删除(ceres solver, cartographer, cartographer_ros),再一次安装。
安装明明大神的步骤安装,只是在安装cartographer_ros有些区别,这里我是下载官网给的源码 :https://github.com/googlecartographer/cartographer_ros
在cartographer_ros文件中删掉ceres_solver和scripts两个文件夹。然后在catkin_ws中catkin_make即可。
再次测试,通过。如下为我跑出来的结果