踩坑之旅:配置 ROS 环境
以下内容为本人的著作,如需要转载,请声明原文链接微信公众号「englyf」https://www.cnblogs.com/englyf/p/16660252.html
最近在学习机器人相关的导航算法,为了方便于验证算法的效果,需要搭一个 ROS(Robot Operate System) 环境。特地写点笔记,这是这个机器人系列的首篇笔记。
虽然在网络上有很详细的教程,不过在对着教程一步步安装的过程中还是踩了不少坑。因为在墙内(你懂的),会导致联网下载文件的时候老是失败。可能你会说不可以指定墙内的安装源吗?可以是可以,不过在安装完 ROS 包后还需要初始化一些环境,比如 rosdep 的初始化,这时候还是需要从 github 联网下载文件的,这时就算指定了墙内的安装源也不管事,因为这个 github 的域名被污染了。下面就记录一下解决的过程吧,回首往事真的一把心酸。。。
基础环境:
Ubuntu 18.04
ROS Melodic
VMware Workstation 14 Pro
1.配置软件仓库
确保软件仓库里允许下载的资源类型包括 main
, universe
, restricted
, multiverse
。如下面图所示,
2.指定墙内的安装源
国内的安装源有好几个,还是觉得阿里的安装源比较快一些,直接拷贝下面的内容到 /etc/apt/sources.list
文件中替换原来的内容并且保存
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
# deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src 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-backports main restricted universe multiverse
单独指定 ROS 包的安装源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.aliyun.com/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
3.指定密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
到目前为止,以上的设置都很顺利。如果这一步你刚好出错了,可以到这里去看看处理方法。
4.安装 ROS 包
更新一下安装索引
sudo apt update
安装完整的桌面版
sudo apt install ros-melodic-desktop-full
中间会出现提示
Do you want to continue? [Y/n]
输入 Y 然后回车继续安装过程,花点时间休息一下再回来。。。
回来一看
E: Failed to fetch http://mirrors.aliyun.com/ros/ubuntu/pool/main/r/ros-melodic-rqt-moveit/ros-melodic-rqt-moveit_0.5.10-1bionic.20210505.031448_amd64.deb Undetermined Error [IP: 120.241.234.99 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
出现了这一坨失败提示,后边还建议加个参数 --fix-missing
下载补漏,好的再来一次
sudo apt install ros-melodic-desktop-full --fix-missing
好了,安装完成
5.配置 ROS 环境变量
为了在每次启动 bash 时都自动载入 ROS 的环境变量,输入
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
配置完,重启一下 Terminal 窗口
6.安装一些关键的依赖包
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
中间又会出现提示
Do you want to continue? [Y/n]
输入 Y 然后回车继续安装过程
7.初始化 ROS 的依赖安装管理包 rosdep
rosdep 是 ROS 安装管理包。使用 ROS 过程中如果需要安装被 ROS 要编译的源代码,或被某些 ROS 核心组件依赖的包,那么就可以用 rosdep 来安装。使用前,这个包需要被初始化一次
sudo rosdep init
但是,很多情况下你会碰到下面这些错误提示
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.
报错内容的意思说白了就是说域名 raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
的页面找不到了。真实情况其实是这个地址的域名因为众所周知的原因被污染了,并不是页面已经下架。
我是这么处理的,在网上搜一下关键词 域名查IP
找到可以查域名对应 IP 的网站,然后根据查到的 IP 来修改 主机名静态查询表
文件。如果网站告诉你 禁止查询该域名
,那就再换一个网站再查,多大点事!
我这里页面返回的结果是
物理地址 | IP地址 | 数字地址 |
---|---|---|
美国加利福尼亚旧金山 | 185.199.108.133 | 3116854405 |
美国加利福尼亚旧金山 | 185.199.111.133 | 3116855173 |
美国加利福尼亚旧金山 | 185.199.110.133 | 3116854917 |
美国加利福尼亚旧金山 | 185.199.109.133 | 3116854661 |
打开 /etc/hosts 文件,这个就是 主机名静态查询表 |
sudo gedit /etc/hosts
对应上边查到的 IP 地址,把下面的内容拷贝追加到 /etc/hosts
的尾部并保存
185.199.108.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
然后,再试一次
~$ sudo rosdep init
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run
rosdep update
成功通过这一关,接着执行更新一下
~$ rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
ERROR: error loading sources list:
('The read operation timed out',)
可惜又访问失败了,这会儿报的是读操作超时。重试了好几回,没办法了,看来要动用大招~
上面说白了就是读 github 网站的资源不稳定,那么我们就找一个 github 的代理资源吧。刚好我这认识一个 https://ghproxy.com/
支持对 github 资源代理加速,速度非常好,目前是的。
下面是应用加速代理
打开文件,这里注意一下 ROS Melodic 用的是 python2
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
找到函数 download_rosdep_data
,把变量 url 赋值成
url = "https://ghproxy.com/" + url
修改后效果
def download_rosdep_data(url):
"""
:raises: :exc:`DownloadFailure` If data cannot be
retrieved (e.g. 404, bad YAML format, server down).
"""
try:
# http/https URLs need custom requests to specify the user-agent, since some repositories reject
# requests from the default user-agent.
url = "https://ghproxy.com/" + url
if url.startswith("http://") or url.startswith("https://"):
url_request = request.Request(url, headers={'User-Agent': 'rosdep/{version}'.format(version=__version__)})
else:
url_request = url
f = urlopen(url_request, timeout=DOWNLOAD_TIMEOUT)
text = f.read()
f.close()
data = yaml.safe_load(text)
if type(data) != dict:
raise DownloadFailure('rosdep data from [%s] is not a YAML dictionary' % (url))
return data
except (URLError, httplib.HTTPException) as e:
raise DownloadFailure(str(e) + ' (%s)' % url)
except yaml.YAMLError as e:
raise DownloadFailure(str(e))
打开下面的几个文件,在所有找到的 https://raw.githubusercontent.com
字符串前添加上 https://ghproxy.com/
保存即可。
/usr/lib/python2.7/dist-packages/rosdistro/__init__.py
/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py
/usr/lib/python2.7/dist-packages/rosdistro/manifest_provider/github.py
不过,对于文件 /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
里函数 download_gbpdistro_as_rosdep_data 的输入参数 gbpdistro_url 在应用前也需要补上加速地址
def download_gbpdistro_as_rosdep_data(gbpdistro_url, targets_url=None):
"""
Download gbpdistro file from web and convert format to rosdep distro data.
DEPRECATED: see REP137. This function will output
(at least) one deprecation warning
:param gbpdistro_url: url of gbpdistro file, ``str``
:param target_url: override URL of platform targets file
:raises: :exc:`DownloadFailure`
:raises: :exc:`InvalidData` If targets file does not pass cursory
validation checks.
"""
# we can convert a gbpdistro file into rosdep data by following a
# couple rules
# will output a warning
targets_data = download_targets_data(targets_url=targets_url)
gbpdistro_url = "https://ghproxy.com/" + gbpdistro_url
try:
f = urlopen(gbpdistro_url, timeout=DOWNLOAD_TIMEOUT)
text = f.read()
f.close()
gbpdistro_data = yaml.safe_load(text)
# will output a warning
return gbprepo_to_rosdep_data(gbpdistro_data,
targets_data,
gbpdistro_url)
except Exception as e:
raise DownloadFailure('Failed to download target platform data '
'for gbpdistro:\n\t' + str(e))
好了,大招都使完了,看看效果
~$ rosdep update
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
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Add distro "foxy"
Add distro "galactic"
Skip end-of-life distro "groovy"
Add distro "humble"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/if/.ros/rosdep/sources.cache
8.测试一下环境
分别按顺序独立在各自的终端里执行下边的这几个指令
// 启动 ROS 核心
roscore
// 启动 ROS 仿真平台
rosrun turtlesim turtlesim_node
// 接收方向键按键信息
rosrun turtlesim turtle_teleop_key
在最后的终端里按着键盘方向键就可以控制仿真窗口里的小乌龟动起来了
如果你能顺利走到这里,说明 ROS 环境可以正常跑了。
后记:
其实写这篇笔记的过程中,除了首次配置环境,还穿插了很多任务,导致配置的过程一直停滞不前,笔记也落下那么久才发出来。如果你在对照这篇笔记来配置 ROS 环境的时候也碰到了其它的问题,欢迎留言提出来,或者添加我的微信公众号englyf给我留言?毕竟博客不一定一直在线。
踩坑之旅:配置 ROS 环境的更多相关文章
- vue+ vue-router + webpack 踩坑之旅
说是踩坑之旅 其实是最近在思考一些问题 然后想实现方案的时候,就慢慢的查到这些方案 老司机可以忽略下面的内容了 1)起因 考虑到数据分离的问题 因为server是express搭的 自然少 ...
- CentOS7使用tar.gz包安装MySql的踩坑之旅
由于客户的CentOS服务器没有安装yum工具,只能通过下载tar.gz包安装mysql,于是跟着万能的百度开启了漫漫踩坑之旅: 1.下载mysql-5.6.33-linux-glibc2.5-x86 ...
- EasyTrader踩坑之旅总结
easytrader是用python写的可以调用主要券商完成自动化炒股的一个软件 ,但我用的是同花顺,在研究过程中,发现同花顺暂时调不通.后来搜索发现thstrade的源码作者说是easytrad ...
- 我的微信小程序入门踩坑之旅
前言 更好的阅读体验请:我的微信小程序入门踩坑之旅 小程序出来也有一段日子了,刚出来时也留意了一下.不过赶上生病,加上公司里也有别的事,主要是自己犯懒,就一直没做.这星期一,赶紧趁着这股热乎劲,也不是 ...
- 微信小程序之mpvue+iview踩坑之旅
因为之前参照微信的原生的文档写过一些小程序的demo,写的过程比较繁琐,后来出了美团的mpvue,可以直接使用vue开发,其他的不作对比,这篇文章记录一下踩坑之旅. 参照mpvue http://mp ...
- Python踩坑之旅其一杀不死的Shell子进程
目录 1.1 踩坑案例 1.2 填坑解法 1.3 坑位分析 1.4 坑后扩展 1.4.1 扩展知识 1.4.1 技术关键字 1.5 填坑总结 1.1 踩坑案例 踩坑的程序是个常驻的Agent类管理进程 ...
- [代码修订版] Python 踩坑之旅 [进程篇其四] 踩透 uid euid suid gid egid sgid的坑坑洼洼
目录 1.1 踩坑案例 1.2 填坑解法 1.3 坑位分析 1.4 技术关键字 1.5 坑后思考 下期坑位预告 代码示例支持 平台: Centos 6.3 Python: 2.7.14 代码示例: 公 ...
- 安装并配置ROS环境1
ros学习之路(原创博文,转载请标明出处-周学伟http://www.cnblogs.com/zxouxuewei/) 一.ros核心教程 1.安装并配置ROS环境: 注意: 学习这节课之前请按 ...
- vue踩坑之旅 -- computed watch
vue踩坑之旅 -- computed watch 经常在使用vue初始化组件时,会报一些莫名其妙的错误,或者,数据明明有数据,确还是拿不到,这是多么痛苦而又令人忍不住抓耳挠腮,捶胸顿足啊 技术点 v ...
随机推荐
- 基于thinkphp6 layui的优秀极速后台开发框架推荐
很多时候我们在做项目开发的时候,苦于没有好一点的轮子,自己动手开发的话,太耗费时间了,如果采用VUE的话,学习成本跟调试也比较麻烦, 而且有时候选用的东西甲方也不太容易接受,现在给大家介绍一款优秀的极 ...
- Docker 配置 Seata 集成 Nacos
1.拉取镜像 docker pull seataio/seata-server:1.4.2 docker run --name seata -p 8091:8091 -d seataio/seata- ...
- 纪念我逝去的n个小时
纪念我逝去的n个小时 某人的惨案要我擦屁股=.= #include <bits/stdc++.h> using namespace std; template<class T> ...
- Spring框架系列(12) - Spring AOP实现原理详解之JDK代理实现
上文我们学习了SpringAOP Cglib动态代理的实现,本文主要是SpringAOP JDK动态代理的案例和实现部分.@pdai Spring框架系列(12) - Spring AOP实现原理详解 ...
- 集合容器和Hash表
集合容器 集合相当于一个容器,在我们使用Arraylist的时候添加参数相当与放了一个容器中.这里面的元素是可以重复的 在HashSet中添加元素是没有重复的,我们来写一个测试看一下 public s ...
- 记一次react-hooks项目获取图表图片集合并生成pdf的需求
需求: 获取子组件中所有图片的dom元素并生成图片,再把生成的图片转化为pdf下载 难点 众所周知,react是单向数据流,倡导f(data)⇒ UI的哲学, 并不建议过多直接操作dom,但是生成图片 ...
- highcharts图表及报表展示、导出数据
@ 目录 前言 一.使用highcharts前后端交互展示图表,及使用报表导出 二.实现思路 1.图表可以选择echarts.highcharts,我们这里选择highcharts(echarts使用 ...
- 启用Hyper-v后,重启后界面提示 无法完成功能配置,正在撤销更改
安装docker后,提示需要启用hyper-v,在控制面板中勾选Hyper-v,然后重启,更新快完成就提示无法完成功能配置,正在撤销更改 解决方法 方法1 控制面板一个一个选 方法2 百度了n多内容, ...
- C# 给Word每一页设置不同文字水印
Word中设置水印时,可预设的文字或自定义文字设置为水印效果,但通常添加水印效果时,会对所有页面都设置成统一效果,如果需要对每一页或者某个页面设置不同的水印效果,则可以参考本文中的方法.下面,将以C# ...
- Python3的单元测试模块Mock与性能测试模块CProfile
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_92 我们知道写完了代码需要自己跑一跑进行测试,一个写好的程序如果连测试都没有就上到生产环境是不敢想象的,这么做的人不是太自信就是太 ...