0%

ROS 1 安装——从手动到自动:以 Ubuntu 18.04 + ROS Melodic 为例

ROS-1-安装——从手动到自动:以-Ubuntu-18-04-ROS-Melodic-为例

0 前言

近期在 Ubuntu 18.04 下安装 ROS 1 Melodic 的过程中遇到 rosdep initrosdep update 报错的问题,手动解决不免繁琐,而且 rosdistro 库会时常更新,如果 rosdep update 时使用了旧版的 YAML 文件,有可能导致后期安装其它 ROS 组件时出现问题,为此开发了完全一键安装开源工具 rostaller

1 手动安装

1.1 配置 Ubuntu 软件仓库

确保 restricted、universe 和 multiverse 被勾选,选择国内更稳定的镜像源,例如清华源:https://mirrors.tuna.tsinghua.edu.cn/ubuntu/

配置 Ubuntu 软件仓库

1.2 添加 ros 源

1
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'

1.3 设置密钥

1
2
sudo apt install curl
curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -

1.4 安装 ROS

这里以 ROS Melodic 桌面完全版为例:

1
2
sudo apt update
sudo apt install ros-melodic-desktop-full

1.5 配置环境

1
2
echo "source /opt/ros/melodic/setup.bash" >>~/.bashrc
source ~/.bashrc

1.6 安装构建包所需依赖

1
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential

1.7 初始化 rosdep

1
sudo rosdep init

由于域名污染,这一步往往会报下面的错误:

1
2
3
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.

为解决该问题,首先,克隆 rosdistro 仓库:

1
git clone https://github.com/ros/rosdistro.git

然后,本地新建对应目录:

1
sudo mkdir -p /etc/ros/rosdep/sources.list.d

最后,将克隆下来的 rosdistro 仓库中的 list 文件拷贝到上述目录:

1
2
cd rosdistro
sudo cp rosdep/sources.list.d/20-default.list /etc/ros/rosdep/sources.list.d/

1.8 更新本地 rosdep 数据库

1
rosdep update

同样是由于域名污染,这一步往往会报下面的错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
reading in sources list data from /etc/ros/rosdep/sources.list.d
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml]:
Failed to download target platform data for gbpdistro:
<urlopen error [Errno 111] Connection refused>
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
ERROR: error loading sources list:
<urlopen error <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml)>

假设已经解决上面步骤中 rosdep init 遇到的问题,现在需要编辑以下四个文件(做好备份):

  • /etc/ros/rosdep/sources.list.d/20-default.list
  • /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
  • /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
  • /usr/lib/python2.7/dist-packages/rosdistro/__init__.py

搜索文件中的 https://raw.githubusercontent.com/ros/rosdistro/master 字段,将其替换为本地 rosdistro 仓库的绝对地址,例如本示例中为 file:///home/shipeng/Desktop/rosdistro。编辑后的 list 文件如下所示:

1
2
3
4
5
6
7
8
9
10
# os-specific listings first
yaml file:///home/shipeng/Desktop/rosdistro/rosdep/osx-homebrew.yaml osx

# generic
yaml file:///home/shipeng/Desktop/rosdistro/rosdep/base.yaml
yaml file:///home/shipeng/Desktop/rosdistro/rosdep/python.yaml
yaml file:///home/shipeng/Desktop/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/shipeng/Desktop/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 update 命令即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///home/shipeng/Desktop/rosdistro/rosdep/osx-homebrew.yaml
Hit file:///home/shipeng/Desktop/rosdistro/rosdep/base.yaml
Hit file:///home/shipeng/Desktop/rosdistro/rosdep/python.yaml
Hit file:///home/shipeng/Desktop/rosdistro/rosdep/ruby.yaml
Hit file:///home/shipeng/Desktop/rosdistro/releases/fuerte.yaml
Query rosdistro index file:///home/shipeng/Desktop/rosdistro/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Add distro "foxy"
Add distro "galactic"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/shipeng/.ros/rosdep/sources.cache

1.8 运行小海龟示例

打开终端,执行:

1
roscore

另开新的终端,执行:

1
rosrun turtlesim turtlesim_node

弹出小海龟界面:

小海龟

另开新的终端,执行:

1
rosrun turtle_teleop_key

保持该终端中的光标处于激活状态,通过方向键即可控制小海龟的移动。

2 自动化安装——使用 rostaller

上述手动安装的步骤中,处理 rosdep initrosdep update 报错问题的方法操作起来不免繁琐,而且 rosdistro 库会时常更新,如果 rosdep update 时使用了旧版的 YAML 文件,有可能导致后期安装其它 ROS 组件时出现问题,为此开发了 Ubuntu 18.04 下 ROS 1 Melodic 完全一键安装的开源工具 rostaller,再也不用纠结 rosdep initrosdep update 报错的问题,工具执行时会尝试在线更新 YAML 文件,后面可能会增加对 ROS 1 其它版本及 ROS 2 的支持。欢迎使用 + star,欢迎提 issue,欢迎 folk + pull request。工具使用方法:

  • 克隆仓库:

    1
    git clone https://github.com/RocShi/rostaller.git
  • 进入本地仓库目录,为脚本添加可执行权限(仅首次执行需要):

    1
    chmod +x run.sh
  • 运行脚本,一键安装:

    1
    ./run.sh

Enjoy!

参考

  1. 在 Ubuntu 中安装 ROS Melodic
  2. Ubuntu install of ROS Melodic
  3. rosdep init/update 解决方法
  4. ROS rosdep init/update 报错终极解决方法

Thank you for your donate!