以下内容为本人的著作,如需要转载,请声明原文链接 微信公众号「englyf」https://mp.weixin.qq.com/s/IS2lkMud7x_u0aZKar9z3w
最近在学习机器人相关的导航算法,为了方便于验证算法的效果,需要搭一个 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.