ORBSLAM2|ubuntu18.04 ROS melodic完整版教程及错误处理(附带 catkin_ws工作空间搭建)

一、配置Ubuntu软件库 桌面点击Ubuntu软件,接着左上角点击Ubuntu软件,点击软件和更新。
将可从互联网下载的所有选项选中,并且将下载自 选为 中国 的服务器
二、安装过程及错误处理 ros官网安装教程: ROS Instal

  1. 设置安装源,与官网教程不同,此处需要设置代理源,如清华源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

  1. 设置密钥
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

  1. 更新软件包
sudo apt update

  1. 安装ROS melodic
    提前安装python-rosdep,避免出现sudo rosdep:找不到命令提示
sudo apt install python-rosdep sudo apt-get install ros-melodic-desktop-full

  • 如果出现如下错误
W: GPG 错误:http://mirrors.ustc.edu.cn/ros/ubuntu bionic InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY F42ED6FBAB17C654

  • 执行以下命令
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

  1. 初始化ROS(网络报错问题最终解决方案)
    初始化ROS过程中需要通过网络下载一些文件,但由于网络网速不够或其他原因,会出现无法下载和无法连接的错误,如下:
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.

ERROR: error loading sources list: ('The read operation timed out',)

sudo rosdep initrosdep update 报错终极解决方案如下:
1 将rosdistro clone到本地
这里,可以选择github方式
git clone https://github.com/ros/rosdistro.git

建议选择gitee的方式(此方法下载更快,库是我自己导入的,可以使用!)
git clone https://gitee.com/huang_hongzhi/rosdistro.git

注意这里克隆的地址选择根目录,我的用户名是hhz,那么这个文件夹的地址就是~/rosdistro,即/home/hhz/rosdistro
2 创建20-default.list,对应sudo rosdep init 这一步
打开一个新终端,输入以下内容,用途是创建20-default.list
sudo su //输入你的密码切换至root sudo mkdir -p /etc/ros/rosdep/sources.list.d cd /etc/ros/rosdep/sources.list.d sudo gedit 20-default.list

将以下内容复制进20-default.list
注意:以下的yourname全部改为你们自己的用户名
#os-specific listings first yaml file:///home/yourname/rosdistro/rosdep/osx-homebrew.yaml osx #generic yaml file:///home/yourname/rosdistro/rosdep/base.yaml yaml file:///home/yourname/rosdistro/rosdep/python.yaml yaml file:///home/yourname/rosdistro/rosdep/ruby.yaml gbpdistro file:///home/yourname/rosdistro/releases/fuerte.yaml fuerte#newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

3 替换下载网址为本地的文件
  • 打开第一个文件
cd /home/yourname/rosdistro/rosdep/sources.list.d/ sudo gedit 20-default.list

将里面所有的 raw.githubusercontent.com替换成file:///home/yourname/rosdistro的地址,如下:
# os-specific listings first yaml file:///home/yourname/rosdistro/rosdep/osx-homebrew.yaml osx# generic yaml file:///home/yourname/rosdistro/rosdep/base.yaml yaml file:///home/yourname/rosdistro/rosdep/python.yaml yaml file:///home/yourname/rosdistro/rosdep/ruby.yaml gbpdistro file:///home/yourname/rosdistro/releases/fuerte.yaml fuerte# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

  • 打开第二个文件
cd /usr/lib/python2.7/dist-packages/rosdep2/ sudo gedit gbpdistro_support.py

替换对应的内容(注意两行都要换)
FUERTE_GBPDISTRO_URL = 'file:///home/yourname/rosdistro/' \ 'releases/fuerte.yaml'

  • 打开第三个文件
cd /usr/lib/python2.7/dist-packages/rosdep2/ sudo gedit rep3.py

替换对应的内容
REP3_TARGETS_URL = 'file:///home/yourname/rosdistro/releases/targets.yaml'

  • 打开第四个文件
    我电脑里是 __init__.py,但是作者的是init.py
cd /usr/lib/python2.7/dist-packages/rosdistro/ sudo gedit __init__.py

替换对应的内容
DEFAULT_INDEX_URL = 'file:///home/yourname/rosdistro/index-v4.yaml'

4 执行rosdep update
新建一个终端执行rosdep update,出现如下代码则成功:
reading in sources list data from /etc/ros/rosdep/sources.list.d Hit file:///home/hhz/rosdistro/rosdep/osx-homebrew.yaml Hit file:///home/hhz/rosdistro/rosdep/base.yaml Hit file:///home/hhz/rosdistro/rosdep/python.yaml Hit file:///home/hhz/rosdistro/rosdep/ruby.yaml Hit file:///home/hhz/rosdistro/releases/fuerte.yaml Query rosdistro index file:///home/hhz/rosdistro/index-v4.yaml Skip end-of-life distro "ardent" Add distro "bouncy" Add distro "crystal" Add distro "dashing" Add distro "eloquent" Skip end-of-life distro "groovy" Skip end-of-life distro "hydro" Skip end-of-life distro "indigo" Skip end-of-life distro "jade" Add distro "kinetic" Skip end-of-life distro "lunar" Add distro "melodic" updated cache in /home/hhz/.ros/rosdep/sources.cache

ROS环境变量设置
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc source ~/.bashrc sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential

创建工作空间 初始化工作空间
mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src catkin_init_workspace

编译工作空间
cd ~/catkin_ws/ catkin_make

使得工作空间的环境变量生效
source devel/setup.bash

使得环境变量在所有的终端中都有效
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc

检查环境变量已经生效,创建一个新终端,输入:
echo $ROS_PACKAGE_PATH

如果打印的路径中包含当前工作空间的路径,则环境变量设置成功
【ORBSLAM2|ubuntu18.04 ROS melodic完整版教程及错误处理(附带 catkin_ws工作空间搭建)】如果以上内容对你有帮助的话,麻烦点个关注谢谢啦~

    推荐阅读