Ubuntu18.04 ROS 安装以及安装问题解决

最近因为项目需要,所以又开始拿起用过一段时间的ROS,在重新安装的过程中出现了一个极为常见的问题,特此记录一下。



前言

ROS是当前比较流行和成熟的机器人系统。本文主要分为以下两个部分:

  • ROS安装
  • ROS问题解决

一、ROS安装

1.首先设置好ubuntu18.04的源

安装好ubuntu系统后,默认的软件更新源是国外的,在国内使用速度很慢,更换后能够提升更新的速度。我使用的是阿里云的源:

打开ubuntu终端,输入下面的命令:

sudo  gedit   /etc/apt/sources.list

将出来的文本中的原有的源全部注释,将下面的阿里云的源链接复制粘贴并保存,退出:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

然后下面的命令更新源:

sudo apt update

2.正式开始安装ROS

1.配置安装源:

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

若上面的源出错可以使用国内的清华源:

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'

2.设置密钥

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

若无法连接到密钥服务器,可以尝试替换上面命令中的

hkp://keyserver.ubuntu.com:80 为 hkp://pgp.mit.edu:80。

你也可以使用curl命令替换apt-key命令,这在使用代理服务器的情况下比较有用:


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

3.安装
安装时要确保Debian 包索引是最新的,使用如下的命令:

sudo apt update

ROS 中有很多不同的库和工具,我选择的是比较完整的桌面版,桌面版包含:ROS、rqt、rviz、机器人通用库、2D/3D 模拟器、导航以及 2D/3D 感知包。安装的命令如下:

sudo apt install ros-melodic-desktop-full

等待安装下载i完成,可能需要一段时间。

4.初始化rosdep
初始化命令:

sudo rosdep init
rosdep update

等下初始化下载。

5.设置环境变量

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

6.构建ROS的依赖
这一步很重要,不构建ROS不会正常的工作:

sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential

7.测试安装
打开终端,查看是否成功安装:

roscore

安装成功时的信息是这样的:

... logging to /home/zhangys/.ros/log/2d13af0e-0faf-11ec-a08e-18c04d4b6761/roslaunch-zhangys-19975.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://zhangys:42133/
ros_comm version 1.14.11


SUMMARY
========

PARAMETERS
* /rosdistro: melodic
* /rosversion: 1.14.11

NODES

auto-starting new master
process[master]: started with pid [19985]
ROS_MASTER_URI=http://zhangys:11311/

setting /run_id to 2d13af0e-0faf-11ec-a08e-18c04d4b6761
process[rosout-1]: started with pid [19998]
started core service [/rosout]

至此,ROS的安装部分就完成了。

二、ROS安装问题的解决

rosdep update 超时的问题

问题是这样的:
ERROR: error loading sources list:
    <urlopen error <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/ardent/distribution.yaml)>
       

这个问题是由于无法连接到:https://raw.githubusercontent.com这个源造成的。我解决的思路如下:

首先:

sudo gedit /etc/resolv.conf

将原有的nameserver这一行注释,并添加以下两行:

nameserver 8.8.8.8 #google域名服务器

nameserver 8.8.4.4 #google域名服务器

其次,打开host文件,更改源的IP地址:

sudo  gedit   /etc/apt/sources.list

在文件的末尾添加如下IP:

151.101.84.133  raw.githubusercontent.com
151.101.76.133  raw.githubusercontent.com
199.232.28.133  raw.githubusercontent.com
199.232.28.133 raw.githubusercontent.com

上面的IP地址是网上很多地方收集测试的,来源是:

在该网址中进行查询:IP查询

输入:raw.githubusercontent.com ,即可查询。但是奇怪的是我查询的时候反馈的是禁止查询。后面的小伙伴如有需要可以试试。

使用以上的方法可能还是会出现问题,但是可以多尝试几次。

如果上面的方法还处于卡顿的状态下,可以使用以下的命令将文件下载

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

注意:使用该命令时,可能出错提示没有安装git,按照所给的提示安装即可。

如果到此就输出已经可以了的话,后面的方法就不用了,如果不行,那就使用如下的终极方法。

最后的rosdep update其实是从github上下载yaml文件,虽然raw.githubusercontent.com服务器无法访问,但是可以直接从git clone的repo中获得。

获取yaml文件的命令:

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

所以,只要将ros/rosdistro整个git下来,然后再将下列文件中的默认url全部指向本地的git,即可解决这个问题。

/ros/rosdistro/master/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

打开一个终端,执行以下指令创建root并切换至root用户

sudo passwd    //接着提示输入UNIX密码,输入你的用户密码即可
sudo su //或者su root 然后输入密码切换至root用户
sudo mkdir -p /etc/ros/rosdep/sources.list.d
cd /etc/ros/rosdep/sources.list.d
sudo gedit /ros/rosdistro/master/rosdep/sources.list.d/20-default.list

将下面的内容复制粘贴到 /ros/rosdistro/master/rosdep/sources.list.d/20-default.list:

#os-specific listings first
yaml file:///home/yourname/rosdistro/rosdep/osx-homebrew.yaml osx
#generic
yaml file:///home/yourname/rosdistro/rosdep/base.yaml
yaml file:///home/yourname/rosdistro/rosdep/python.yaml
yaml file:///home/yourname/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/yourname/rosdistro/rosdep/fuerte.yaml fuerte
#newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

注意:此处的yourname是你自己电脑home目录下的文件夹名字,每台电脑不一样,按照自己的来。

最后再次rosdep update,成功。

说明:网上还有使用其他办法解决这个问题的,比如使用手机热点,但是我是给台式机安装,所以没有办法使用,如果用笔记本安装的话也可以试试。

希望会对你有所帮助~

参考文献:

https://blog.csdn.net/u012308586/article/details/102953882

https://blog.csdn.net/weixin_42584917/article/details/114448355

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值