[TOC]
记录配置ROS环境及遇到的问题
1. 版本选择
ROS 虽然叫机器人操作系统,但它是寄生在 LINUX 操作系统之下的,更应该叫开发框架或工具集。不同的ROS版本支持不同的Ubuntu系统。我使用的是Ubuntu 20.04 + ROS 1.0 Noetic。
Ubuntu与ROS版本对应关系:
Ubuntu | ROS 1.0 | ROS 2.0 |
---|---|---|
16.04 LTS | Kinetic LTS | Ardent |
18.04 LTS | Melodic LTS | Dashing LTS |
20.04 LTS | Noetic LTS | Foxy LTS |
2. 安装步骤
2.1. 配置软件源
配置Ubuntu软件仓允许restricted、 universe、multiverse。仓地址可选择清华源。
image.png
2.2. 配置ROS软件源及设置秘钥
sudo sh -c '. /etc/lsb-release && \
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ \
`lsb_release -cs` main" \
> /etc/apt/sources.list.d/ros-latest.list'
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc \
| sudo apt-key add -
- raw.githubusercontent.com经常超时,可以多次尝试
- 如果想用其他镜像源可查询http://wiki.ros.org/ROS/Installation/UbuntuMirrors
2.3 安装
- sudo apt update 更新软件源index
- sudo apt install ros-noetic-desktop-full 安装ROS
3. 设置环境变量
- 执行
source /opt/ros/noetic/setup.bash
将ROS的可执行文件加入环境变量中 - 可以将该命令加入到.bashrc中,这样每次shell启动都会执行source
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
4. 安装构建工具所需依赖
到此步ROS的核心包已经安装完成。管理ROS的工作空间的工具还需要安装一些依赖:
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
4.1 安装及初始化rosdep
rosdep是更简便管理包依赖的工具,需要安装及初始化。
sudo apt install python3-rosdep
sudo rosdep init
rosdep update
5.处理raw.githubusercontent.com链接超时问题
在rosdep update过程中,raw.githubusercontent.com这个网站经常超时,大概率会导致文件下载不下来。网上给出的方案经常是改大超时时间,设置其host ip。但这种情况不一定可行,看个人运气。如果还是不行,可以手工下载代码仓,并更改rosdep的源码解决。
- clone代码仓https://github.com/ros/rosdistro到本地,并更改其文件rosdep/sources.list.d/20-default.list,将其url改成本地文件路径,内容类似如下:
# os-specific listings first
yaml file:///home/baby/rosdistro/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///home/baby/rosdistro/rosdep/base.yaml
yaml file:///home/baby/rosdistro/rosdep/python.yaml
yaml file:///home/baby/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/baby/rosdistro/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
- 更改rosdep源码
由于rosdep使用python,可直接该动源码。我们需要改动三个文件:
文件 | 更改内容 |
---|---|
/usr/lib/python3/dist-packages/rosdep2/sources_list.py | DEFAULT_SOURCES_LIST_URL = 'file:///home/baby/rosdistro/rosdep/sources.list.d/20-default.list' |
/usr/lib/python3/dist-packages/rosdep2/rep3.py | REP3_TARGETS_URL = 'file:///home/baby/rosdistro/releases/targets.yaml' |
/usr/lib/python3/dist-packages/rosdep2/gbpdistro_support.py | FUERTE_GBPDISTRO_URL = 'file:///home/baby/rosdistro/releases/fuerte.yaml' |
/usr/lib/python3/dist-packages/rosdistro/init.py | DEFAULT_INDEX_URL = 'file:///home/baby/rosdistro/index-v4.yaml' |
完成后先把/etc/ros/rosdep/sources.list.d/20-default.list删除,再执行init与update就可以成功了。
image.png