Ubuntu16.04系统下ROS的安装

上课需要在Ubuntu16.04下安装ROS,所以记录一下,以方便后来人。

ROS安装

1.配置Ubuntu仓库

SettingsSoftware & UpdatesUbuntu Software中,选中以允许“restricted”、“universe”、“multiverse”三项。

2.配置国内源

在终端中输入:(注:终端中的粘贴为Ctrl + Shift + V

$ 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'

3.配置key

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

4.更新

$ sudo apt-get update

5.安装桌面完整版

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

6.初始化rosdep

$ sudo rosdep init
$ rosdep update

需要特别注意:
在执行sudo rosdep init后,如果执行成功,将出现文本提示输入继续执行rosdep update,如果没有此提示,报各种错,则无法正常安装;同理,rosdep update报错,也无法正常安装。这里找到了一种不需要外网也可以正常安装的方法:

  1. 在网站 github.com/ros/rosdistro中将rosdistro整个压缩包进行下载。在Ubuntu中下载后文件将存于“下载”文件夹中。将此文件进行解压缩(extract)
  2. 将此文件夹移至home下(实际路径是\home\xxx),并将文件夹名改为rosdistro
  3. 修改路径rosdistro/rosdep/source.list.d/下的文件20-default.list,修改为:
    注: xxx为自己电脑的名字
# os-specific listings first
yaml file:///home/xxx/rosdistro/rosdep/osx-homebrew.yaml osx

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

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
  1. 修改文件
$ cd /usr/lib/python2.7/dist-packages/rosdep2
$ sudo gedit sources_list.py

将文件中的DEFAULT_SOURCES_LIST_URL一处,修改为:

# default file to download with 'init' command in order to bootstrap
# rosdep
DEFAULT_SOURCES_LIST_URL = 'file:///home/xxx/rosdistro/rosdep/sources.list.d/20-default.list'

# seconds to wait before aborting download of rosdep data

修改完毕,先保存再关闭,xxx处解释同上

  1. 修改文件
$ sudo gedit rep3.py

文件中REP3_TARGETS_URL修改为:

# location of targets file for processing gbpdistro files
REP3_TARGETS_URL = 'file:///home/xxx/rosdistro/releases/targets.yaml'

# seconds to wait before aborting download of gbpdistro data
  1. 修改文件
$ cd /usr/lib/python2.7/dist-packages/rosdistro
$ sudo gedit __init.py__

文件中DEFAULT_INDEX_URL修改为:

# index information

DEFAULT_INDEX_URL = 'file:///home/xxx/rosdistro/index-v4.yaml'

def get_index_url():

进行完如上步骤后,再运行sudo rosdep init,就可以顺利通过了
另需注意: 如果修改文件之前sudo rosdep init成功,而只是rosdep update失败时,首先要运行如下代码:

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

然后重新进行sudo rosdep init

7.环境设置

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

8.最后的安装

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

到这里就完成啦!

ROS安装测试

打开一个终端:

$ roscore

打开一个新终端:

$ rosrun turtlesim turtlesim_node

将出现一只小乌龟
打开另一个新终端:

$ rosrun turtlesim turtle_teleop_key

注:此终端窗口需要置顶才能用键盘的上下左右控制小乌龟
注: 结束任务按键为Ctrl + C,尽量不要强制关闭终端。

创建工作空间

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/
$ catkin_make
$ source devel/setup.bash

$ echo "source catkin_ws/devel/setup.bash" >> ~/.bashrc
$ source ~/.bashrc

本文主要参考链接:
https://blog.csdn.net/nanianwochengshui/article/details/105702188

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值