上课需要在Ubuntu16.04下安装ROS,所以记录一下,以方便后来人。
ROS安装
1.配置Ubuntu仓库
Settings
— Software & Updates
— Ubuntu 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
报错,也无法正常安装。这里找到了一种不需要外网也可以正常安装的方法:
- 在网站 github.com/ros/rosdistro中将
rosdistro
整个压缩包进行下载。在Ubuntu中下载后文件将存于“下载”文件夹中。将此文件进行解压缩(extract) - 将此文件夹移至
home
下(实际路径是\home\xxx
),并将文件夹名改为rosdistro
- 修改路径
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
- 修改文件
$ 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处解释同上
- 修改文件
$ 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
- 修改文件
$ 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