Cartographer安裝斷斷續續弄了三天,理論上應該挺容易的,但還是踩了好多坑。當然,hitcm大神的方法可能100%成功,但是我沒有試,因爲大神把cartographer重新封裝,沒有辦法根據自己項目的需求修改裏邊的內容。所以只能按照官網的方法來安裝,還參照了這篇博文的內容——
問題解決方案2-------------ros的 Cartographer,ninja,ceres-solver,cartographer_ros安裝及其問題,附上最好的安裝方法。
1、安裝
sudo apt-get update
sudo apt-get install python-wstool python-rosdep ninja-build
# 創建工作空間
mkdir catkin_ws
cd catkin_ws
wstool init src
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
因爲國內無法上谷歌,所以需要修改鏈接地址,修改catkin_ws/src/.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://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
繼續指令:
wstool update -t src
這時會下載上面5個git的包。再修改catkin_ws/src/cartographter_ros/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'}
繼續指令
src/cartographer/scripts/install_proto3.sh#安裝符合要求的protobuf
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO}
# Build and install.
catkin_make_isolated --install --use-ninja
source install_isolated/setup.bash
2、可能會遇到的問題
2.1、網絡
安裝cartographer對網絡要求較高,如果出現網絡問題,可切換幾個手機熱點嘗試。有可能會出現網絡問題的地方:
1、wstool update -t src
這裏需要下載github的內容,如果下載很慢或者下載不成果,需要更換網絡再試;
2、src/cartographer/scripts/install_proto3.sh
原因同1;
3、sudo rosdep init
ros的這個網站經常連不上,這裏是需要安裝rosdep。
如果網絡正常,已有rosdep,再輸入這個指令會提示:
Please delete if you wish to re-initialize
網絡出問題會提示:
Website may be down.
更換網絡,如果還不行,可以嘗試參照這個文章——
rosdep init報錯之網絡不通解決辦法
sudo gedit /etc/hosts
添加下面內容到hosts文件
199.232.28.133 raw.githubusercontent. com
4、rosdep update
網絡正常時,最後會提示:
update cache in /home/xxx/.ros/rosdep/source.cache
5、catkin_make_isolated --install --use-ninja
同1.
2.2、依賴庫
cartographer安裝對glag、glog、ceres和protobuf的版本有要求,進入/usr/local/include/手動刪除這些庫,再重新安裝。glog安裝可以參考我另一篇文章——Ubuntu glog 0.3.5安裝.
proto不用另外安裝,上面安裝cartographer時有一條指令就是安裝proto:
src/cartographer/scripts/install_proto3.sh
3、驗證
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=/${bag的絕對路徑}/cartographer_paper_deutsches_museum.bag
3D數據:
https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/b3-2016-04-05-14-14-00.bag
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=/${bag的絕對路徑}/b3-2016-04-05-14-14-00.bag