ubunt18.04安装ROS避坑指南

1 前言:

本文是ubunt18.04下安装ros的,如果想使用ros2,请看我的下一篇文章,ubunt18.04安装ROS2

本来是不该写的,有官方文档,还有很多大神的分析。但里面的坑太多,我考虑了一下,还是想记录下避免下次在跳泥坑;

坑在哪里呢,其实如果能正常访问某些网站,理论上2个小时左右是完全能完成安装的,坑就在这些安装网站是打不开的,我这就是个神坑;

一个翻译的官网安装步骤;一个是业内名气很大的古月居整理的,对,确实是整理的,因为它给的解决方案,我在zhihu上无意看过。

http://dev.ros2.fishros.com/doc/Installation/Ubuntu-Install-Binary.html#system-requirements
https://www.guyuehome.com/34563

几个重要网址你先测试下

常见的安装资料步骤会用到如下两个网站

http://packages.ros.org/ros/ubuntu
https://raw.githubusercontent.com

我这边的网络是一个也打不开,导致了我安装ros难度变大;

然后测试下如下两个网站

第一个是ros下载,第二是rosdep init update 用的

http://mirrors.ustc.edu.cn/ros/ubuntu/ 
https://github.com/ros/rosdistro

等于说是替换版本;

2 更改Ubuntu软件源

更改Ubuntu软件源
https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
在这里插入图片描述

sudo gedit /etc/apt/sources.list

打开后把清华源对应版本 进行替换;

3 添加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.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

向系统添加秘钥输入以下命令:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

安装错误

sudo apt-get update
sudo apt-get install ros-melodic-desktop-full python-rosinstall

此处如果出问题,请参考
https://blog.csdn.net/qq_44830040/article/details/106049992

如果出现这种错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 ros-indigo-desktop-full : Depends: ros-indigo-desktop but it is not going to be installed
                           Depends: ros-indigo-perception but it is not going to be installed
                           Depends: ros-indigo-simulators but it is not going to be installed
                           Depends: ros-indigo-urdf-tutorial but it is not going to be installed
E: Unable to correct problems, you have held broken packages. 
使用sudo aptitude install ros-melodic-desktop-full 安装

4 sudo rosdep init &&rosdep update update失败

ROS:sudo rosdep init出错常规方法都无效后解决办法记录
如果还不行,我是参考如下:
https://blog.csdn.net/Iamsonice/article/details/123315787

第一:手动创建
sudo mkdir -p /etc/ros/rosdep/sources.list.d
cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list

然后将下面的内容粘贴到这个20-default.list文件里面:

# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

如果你继续执行sudo rosdep init ,还是同样错误,不用管他

第二步 update

依然失败;
换个思路,这篇文章有介绍
https://blog.csdn.net/Iamsonice/article/details/123315787
先把所需的文件下载下来,就是下载update所需的一些配置文件

git clone https://github.com/ros/rosdistro.git home/fang/ros2/download
替换一
sudo gedit /usr/lib/python3/dist-packages/rosdep2.7/rep3.py

输入后回车会弹出rep3.py文件将原来文件中的 REP3_TARGETS_URL = ‘https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml’ 替换成 REP3_TARGETS_URL = ‘file:///home/fang/ros2/download/rosdistro/releases/targets.yaml’
在这里插入图片描述

替换二

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

输入回车后会弹出__init__.py文件将原来文件中的 DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml’替换成 DEFAULT_INDEX_URL = ‘file:///home/nice/robot/index-v4.yaml’
在这里插入图片描述

替换三:

修改/etc/ros/rosdep/sources.list.d/20-default.list中的网址为本地地址

sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list

输入回车后会弹出20-default.list文件将原来文件中的所有 raw.githubusercontent.com开头的网址替换成对应文件在本地的路径(可将下面代码更换20-default.list中的代码

#os-specific listings first
yaml file:///home/fang/ros2/download/rosdistro/rosdep/osx-homebrew.yaml osx

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

#newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

然后再次rosdep update

fang@fang-inspiron-5580:~/ros2/download/rosdistro$ rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///home/fang/ros2/download/rosdistro/rosdep/osx-homebrew.yaml
Hit file:///home/fang/ros2/download/rosdistro/rosdep/base.yaml
Hit file:///home/fang/ros2/download/rosdistro/rosdep/python.yaml
Hit file:///home/fang/ros2/download/rosdistro/rosdep/ruby.yaml
Hit file:///home/fang/ros2/download/rosdistro/releases/fuerte.yaml
Query rosdistro index file:///home/fang/ros2/download/rosdistro/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Skip end-of-life distro "foxy"
Skip end-of-life distro "galactic"
Skip end-of-life distro "groovy"
Add distro "humble"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Add distro "iron"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Skip end-of-life distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/fang/.ros/rosdep/sources.cache

5 设置环境变量和ros安装

在这里插入图片描述

fang@fang-inspiron-5580:~/ros2/download/rosdistro$ echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
fang@fang-inspiron-5580:~/ros2/download/rosdistro$ source ~/.bashrc
fang@fang-inspiron-5580:~/ros2/download/rosdistro$ sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version (12.4ubuntu1).
python-rosinstall is already the newest version (0.7.8-1).
python-wstool is already the newest version (0.1.17-1).
python-wstool set to manually installed.
The following NEW packages will be installed:
  python-rosinstall-generator
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 11.5 kB of archives.
After this operation, 75.8 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.ustc.edu.cn/ros/ubuntu bionic/main amd64 python-rosinstall-generator all 0.1.23-1 [11.5 kB]
Fetched 11.5 kB in 0s (96.5 kB/s)                      
Selecting previously unselected package python-rosinstall-generator.
(Reading database ... 320738 files and directories currently installed.)
Preparing to unpack .../python-rosinstall-generator_0.1.23-1_all.deb ...
Unpacking python-rosinstall-generator (0.1.23-1) ...
Setting up python-rosinstall-generator (0.1.23-1) ...

6 测试安装是否成功

1.启动RosMaster(管理Ros中各个节点的“大管家”,每次启动Ros时需要首先启动RosMaster)

roscore
fang@fang-inspiron-5580:~/ros2/download/rosdistro$ roscore
... logging to /home/fang/.ros/log/6ec2d790-fe1d-11ee-aba8-1c1bb5cdec7c/roslaunch-fang-inspiron-5580-14636.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://fang-inspiron-5580:44325/
ros_comm version 1.14.13

1.启动RosMaster(管理Ros中各个节点的“大管家”,每次启动Ros时需要首先启动RosMaster)

roscore
fang@fang-inspiron-5580:~/ros2/download/rosdistro$ roscore
... logging to /home/fang/.ros/log/6ec2d790-fe1d-11ee-aba8-1c1bb5cdec7c/roslaunch-fang-inspiron-5580-14636.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://fang-inspiron-5580:44325/
ros_comm version 1.14.13

2.启动海龟仿真器turtlesim

rosrun turtlesim turtlesim_node
fang@fang-inspiron-5580:~/ros2/download/rosdistro$ rosrun turtlesim turtlesim_node
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so"
Found metadata in lib /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqeglfs.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "eglfs"
        ]
    },
    "className": "QEglFSIntegrationPlugin",
    "debug": false,
    "version": 329989
}

3.启动海龟控制器

rosrun turtlesim turtle_teleop_key
fang@fang-inspiron-5580:~/ros2/download/rosdistro$ rosrun turtlesim turtle_teleop_key
Reading from keyboard
---------------------------
Use arrow keys to move the turtle. 'q' to quit.

使用键盘的上下左右键,可以控制小龟的移动!
在这里插入图片描述
自此,算是安装完成;

  • 14
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值