ubuntu18.04 ROS melodic完整版教程及错误处理(附带 catkin_ws工作空间搭建)

一、配置Ubuntu软件库

桌面点击Ubuntu软件,接着左上角点击Ubuntu软件,点击软件和更新。
将可从互联网下载的所有选项选中,并且将下载自 选为 中国 的服务器

二、安装过程及错误处理

ros官网安装教程: ROS Instal
软件与更新中,将所有选项都勾上

  1. 设置安装源,设置代理源,如清华源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
  1. 设置密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
  1. 更新软件包
sudo apt update
sudo apt upgrade
  1. 安装ROS melodic
sudo apt-get install ros-melodic-desktop-full
  • 如果出现如下错误
W: GPG 错误:http://mirrors.ustc.edu.cn/ros/ubuntu bionic InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY F42ED6FBAB17C654
  • 执行以下命令
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

初始化ROS(网络报错问题最终解决方案)

初始化ROS过程中需要通过网络下载一些文件,但由于网络网速不够或其他原因,会出现无法下载和无法连接的错误,如下:

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.
ERROR: error loading sources list:
	('The read operation timed out',)

sudo rosdep initrosdep update 报错终极解决方案如下:

1 将rosdistro clone到本地
这里,可以选择github方式

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

建议选择gitee的方式(此方法下载更快,库是我自己导入的,可以使用!)

git clone https://gitee.com/huang_hongzhi/rosdistro.git

注意这里克隆的地址选择根目录,我的用户名是hhz,那么这个文件夹的地址就是~/rosdistro,即/home/hhz/rosdistro

2 创建20-default.list,对应sudo rosdep init 这一步
打开一个新终端,输入以下内容,用途是创建20-default.list

sudo su //输入你的密码切换至root
sudo mkdir -p /etc/ros/rosdep/sources.list.d   
cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list

将以下内容复制进20-default.list
注意:以下的ubuntu全部改为你们自己的用户名

#os-specific listings first
yaml file:///home/ubuntu/rosdistro/rosdep/osx-homebrew.yaml osx
#generic
yaml file:///home/ubuntu/rosdistro/rosdep/base.yaml
yaml file:///home/ubuntu/rosdistro/rosdep/python.yaml
yaml file:///home/ubuntu/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/ubuntu/rosdistro/releases/fuerte.yaml fuerte

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

3 替换下载网址为本地的文件

  • 打开第一个文件
cd /home/ubuntu/rosdistro/rosdep/sources.list.d/
sudo gedit 20-default.list 

将里面所有的 raw.githubusercontent.com替换成file:///home/ubuntu/rosdistro的地址,如下:

# os-specific listings first
yaml file:///home/ubuntu/rosdistro/rosdep/osx-homebrew.yaml osx

# generic
yaml file:///home/ubuntu/rosdistro/rosdep/base.yaml
yaml file:///home/ubuntu/rosdistro/rosdep/python.yaml
yaml file:///home/ubuntu/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/ubuntu/rosdistro/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
  • 打开第二个文件
cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit gbpdistro_support.py

替换对应的内容(注意两行都要换

FUERTE_GBPDISTRO_URL = 'file:///home/ubuntu/rosdistro/' \
    'releases/fuerte.yaml'
  • 打开第三个文件
cd /usr/lib/python2.7/dist-packages/rosdep2/
sudo gedit rep3.py

替换对应的内容

REP3_TARGETS_URL = 'file:///home/ubuntu/rosdistro/releases/targets.yaml'
  • 打开第四个文件
    我电脑里是 __init__.py,但是作者的是init.py
cd /usr/lib/python2.7/dist-packages/rosdistro/
sudo gedit __init__.py

替换对应的内容

DEFAULT_INDEX_URL = 'file:///home/ubuntu/rosdistro/index-v4.yaml'

4 执行rosdep update
新建一个终端执行rosdep update,出现如下代码则成功:

reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///home/hhz/rosdistro/rosdep/osx-homebrew.yaml
Hit file:///home/hhz/rosdistro/rosdep/base.yaml
Hit file:///home/hhz/rosdistro/rosdep/python.yaml
Hit file:///home/hhz/rosdistro/rosdep/ruby.yaml
Hit file:///home/hhz/rosdistro/releases/fuerte.yaml
Query rosdistro index file:///home/hhz/rosdistro/index-v4.yaml
Skip end-of-life distro "ardent"
Add distro "bouncy"
Add distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
updated cache in /home/hhz/.ros/rosdep/sources.cache

到此ROS安装结束!!!

ROS环境变量设置

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential

创建工作空间

初始化工作空间

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

编译工作空间

cd ~/catkin_ws/
catkin_make

使得工作空间的环境变量生效

source devel/setup.bash

使得环境变量在所有的终端中都有效

echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc

检查环境变量已经生效,创建一个新终端,输入:

echo $ROS_PACKAGE_PATH

如果打印的路径中包含当前工作空间的路径,则环境变量设置成功

如果以上内容对你有帮助的话,麻烦点个关注谢谢啦~

  • 14
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值