目录
前言
最近几次在Ubuntu上安装ROS,每次都会遇到不少坑要到网上找各位大神的文章。因此,特此将安装经验整理汇总了一下,以备后面需要的时候查阅。
1.设置软件源
国外的源更新软件时会比较慢,因此这里选择使用清华的软件源。
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/'lsb_release -cs' main" > /etc/apt/source.list.d/ros-latest.list'
2.设置密钥
如果未安装curl,需要先安装此工具。
sudo apt install curl
设置密钥
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
此处常会遇到raw.githubusercontent.com无法访问的问题,解决方案如下:
首先,访问raw.githubusercontent.com网络查询raw.Githubusercontent.com的DNS。
其次,编辑/etc/hosts文件,将查找到的DNS及对应的URL地址添加到文件中,如图所示:
如果出现"gpg:找不到时有效的OpenPGP",也可以采用以下方式设置密钥:
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
3.安装
首先,更新软件源为最新版本。
sudo apt update
其次,安装推荐的Desktop-Full Install版本。
sudo apt install ros-melodic-desktop-full
4.配置环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
5.配置编译依赖
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
5.1初始化rosdep
首先,安装rosdep。
sudo apt install python-rosdep
其次,初始化并更新rosdep。
sudo rosdep init
rosdep update
初始化和更新rosdep过程中经常会出现问题,以下介绍两种方法。方法一:
如果rosdep初始化或更新超时,需要修改如下文件内容。
修改/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py:
变量DEFAULT_SOURCES_LIST_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list';
函数download_rosdep_data中的url_request = request.Request("https://ghproxy.com/" + url, headers={'User-Agent': 'rosdep/{version}'.format(version=__version__)})
修改/usr/lib/python2.7/dist-packages/rosdistro/__init__.py:
变量DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
方法二:(此方法源于网络作者鄢立宝的Ros安装教程)
原理:
raw.githubusercontent.com
实际上就是github的用户数据服务器,rosdep程序下载的就是从github.com/ros/rosdistro
这个repo里的yaml文件虽然http://raw.githubusercontent.com
服务器无法访问,但是yaml文件可以直接从git clone的repo中获得。
首先,将rosdistro克隆到本地:
git clone https://github.com/ros/rosdistro.git
然后, 在/etc下创建目录,并将rosdistro库中的20-default.list复制到该目录下:
sudo mkdir -p /etc/ros/rosdep/sources.list.d
sudo cp ~/rosdistro/rosdep/sources.list.d/20-default.list /etc/ros/rosdep/sources.list.d/
其次, 编辑以下四个文件:
/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
将 20-default.list文件中的链接更新为本地
rosdistro库中的地址:
# os-specific listings first
yaml file:///home/[用户名]/rosdistro/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///home/[用户名]/rosdistro/rosdep/base.yaml
yaml file:///home/[用户名]/rosdistro/rosdep/python.yaml
yaml file:///home/[用户名]/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/[用户名]/rosdistro/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
将gbpdistro_support.py文件中变量FUERTE_GBPDISTRO_URL的值修改为:
FUERTE_GBPDISTRO_URL = 'file:///home/[用户名]/rosdistro/' \
'releases/fuerte.yaml'
将rep3.py文件中变量REP3_TARGETS_URL的值修改为:
REP3_TARGETS_URL = 'file:///home/[用户名]/rosdistro/releases/targets.yaml'
将__init__.py文件中变量DEFAULT_INDEX_URL的值修改为:
DEFAULT_INDEX_URL = 'file:///home/[用户名]/rosdistro/index-v4.yaml'
第二种方法的问题是rosdistro库更新后, 如果仍使用旧版本会导致安装其它ros组件出错,请注意!
总结
以上简单的记录了在Ubuntu 18.04环境下安装ROS Melodic的安装步骤和安装过程中会遇到的一些常见的问题及其解决方案,希望能有所帮助。