ROS-noetic安装Google的Cartographer
写在最前
- 本文建议在不能科学上网的同学,最好采用手机热点进行安装
- 如果你的ROS环境是刚刚安装好,不怕乱动的最好了
- rosdep更新:可以采用sudo pip3 install rosdepc
- 文中所有的命令路径都无需切换
参考内容:
【安装学习】安装Cartographer ROS(noetic)
安装cartographer步骤及问题解决
1. 创建工作空间并初始化
-
- 创建工作空间:
mkdir -p ~/catkin_google_ws/src
- 创建工作空间:
-
- 跳转到工作空间:
cd ~/catkin_google_ws/src/
- 跳转到工作空间:
-
- 在2的命令下,初始化工作空间
catkin_init_workspace
- 在2的命令下,初始化工作空间
pc@pc:~$ mkdir -p ~/catkin_google_ws/src
pc@pc:~$ ls
catkin_google_ws Documents Music Public Videos
Desktop Downloads Pictures Templates
pc@pc:~$ cd ~/catkin_google_ws/src/
pc@pc:~/catkin_google_ws/src$ catkin_init_workspace
Creating symlink "/home/pc/catkin_google_ws/src/CMakeLists.txt" pointing to "/opt/ros/noetic/share/catkin/cmake/toplevel.cmake"
2. 安装下载工具并下载谷歌Cartographer
-
- 更新一下软件源:
sudo apt-get update
- 更新一下软件源:
-
- 安装下载工具:
sudo apt install -y python3-wstool ninja-build stow
- 安装下载工具:
-
- 切换到工作空间:
cd ~/catkin_google_ws/
- 切换到工作空间:
-
- wstool工具初始化工作空间:
wstool init src
- wstool工具初始化工作空间:
pc@pc:~/catkin_google_ws$ sudo apt install -y python3-wstool ninja-build stow
... ...
Creating config file /etc/mercurial/hgrc.d/hgext.rc with new version
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for install-info (6.7.0.dfsg.2-5) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
pc@pc:~/catkin_google_ws/src$ cd ~/catkin_google_ws/
pc@pc:~/catkin_google_ws$ wstool init src
Writing /home/pc/catkin_google_ws/src/.rosinstall
update complete.
-
- 工作空间下merge远程的代码库:
wstool merge -t src https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall
,merge代码出错查看第4.1节内容
- 工作空间下merge远程的代码库:
-
- wstool工具更新源文件:
wstool update -t src
,由于github的不稳定性,这一步多半失败,更新出错见4.2解决方法
- wstool工具更新源文件:
-
- 安装abseil cpp库:切换到工作空间目录:
cd ~/catkin_google_ws/
,输入命令src/cartographer/scripts/install_abseil.sh
,安装库
- 安装abseil cpp库:切换到工作空间目录:
-
- 安装依赖项:
rosdep install --from-paths ~/catkin_google_ws/src --ignore-src -r
,该命令主要替代rosdep install --from-paths src --ignore-src --rosdistro=noetic -y
,但是后续可能弄乱环境,需要重新安装ROS,即sudo apt install ros-noetic-desktop-full
- 安装依赖项:
pc@pc:~/catkin_google_ws$ rosdep install --from-paths src --ignore-src --rosdistro=noetic -y
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
cartographer: [libabsl-dev] defined as "not available" for OS version [focal]
-
- 编译Cartographer:
catkin_make_isolated --install --use-ninja
,这一个最关键,不报错,说明catrograppher部署成功了,那么恭喜你,可以开始Cartographer的学习了!
- 编译Cartographer:
pc@pc:~/catkin_google_ws$ catkin_make_isolated --install --use-ninja
... ....
-- Installing: /home/pc/catkin_google_ws/install_isolated/share/cartographer_rviz/rviz_plugin_description.xml
-- Installing: /home/pc/catkin_google_ws/install_isolated/share/cartographer_rviz/ogre_media
-- Installing: /home/pc/catkin_google_ws/install_isolated/share/cartographer_rviz/ogre_media/materials
-- Installing: /home/pc/catkin_google_ws/install_isolated/share/cartographer_rviz/ogre_media/materials/glsl120
-- Installing: /home/pc/catkin_google_ws/install_isolated/share/cartographer_rviz/ogre_media/materials/glsl120/submap.frag
-- Installing: /home/pc/catkin_google_ws/install_isolated/share/cartographer_rviz/ogre_media/materials/glsl120/submap.vert
-- Installing: /home/pc/catkin_google_ws/install_isolated/share/cartographer_rviz/ogre_media/materials/glsl120/glsl120.program
-- Installing: /home/pc/catkin_google_ws/install_isolated/share/cartographer_rviz/ogre_media/materials/scripts
-- Installing: /home/pc/catkin_google_ws/install_isolated/share/cartographer_rviz/ogre_media/materials/scripts/submap.material
<== Finished processing package [4 of 4]: 'cartographer_rviz'
3. 测试Cartographer
3.1 下载官方的二维模型
-
- 下载模型可以用wget方式或者直接http下载,下载的位置就在工作空间下:
wget -P ~/catkin_google_ws/ https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
- 下载模型可以用wget方式或者直接http下载,下载的位置就在工作空间下:
3.2 测试运行Cartographer
-
- 激活环境,激活环境前确保你的catrographer项目是编译通过的,即第12步不报错:
source devel_isolated/setup.bash
- 激活环境,激活环境前确保你的catrographer项目是编译通过的,即第12步不报错:
-
- 启动官方demo:
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/catkin_google_ws/cartographer_paper_deutsches_museum.bag
- 启动官方demo:
pc@pc:~/catkin_google_ws$ source devel_isolated/setup.bash
pc@pc:~/catkin_google_ws$ roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/catkin_google_ws/cartographer_paper_deutsches_museum.bag
4. 错误解决办法,和附件
4.1 merge代码出错解决
- 在第8步中,merge代码多半出现
pc@pc:~/catkin_google_ws$ wstool merge -t src https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall
ERROR in config: Unable to download URL [https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall]: <urlopen error [Errno 111] Connection refused>
- 此时复制
https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall
连接也发现进不去,多半肯定是不成功
- 方法一:换手机热点多试几次,能成功
- 方法二:直接跑到src的目录下,添加需要merge的信息:
- 8.1 进入src目录:
cd ~/catkin_google_ws/src/
,输入ls -a
可以查看是否有.rosinstall
文件 - 8.2 编辑
.rosinstall
文件:sudo gedit ~/catkin_google_ws/src/.rosinstall
,保存关闭,进入第九步:
# THIS IS AN AUTOGENERATED FILE, LAST GENERATED USING wstool ON 2022-10-27
- git: {local-name: cartographer, uri: 'https://github.com/cartographer-project/cartographer.git', version: 'master'}
- git: {local-name: cartographer_ros, uri: 'https://github.com/cartographer-project/cartographer_ros.git', version: 'master'}
4.2 wstool update -t src报错解决办法
- 报错内容:
pc@pc:~/catkin_google_ws$ wstool update -t src
[cartographer] Fetching https://github.com/cartographer-project/cartographer.git (version master) to /home/pc/catkin_google_ws/src/cartographer
Cloning into '/home/pc/catkin_google_ws/src/cartographer'...
fatal: unable to access 'https://github.com/cartographer-project/cartographer.git/': Failed to connect to github.com port 443: Connection refused
[cartographer_ros] Fetching https://github.com/cartographer-project/cartographer_ros.git (version master) to /home/pc/catkin_google_ws/src/cartographer_ros
Cloning into '/home/pc/catkin_google_ws/src/cartographer_ros'...
fatal: unable to access 'https://github.com/cartographer-project/cartographer_ros.git/': Failed to connect to github.com port 443: Connection refused
Exception caught during install: Error processing 'cartographer' : [cartographer] Checkout of https://github.com/cartographer-project/cartographer.git version master into /home/pc/catkin_google_ws/src/cartographer failed.
Error processing 'cartographer_ros' : [cartographer_ros] Checkout of https://github.com/cartographer-project/cartographer_ros.git version master into /home/pc/catkin_google_ws/src/cartographer_ros failed.
ERROR in config: Error processing 'cartographer' : [cartographer] Checkout of https://github.com/cartographer-project/cartographer.git version master into /home/pc/catkin_google_ws/src/cartographer failed.
Error processing 'cartographer_ros' : [cartographer_ros] Checkout of https://github.com/cartographer-project/cartographer_ros.git version master into /home/pc/catkin_google_ws/src/cartographer_ros failed.
pc@pc:~/catkin_google_ws$
-
解决方法:
-
- 切换热点多试几次
-
- 直接进入GitHub下载文件夹:https://github.com/cartographer-project,可以看到几个文件,将两个C++文件进入到下载页面下载下来https://github.com/cartographer-project/cartographer,https://github.com/cartographer-project/cartographer_ros
- 直接进入GitHub下载文件夹:https://github.com/cartographer-project,可以看到几个文件,将两个C++文件进入到下载页面下载下来https://github.com/cartographer-project/cartographer,https://github.com/cartographer-project/cartographer_ros
-
- 将两个文件解压到
catkin_google_ws/src
下,看到文件夹后面有尾缀master,删除-master:
- 将两个文件解压到