ubuntu18.04安装ROS及问题解决

一、清华源

打开终端输入

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

二、设置最新的密钥

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

三、安装

sudo apt update
sudo apt install ros-melodic-desktop-full
sudo apt install ros-melodic-rqt*

在使用apt-get的时候会有如下错误产生(有的电脑会这样,没有出现如下错误的可自动忽略)

正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
有一些软件包无法被安装。如果您用的是 unstable 发行版,这也许是
因为系统无法达到您要求的状态造成的。该版本中可能会有一些您需要的软件
包尚未被创建或是它们已被从新到(Incoming)目录移出。
下列信息可能会对解决问题有所帮助:

下列软件包有未满足的依赖关系:
 ros-melodic-desktop-full : 依赖: ros-melodic-desktop 但是它将不会被安装
                            依赖: ros-melodic-perception 但是它将不会被安装
                            依赖: ros-melodic-simulators 但是它将不会被安装
                            依赖: ros-melodic-urdf-sim-tutorial 但是它将不会被安装
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。

则使用apt就可以避免错误产生

四、下载rosdep

sudo apt install python-rosdep

五、初始化rosdep

sudo rosdep init

可能会遇到的问题

1、网络问题

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.

这种情况下可更换网络,或者换成自己的热点

如果还有问题,则sudo gedit 20-default.list打开一个文件,将下面代码添加进去并保存

# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

2、错误的源文件

ERROR: default sources list file already exists:
    /etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize

这时只需要删除这个文件即可,代码如下

sudo rm /etc/ros/rosdep/sources.list.d/20-default.list

3、操作不允许

Error: [Errno 13] Permission denied: '/home/XXX/.ros/rosdep/sources.cache/index'

这种情况下输入

sudo rm -rf $HOME/.ros/rosdep
sudo rm -rf /etc/ros/rosdep```

然后重启终端,重新下载rosdep(四)并初始化(五)

这一步骤成功则显示

Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run

	rosdep update

就可以继续啦!!!

六、更新

rosdep update

可能遇到的问题

1、超时问题

reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
ERROR: error loading sources list:
	('The read operation timed out',)

解决办法:

(1)将网络换成自己的热点(玄学)

(2)更改超时时间设置,操作如下

sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/rep3.py

分别打开这几个文件,找到DOWNLOAD_TIMEOUT,将后面的时间改的大一点(本人改成了1500000.0)

2、连接被拒绝问题

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)>

这个时候其实是https://raw.githubusercontent.com登录不上去,可以去ip138查询一下(大概率是禁止查询该域名),所以可在hosts里添加可用的域名

解决办法

sudo gedit /etc/hosts打开hosts文件,在里面添加以下网址

185.199.111.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.108.133 raw.githubusercontent.com
151.101.84.133 raw.githubusercontent.com

其实rosdep update这一步不会遇到很严重的问题,只是可能会因为网络问题而花费很长时间,这时多试一试就好啦,不要着急

七、安装rosinstall

sudo apt-get install python-rosinstall

八、加载环境设置文件

source /opt/ros/melodic/setup.bash

九、创建并初始化工作目录

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make

十、设置环境变量

sudo apt install net-tools
gedit ~/.bashrc

将下面复制到文件末尾

# Set ROS melodic
source /opt/ros/melodic/setup.bash
source ~/catkin_ws/devel/setup.bash

十一、小海龟测试

打开三个终端,将下面三句分别运行

roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

并停留在最后一个终端,通过方向键盘可控制小海龟的运动即可

ros安装就到此为止了,接下来可根据需求配置IDE

祝顺利!!!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值