一、安装Ubuntu18.04
-
安装Raspberry Pi Imager
链接:https://www.raspberrypi.com/software/ -
下载镜像
下载ubuntu-18.04.5-preinstalled-server-arm64+raspi4.img.xz
链接:http://cdimage.ubuntu.com/releases/18.04/release/
PS:在这里我安装的是Ubuntu18的服务器版本,也可以根据自己的需求选择其他镜像。 -
烧录
1.选择操作系统,使用自定义镜像
2.选择存储卡
3.设置主机名,开启SSH服务,设置用户名密码,配置WiFi
4.烧录
二、安装ROS
-
SSH远程连接树莓派
后面的步骤需要在树莓派终端中进行,如果有显示器,可以直接连键鼠
因为前面配置了WiFi,可以在路由器DHCP服务器中找到树莓派的IP,然后在PC终端通过SSH远程连接树莓派。ssh username@ip
-
添加 ROS 软件源
官方默认安装源:sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
清华安装源:
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
中科大安装源:
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'
-
添加密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
-
安装ROS
更新apt
sudo apt update
安装ROS
sudo apt install ros-melodic-desktop-full
-
配置环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
使环境变量的配置生效
source ~/.bashrc
-
安装构建ROS包的依赖
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
-
初始化rosdep
安装:sudo apt install python-rosdep
初始化:
sudo rosdep init
rosdep update
-
测试
roscore
遇到问题及解决方案
1. 安装ROS报错
问题:
由于网络原因,导致连接超时,可能会安装失败
解决:
可以多次重复调用更新apt和安装ROS命令,直至成功
更新apt
sudo apt update
安装ROS
sudo apt install ros-melodic-desktop-full
2. 初始化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.
这一步是对rosdep初始化,在初始化的过程中需要访问GitHub
解决:
方法一:使用 https://ghproxy.com/ 代理 GitHub 的资源
在/usr/lib/python2.7/dist-packages
文件夹下修改相关文件:
- ./rosdep2/sources_list.py
- ./rosdep2/gbpdistro_support.py
- ./rosdep2/rep3.py
- ./rosdistro/__init__.py
- ./rosdistro/manifest_provider/github.py
具体步骤如下:
-
在
/usr/lib/python2.7/dist-packages/rosdep2
文件夹下修改文件cd /usr/lib/python2.7/dist-packages/rosdep2
修改
sources_list.py
sudo vim ./sources_list.py
在311行添加如下代码:
url = "https://ghproxy.com/" + url
将72行代码修改成如下代码(添加https://ghproxy.com/前缀):
DEFAULT_SOURCES_LIST_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list'
继续修改下一文件
gbpdistro_support.py
sudo vim ./gbpdistro_support.py
将36行代码修改成如下代码(添加https://ghproxy.com/前缀):
FUERTE_GBPDISTRO_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/' \
在204行添加如下代码:
gbpdistro_url = "https://ghproxy.com/" + gbpdistro_url
继续修改下一文件
rep3.py
sudo vim ./rep3.py
将39行代码修改成如下代码(添加https://ghproxy.com/前缀):
REP3_TARGETS_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'
-
在
/usr/lib/python2.7/dist-packages/rosdistro
下修改文件__init__.py
cd /usr/lib/python2.7/dist-packages/rosdistro
sudo vim ./__init__.py
将68行代码修改成如下代码(添加https://ghproxy.com/前缀):
DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
-
在
/usr/lib/python2.7/dist-packages/rosdistro/manifest_provider
下修改文件github.py
cd /usr/lib/python2.7/dist-packages/rosdistro/manifest_provider
sudo vim ./github.py
将119行代码修改成如下代码(添加https://ghproxy.com/前缀):
url = 'https://ghproxy.com/https://raw.githubusercontent.com/%s/%s/%s' % \
-
初始化rosdep
sudo rosdep init
有如下提示说明成功
Wrote /etc/ros/rosdep/sources.list.d/20-default.list Recommended: please run rosdep update
根据提示执行
rosdep update
方法二:将相关资源备份到 gitee,修改 rosdep 源码,重新定位资源
修改/etc/ros/rosdep/sources.list.d/20-default.list
在/usr/lib/python2.7/dist-packages
文件夹下修改相关文件:
- ./rosdep2/sources_list.py
- ./rosdep2/gbpdistro_support.py
- ./rosdep2/rep3.py
- ./rosdistro/__init__.py
具体步骤如下:
- 进入
sources.list.d
文件夹(如果没有,则新建)
修改cd /etc/ros/rosdep/sources.list.d
20-default.list
文件
将里面的sudo vim 20-default.list
raw.githubusercontent.com/ros/rosdistro/master
替换成gitee.com/XHN-1/rosdistro/raw/master
如果是新建的文件,直接编辑
修改后:# os-specific listings first yaml https://gitee.com/XHN-1/rosdistro/raw/master/rosdep/osx-homebrew.yaml osx # generic yaml https://gitee.com/XHN-1/rosdistro/raw/master/rosdep/base.yaml yaml https://gitee.com/XHN-1/rosdistro/raw/master/rosdep/python.yaml yaml https://gitee.com/XHN-1/rosdistro/raw/master/rosdep/ruby.yaml gbpdistro https://gitee.com/XHN-1/rosdistro/raw/master/releases/fuerte.yaml fuerte # newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
- 在
/usr/lib/python2.7/dist-packages/rosdep2
文件夹下修改文件
修改cd /usr/lib/python2.7/dist-packages/rosdep2
sources_list.py
将72行代码修改成如下代码(把raw.githubusercontent.com/ros/rosdistro/master替换成gitee.com/XHN-1/rosdistro/raw/master):sudo vim ./sources_list.py
继续修改下一文件DEFAULT_SOURCES_LIST_URL = 'https://gitee.com/XHN-1/rosdistro/raw/master/rosdep/sources.list.d/20-default.list'
gbpdistro_support.py
将36行代码修改成如下代码(把raw.githubusercontent.com/ros/rosdistro替换成gitee.com/XHN-1/rosdistro/raw):sudo vim ./gbpdistro_support.py
继续修改下一文件FUERTE_GBPDISTRO_URL = 'https://gitee.com/XHN-1/rosdistro/raw/' \
rep3.py
将39行代码修改成如下代码(把raw.githubusercontent.com/ros/rosdistro/master替换成gitee.com/XHN-1/rosdistro/raw/master):sudo vim ./rep3.py
REP3_TARGETS_URL = 'https://gitee.com/XHN-1/rosdistro/raw/master/releases/targets.yaml'
- 在
/usr/lib/python2.7/dist-packages/rosdistro
下修改文件__init__.py
cd /usr/lib/python2.7/dist-packages/rosdistro
将68行代码修改成如下代码(把raw.githubusercontent.com/ros/rosdistro/master替换成gitee.com/XHN-1/rosdistro/raw/master):sudo vim ./__init__.py
DEFAULT_INDEX_URL = 'https://gitee.com/XHN-1/rosdistro/raw/master/index-v4.yaml'
- 初始化rosdep
直接执行
PS:第一步相当于手动执行了sudo rosdep initrosdep update
方法三:使用rosdepc
- 安装pip
sudo apt install python-pip
- 安装rosdepc
sudo pip install rosdepc
- 使用rosdepc初始化
sudo rosdepc init
rosdepc update
参考资料:
安装ROS:
http://www.autolabor.com.cn/book/ROSTutorials/
初始化rosdep报错及解决:
方法一:【ROS】Ubuntu18.04下安装ROS-Melodic的步骤及rosdep update报错的解决方案
方法二:ROS rosdep init/update百分百解决
方法三:本文之后,世上再无rosdep更新失败问题!如果有…小鱼就…