ROS(melodic)安装问题汇总及解决方法

终于装上了ROS,费了很大的波折,基本上能遇到的问题都遇到了-_-||,记在这里希望能给遇到同样问题的朋友一点参考。

首先是在虚拟机上装ubuntu 18.04,这个没什么问题,所用的镜像文件如下:

链接:https://pan.baidu.com/s/1ZDf6okiH72d4WztCD8ixPg 
提取码:u8e1

接下来安装ROS,就开始各种出问题。首先是一直报错无法定位软件包,以为是源的问题,后来参考了ROS教程(一):ROS安装教程(详细图文)_Leslie的博客-CSDN博客_ros安装,发现可能是版本造成的。ROS与ubuntu的版本是有对应的,对应关系如下:

Ubuntu

ROS 1.0

ROS 2.0

16.04 LTS

Kinetic LTS

Ardent

18.04 LTS

Melodic LTS

Dashing LTS

20.04 LTS

Noetic LTS

Foxy LTS

因为我用的ubuntu是18.04版本,所以ROS得装melodic,步骤如下:

(1)替换源

因为外国源可能会访问不了,最好把源替换成国内的,参考:【Ubuntu 】Ubuntu 更换国内源—解决终端下载错误或速度慢的问题_Leslie的博客-CSDN博客_ubuntu18.04换源

①备份原始文件sources.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

②修改源文件sources.list

sudo chmod 777 /etc/apt/sources.list

更改文件权限使其可编辑;

sudo gedit /etc/apt/sources.list

打开文件进行编辑;

删除原来的文件内容,复制下面的任意一个到其中并保存:

阿里源:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb 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 main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

清华源:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

③更新源

sudo apt update

(2)软件中心配置

 在软件中心选择“software & update”,按下图配置:

(3)添加源

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

配置公网密钥,(这一步是确保我们的系统认为这个路径是安全的,下载文件是没有问题的。不然下载的东西会立刻被清除掉):

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

(4)安装

①更新源列表:

sudo apt-get update

②安装ROS melodic:

sudo apt-get install ros-melodic-desktop-full

③安装完成,使用下面的指令查看可使用的包:

apt-cache search ros-melodic

(5)配置ROS环境到系统

首先需要初始化 rosdep,rosdep 让你能够轻松地安装被想要编译的源代码,或被某些 ROS 核心组件需要的系统依赖:

sudo rosdep init rosdep update

这个地方一直有问题:

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 init时website may be down解决方案_Qrpucp的博客-CSDN博客

①先排除DNS的问题

添加Google的DNS服务器。将下面两行内容添加进/etc/resolv.conf文件:

nameserver 8.8.8.8

nameserver 8.8.4.4

如果不能保存,可以用以下指令修改文件权限:

sudo chmod 777 /etc/resolv.conf

②换手机热点

失败_(¦3」∠)_

③使用代理工具

没有合适的工具使用,放弃_(¦3」∠)_

④手动下载、改nameserver和证书

没有找到/etc/ros/rosdep/sources.list.d目录!(╯‵□′)╯︵┻━┻手动增加了这个目录,后面操作按照步骤进行,最后还是失败,只好又把这个目录给删掉了。但不知道为什么,再运行rosdep init的时候,成功新建了需要的文件,提示可以继续进行update了……

limeng@ubuntu:~$ sudo rosdep init

Wrote /etc/ros/rosdep/sources.list.d/20-default.list

Recommended: please run

rosdep update

但是继续update又报错:

$ rosdep update

reading in sources list data from /etc/ros/rosdep/sources.list.d

Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml

Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml

Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml

ERROR: error loading sources list:

('The read operation timed out',)

不知道是不是还是因为墙的问题。_(¦3」∠)_

最后参考Ubuntu18.04安装ROS Melodic(解决网络原因,先将所需压缩包下载到本地,然后rosdep update)_Sun的博客-CSDN博客_rosdep update 本地的做法,直接把需要的文件下载到本地,终于可以了。

(6)接下来初始化环境变量:

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

又出现问题,提示:

bash: /opt/ros/melodic/setup.bash: No such file or directory

参考:安装ROS报错bash: /opt/ros/kinetic/setup.bash: No such file or directory的解决方法_Venquieu的博客-CSDN博客

原来是安装的过程中缺失了setup.bash文件,只需要安装一个ROS自带的功能包就可以了,最方便的就是安装turtlesim了:

sudo apt-get install 
ros-melodic-turtlesim

安装完之后再用source命令就可以了。

(7) 安装 rosinstall

sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential

这次终于比较顺利了。。。

(8)运行roscore

又报错( Ĭ ^ Ĭ )

Command 'roscore' not found, but can be installed with: sudo apt install python-roslaunch

参考:ROS安装问题: “Command ‘roscore‘ not found, but can be installed with: sudo apt install python-roslaunch“_tom17的博客-CSDN博客

发现/opt/ros/indigo/bin/文件夹中确实没有名为“roscore” 的二进制可执行文件

执行以下命令:

sudo apt-get install ros-melodic-desktop

终于配置好了✿✿ヽ(°▽°)ノ✿

运行一下海龟测试程序,在三个终端分别输入:

roscore 
rosrun turtlesim turtlesim_node 
rosrun turtlesim turtle_teleop_key

效果如下:

  • 5
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值