Ubuntu18.04安装ROS系统

1.Ubuntu与ROS的版本对应

Ubuntu         ROS1.0
16.04LTS Kinetic LTS
18.04LTS Melodic LTS
20.04LTS Noetic LTS 

2.安装

本文为Ubuntu18.04版本下的安装。

2.1准备工作

点击左下角的9个点,然后点击“软件和更新”。

前四个选项要勾选上,第五个也要勾选上,第五个勾选应该是一道横线,“下载自”暂选“中国的服务器”

 2.2换源

本文换用的是清华源,当然,阿里、中科大等等,都可以用。

打卡“终端”,输入命令

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

修改源文件

执行命令

sudo chmod 777 /etc/apt/sources.list
sudo gedit /etc/apt/sources.list

出现警告没有关系,不用管他

 将文本框(下图)中的内容替换为清华源(本文已替换),其他源也可以

 清华源:

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-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
 
 
   sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

2.3更新

在“终端”中执行命令,完成换源

sudo apt-get update
sudo apt-get upgrade

3.安装ROS

3.1

 安装ROS桌面完整版:

sudo apt-get install ros-melodic-desktop-full

安装rq4t工具箱:

 sudo apt-get install ros-melodic-rqt*

3.2初始化

这里几乎都会出错!!!!!

sudo rosdep init

初始化一次即可,不需重复初始化 

3.2.1 错误1

sudo rosdep 找不到命令

解决方法:

sudo apt-get install python-rosdep

3.2.2 错误2

Error:cannot download default sources list from:https://raw.githubsercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list

website may be dowm.

解决办法(你应该看到过该方法,反正我当时这样没解决):etc文件夹->创建ros文件夹->在ros中创建rosdep文件夹->在rosdep文件夹中创建sources.list.d文件夹->在该文件夹中创建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

保存并关闭

在桌面终端执行:

 sudo gedit /etc/hosts

将第三行换成:

151.101.76.133 raw.githubusercontent.com    
#也可以换成
151.101.84.133 raw.githubusercontent.com
# GitHub Start
52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
151.101.76.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com
# GitHub End

然后执行

sudo rosdep init
rosdep update

到这里,所谓的该方法算是结束了,但我在做的过程中并没有解决,原因就是,上述ip地址是国外的,不翻墙不能使用。并且,重复执行sudo rosdep init还会告诉你“已存在,不要重复执行,除非删除”。

出了问题不去想办法解决,才是笨蛋

所以,我把需要下载的文件下载好了,直接用下载好的文件去解决问题,主要针对初始化和更新出现的问题

以下是本文精华所在

下载链接:https://pan.baidu.com/s/1Rt7IcxQVqHfDG7xr21XwvQ?pwd=pxmo 
提取码:pxmo

在Ubuntu中下载好文件后,在文件所在的文件夹解压到本地opt目录(使用终端,也可以下载解压软件)

sudo unzip -o rosdep.zip -d /opt/rosdep

打开文件夹,/usr/lib/python2.7/dist-packages/rosdistro中的“__init__.py”文件

 将DEFAULT_INDEX_URL这一行修改为:
DEFAULT_INDEX_URL = 'file:///opt/rosdep/rosdistro/master/index-v4.yaml'
操作之前,请确保ROS安装的命令已经执行且rosdep已经安装
文件:/usr/lib/python2.7/dist-packages/rosdep2/rep3.py
将REP3_TARGETS_URL这一行修改为:
REP3_TARGETS_URL =
'file:///opt/rosdep/rosdistro/master/releases/targets.yaml'
文件:/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
将DEFAULT_SOURCES_LIST_URL 这一行修改为:
DEFAULT_SOURCES_LIST_URL =
'file:///opt/rosdep/rosdistro/master/rosdep/sources.list.d/20-default.list'

再次执行

sudo rosdep init
rosdep update

如果执行sudo rosdep init的时候提示文件已经存在,删除存在的文件后重新执行 sudo
rosdep init 和 rosdep update即可

3.3安装Rosinstall

 sudo apt-get install python-rosinstall

3.4安装catkin编译器

 sudo apt-get install ros-melodic-catkin python-catkin-tools

3.5配置环境变量

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

此时,若出现错误:  bash: /opt/ros/melodic/setup.bash: 没有那个文件或目录 

进入终端输入下方命令:

gedit .bashrc

打开文件后将拉到最后,添加:

source /opt/ros/melodic/setup.bash

至此,ROS系统安装完成,为了验证系统,我们运行一下小龟龟:

桌面终端中:

roscore

再打开一个终端执行:

rosrun turtlesim turtlesim_node

接着打开一个终端执行:

rosrun turtlesim turtle_teleop_key

通过↑、↓、←、→即可控制小龟龟移动

4.结尾

在安装Ros系统中,忘记是哪一步的错误,有的文章指出连上手机热点即可解决问题,反正我是没解决了,境外的东西,不搭梯子翻不出去的。有的文章还让你查ip,查出来就是“ip禁用”哈哈哈哈哈,太讽刺了,这是我踩的坑。

本文参考:ROS教程(一):ROS安装教程(详细图文)_Leslie___Cheung的博客-CSDN博客_ros安装

猜你喜欢

转载自blog.csdn.net/weixin_50736953/article/details/124804558