Ubuntu18.04安装ROS Melodic详细过程(有效解决rosdep init网络原因导致的失败)

整合了安装ROS Melodic过程中出现的一些问题

  1. 设置软件源
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  1. 设置秘钥
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
  1. 更新源地址
sudo apt-get update
  1. 安装
sudo apt-get install ros-melodic-desktop-full
sudo apt-get install ros-melodic-rqt*
  1. 初始化rosdep
sudo rosdep init

如果提示“sudo: rosdep:找不到命令”,执行

sudo apt-get install python-rosdep

如果出现下面情况,基本是网络问题

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.

用了很多方法(手机热点,修改域名等)都不行。

此时,使用本地安装方法

该部分引用https://blog.csdn.net/nanianwochengshui/article/details/105702188
  • 进入https://github.com/ros/rosdistro下载安装包,解压路径不要含中文!
  • 修改这个包中rosdep/source.list.d/下的文件20-default.list,将这个文件中指向raw.githubusercontent.com的url地址全部修改为指向本地文件的地址,也就是该下载好的包的地址:如下:
# os-specific listings first
yaml file:///home/xx/rosdistro/rosdep/osx-homebrew.yaml osx

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

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
  • 在py语言中:url本地文件地址格式是:file://+文件地址
  • 修改/usr/lib/python2.7/dist-packages/rosdep2/main.py中的默认的url的地址,经过对代码的分析,默认地址在/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py中定义,找到"DEFAULT_SOURCES_LIST_URL",修改为本地路径
# default file to download with 'init' command in order to bootstrap
# rosdep
#DEFAULT_SOURCES_LIST_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list'
DEFAULT_SOURCES_LIST_URL = 'file:///home/xx/rosdistro/rosdep/sources.list.d/20-default.list'
  • 修改以下两个文件里面的代码
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py
/usr/lib/python2.7/dist-packages/rosdistro/__init__.py
  1. /usr/lib/python2.7/dist-packages/rosdep2/rep3.py文件:
# location of targets file for processing gbpdistro files
#REP3_TARGETS_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'
REP3_TARGETS_URL = 'file:///home/xx/rosdistro/releases/targets.yaml'

  1. /usr/lib/python2.7/dist-packages/rosdistro/init.py文件
# index information

#DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
DEFAULT_INDEX_URL = 'file:///home/xx/rosdistro/index-v4.yaml'
  • 执行
sudo rosdep init
rosdep update
  1. 安装rosinstall
sudo apt-get install python-rosinstall
  1. 加载环境设置文件
source /opt/ros/melodic/setup.bash
  1. 创建并初始化工作目录
    ROS使用一个名为catkin的ROS专用构建系统。为了使用它,用户需要创建并初始化catkin工作目录,如下所示。除非用户创建新的工作目录,否则此设置只需设置一次
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace

cd ~/catkin_ws/
catkin_make
  1. 设置环境变量
# Set ROS melodic
source /opt/ros/melodic/setup.bash
# Set ROS Network
export ROS_HOSTNAME=localhost
export ROS_MASTER_URI=localhost:11311
  1. 测试demo
    打开三个终端,分别执行
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
  • 注意:三个终端执行命令时若报错
Command 'rosrun' not found, but can be installed with:

sudo apt install rosbash

需要加载环境设置

source /opt/ros/melodic/setup.bash
2021-06-22 15-51-36 的屏幕截图.png

你可能感兴趣的:(Ubuntu18.04安装ROS Melodic详细过程(有效解决rosdep init网络原因导致的失败))