ubuntu16.04安装ROS Kinetic步骤及安装出现的问题解决

ubuntu16.04安装ROS Kinetic步骤及安装出现的问题解决

ROS kinetic官网:http://wiki.ros.org/kinetic/Installation/Ubuntu

1. 添加ROS软件源,设置Ubuntu的sources.lis

source.list 是ubuntu系统保存软件源地址的文件,位于/etc/apt目录下,在这一步中我们需要将ROS的软件源地址添加到该文件中,确保后续安装可以正确找到ROS相关软件的下载地址。如果需要详细了解参考以下链接:
详解Ubuntu的source.list文件
打开终端,输入如下命令,即可添加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 sh -c '. /etc/lsb-release && echo "deb http://mirror.sysu.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

易科机器人实验室:

sudo sh -c '. /etc/lsb-release && echo "deb http://ros.exbot.net/rospackage/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

2.添加密钥

sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

如果无法连接上述服务器,可以尝试hkp://pgp.mit.edu:80或者hkp://keyserver.ubuntu.com:80

3.安装ROS

1.先确保之前的软件源的修改得以更新:

sudo apt-get update

2.ROS系统非常大,包含众多的功能包、函数库和工具,所以ROS 官方为用户提供了很多版本,此处选择最为推荐的桌面完整版:

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

3.安装完可以查看可用的package:

apt-cache search ros-kinetic

4.初始化rosdep

rosdep是ROS中自带的工具,主要功能是为某些功能包安装系统依赖,同时也是某些ROS核心功能包必须用到的工具。初始化rosdep,这一步非常的关键,在你开始使用ros之前,你需要初始化rosdep,因为当你编译你的功能包,被要求运行ros中的一些核心组件的时候,rosdep可以让你轻松地安装源的系统依赖.完成以上步骤之后,需要使用以下命令进行初始化和更新:

sudo rosdep init
rosdep update

没有出错的话,直接到第5步设置环境变量。

4.1 情况一,出现一些.py文件问题:
首先打开Linux终端查看Python软连接是不是Python2, ros暂时只有Python2支持,一般ubuntu 系统默认带Python 2.7.12版本Python软件.

#终端输入
~$ python
Python 2.7.12 (default, Apr 15 2020, 17:07:12) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

如果Python版本不是Python2:

sudo rosdep init

执行这个初始化时候第一个报错问题就是Python版本问题.
提供两个软连接命令:

#Ubuntu将Python3软连接到Python
sudo ln -s /usr/bin/python3 /usr/bin/python

#Ubuntu将Python2软连接到Python
sudo ln -s /usr/bin/python2 /usr/bin/python

已经安装了更高版本Python,执行:

#终端输入
~$ python

Python 3.5.2 (default, Apr 16 2020, 17:47:17) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

出现版本号
python3.5.2 N=3.5 代表版本号下面会用到

#python这个是高版本的python软连接需要先上次,不然执行python2->python,出现python已经存在
sudo rf /usr/bin/python
#然后距离 /usr/bin/目录 这个是直接到目录去看 N
cd /usr/bin/
ls python*
#查看python后面跟着是几,N代表版本号
sudo ln -s /usr/bin/pythonN /usr/bin/python3
#然后执行下面
sudo ln -s /usr/bin/python2 /usr/bin/python

在终端输入python,输出如下就OK了

Python 2.7.12 (default, Apr 15 2020, 17:07:12) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

4.2 sudo rosdep init失败情况2:(如果出现这种情况)

报错如下:

执行命令 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.
方法1:首先看看网络是不是能连接通:github.com
如果能看下一个问题:
如果不能:打开

sudo gedit /etc/hosts
#添加以下网址
# GitHub 
140.82.113.4    github.com
199.232.28.133    githubusercontent.com
199.232.28.133    raw.githubusercontent.com
192.30.253.112    github.com
192.30.253.113    github.com
192.30.253.119    gist.github.com
192.30.255.112    github.com git 
151.101.185.194    github.global.ssl.fastly.net
151.101.88.249    github.global.ssl.fastly.net
151.101.100.133    assets-cdn.github.com
151.101.100.133    raw.githubusercontent.com
185.31.16.184    github.global.ssl.fastly.net

52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
151.101.76.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com

保存执行

sudo rosdep init

我的到这里就Ok了,
如果OK执行

rosdep update

这个更新由于网络原因可能会失败,如果失败在终端Ctrl + C
结束 继续执行rosdep update,如果不行手机开热点快些(这个现象我没弄清楚原因是什么)
原文链接:GitHub网址

方法二:
建立一个文件夹 /etc/ros/rosdep/sources.list.d
然后, /etc/ros/rosdep/sources.list.d这个目录下创建gedit 20-default.list文本,

#创建多级目录
sudo mkdir -p  /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list 

输入下面的内容到打开的gedit 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

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

也有人添加下面的内容:

# os-specific listings first
yaml https://raw.github.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx   
# generic
yaml https://raw.github.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.github.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.github.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte   
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro
index.yaml instead

4.3 rosdep update失败(如果出现这种情况)

情况1:

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
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Add distro "bouncy"
Add distro "crystal"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Add distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Add distro "lunar"
Add distro "melodic"
ERROR: error loading sources list:
	<urlopen error <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (https://raw.githubusercontent.com/ros/rosdistro/master/melodic/distribution.yaml)

这种可能是没有ssl认证,执行以下操作:

sudo apt-get install ca-certificates

情况2:

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
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Add distro "bouncy"
Add distro "crystal"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Add distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"

这里说:ERROR:unable to process source 或者什么什么timeout可能就是这种情况

这种情况,提示运行超时,你要考虑你的网速是否足够快。基本上到了这一步出错的问题都是网速的问题。有一次安装在学校连接校园网失败了,然后多执行了几次就搞定了;还有一次安装是连接的网线失败,然后看网上说用手机开热点这样网速更快,可以解决,然后试了一下,果然可以(如果开了热点不行,多试几次);写这个笔记的时候安装的这一次最惨了,开始是连接家里的网线,试了很多次没用,然后使用手机热点试了很多次也没用,然后用手机热点搞了一整天也没用,然后睡了,想着第二天早上网速可能会快点,然后第二天早上使用手机热点一次通过。总结一下就是:考虑你的网速是否足够快,最好使用手机热点,应该会更快。

5.设置环境变量

由于会频繁的使用终端输入ROS 命令,所以在使用之前还需要对环境变量进行简单的设置。默认的是使用bash终端,在bash中设置ROS环境变量:

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

6.完成安装

现在打开终端,输入roscore命令,就可以看到ROS运行起来了。
rosinstall也是ROS中的一个常用工具,可以下载和安装ROS中的功能包程序。这个工具不是比必须的,但是为了以后的方便,最好安装上:

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

7.

  1. 测试ROS安装成功
  1. 打开Termial,输入以下命令,初始化ROS环境:
roscore

在这里插入图片描述

  1. 打开新的Termial,输入以下命令,弹出一个小乌龟窗口:
rosrun turtlesim turtlesim_node

在这里插入图片描述

  1. 打开新的Termial,输入以下命令,可以在Termial中通过方向键控制小乌龟的移动:
rosrun turtlesim turtle_teleop_key

在这里插入图片描述

  1. 打开新的Termial,输入以下命令,弹出新的窗口查看ROS节点信息:
rosrun rqt_graph rqt_graph

在这里插入图片描述

8.卸载

用apt-get方式安装ROS的,卸载使用如下命令:

sudo apt-get remove ros-*

卸载成功的效果就是/opt下的ROS文件夹被删除,原先的ROS以及曾经安装在ROS中的package也没有了。

参考链接:https://blog.csdn.net/ykwjt/article/details/104524443
参考链接:https://blog.csdn.net/softimite_zifeng/article/details/78632211
参考链接:https://www.jianshu.com/p/bdbfbac69114
参考链接:https://blog.csdn.net/u013468614/article/details/102917569

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值