树莓派4B安装Ubuntu18.04 ROS Melodic及初始化rosdep报错解决

  • Post author:
  • Post category:其他




一、安装Ubuntu18.04

  1. 安装

    Raspberry Pi Imager


    链接:

    https://www.raspberrypi.com/software/

  2. 下载镜像

    下载

    ubuntu-18.04.5-preinstalled-server-arm64+raspi4.img.xz


    链接:

    http://cdimage.ubuntu.com/releases/18.04/release/


    PS:在这里我安装的是Ubuntu18的服务器版本,也可以根据自己的需求选择其他镜像。

  3. 烧录

    1.选择操作系统,使用自定义镜像

    2.选择存储卡

    3.设置主机名,开启SSH服务,设置用户名密码,配置WiFi

    4.烧录



二、安装ROS

  1. SSH远程连接树莓派

    后面的步骤需要在树莓派终端中进行,如果有显示器,可以直接连键鼠

    因为前面配置了WiFi,可以在路由器DHCP服务器中找到树莓派的IP,然后在PC终端通过SSH远程连接树莓派。

    ssh username@ip
    
  2. 添加 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'
    
  3. 添加密钥

    sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
    
  4. 安装ROS

    更新apt

    sudo apt update
    

    安装ROS

    sudo apt install ros-melodic-desktop-full
    
  5. 配置环境变量

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

    使环境变量的配置生效

    source ~/.bashrc
    
  6. 安装构建ROS包的依赖

    sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
    
  7. 初始化rosdep

    安装:

    sudo apt install python-rosdep
    

    初始化:

    sudo rosdep init
    
    rosdep update
    
  8. 测试

    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

具体步骤如下:



  1. /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'
    


  2. /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'
    


  3. /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' % \
    
  4. 初始化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

具体步骤如下:

  1. 进入

    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
    


  2. /usr/lib/python2.7/dist-packages/rosdep2

    文件夹下修改文件

    cd /usr/lib/python2.7/dist-packages/rosdep2
    

    修改

    sources_list.py

    sudo vim ./sources_list.py
    

    将72行代码修改成如下代码(把raw.githubusercontent.com/ros/rosdistro/master替换成gitee.com/XHN-1/rosdistro/raw/master):

    DEFAULT_SOURCES_LIST_URL = 'https://gitee.com/XHN-1/rosdistro/raw/master/rosdep/sources.list.d/20-default.list'
    

    继续修改下一文件

    gbpdistro_support.py

    sudo vim ./gbpdistro_support.py
    

    将36行代码修改成如下代码(把raw.githubusercontent.com/ros/rosdistro替换成gitee.com/XHN-1/rosdistro/raw):

    FUERTE_GBPDISTRO_URL = 'https://gitee.com/XHN-1/rosdistro/raw/' \
    

    继续修改下一文件

    rep3.py

    sudo vim ./rep3.py
    

    将39行代码修改成如下代码(把raw.githubusercontent.com/ros/rosdistro/master替换成gitee.com/XHN-1/rosdistro/raw/master):

    REP3_TARGETS_URL = 'https://gitee.com/XHN-1/rosdistro/raw/master/releases/targets.yaml'
    


  3. /usr/lib/python2.7/dist-packages/rosdistro

    下修改文件

    __init__.py

    cd /usr/lib/python2.7/dist-packages/rosdistro
    
    sudo vim ./__init__.py
    

    将68行代码修改成如下代码(把raw.githubusercontent.com/ros/rosdistro/master替换成gitee.com/XHN-1/rosdistro/raw/master):

    DEFAULT_INDEX_URL = 'https://gitee.com/XHN-1/rosdistro/raw/master/index-v4.yaml'
    
  4. 初始化rosdep

    直接执行

    rosdep update
    

    PS:第一步相当于手动执行了sudo rosdep init


方法三:使用rosdepc

  1. 安装pip

    sudo apt install python-pip
    
  2. 安装rosdepc

    sudo pip install rosdepc
    
  3. 使用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更新失败问题!如果有…小鱼就…



版权声明:本文为Ignorant_dull原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。