在安装ROS之前建议先将ubuntu软件和更新切换到国内的源下载速度快点,我设置为阿里云,如果是为了解决rosdep init报错,请直接跳到6.2分割线
1、添加源(alt+ctrl+t新开终端)
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
2、设置密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
3、 安装ROS完整版
sudo apt-get update
sudo apt-get install ros-kinetic-desktop-full
//安装过程中如果报错就重复几次命令试试,或者切换网络为手机热点试试
4、初始化环境变量
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
5、 安装一些必要的插件
sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
6、初始化rosdep
sudo rosdep init
rosdep update
进行到这一步如果你没报错,那么安装就完成了,你可以跳到第7步启动小海龟。
但是你肯定会报错:网站down机了
6.1 我试了几种方法都失效了(你也可以试试,但是建议直接忽略6.1跳到6.2直接解决烦恼)
6.1.1将dawn机的githubusercontent.com的IP地址添加到/etc/hosts文件中
sudo gedit /etc/hosts
//在打开的文件最后一行添加如下内容并保存退出
151.101.76.133 raw.githubusercontent.com
6.1.2githubusercontent.com有时偶尔是可以连接到的,将DOWNLOAD_TIMEOUT等待值从默认的15s调大到120s
sudo vim /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
6.1.3修改20-default.list脚本文件和init.py文件
sudo mkdir -p /etc/ros/rosdep/source.list.d
sudo vim /etc/ros/rosdep/source.list.d/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
sudo vim /usr/lib/python2.7/dist-packages/rosdistro/init.py
//将原来的DEFAULT_INDEX_URL注释换成下面的
# index information
#DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
DEFAULT_INDEX_URL = 'file:///etc/ros/rosdistro/master/index-v4.yaml'
6.2 rosdep init这个操作主要的作用就是从raw.githubusercontent.com下载文件20-default.list到 /etc/ros/rosdep/sources.list.d/下,解决办法直接手动创建要下载的20-default.list文件
//alt+ctrl+t新开终端
sudo mkdir -p /etc/ros/rosdep/source.list.d
cd /etc/ros/rosdep/source.list.d/
sudo touch 20-default.list
sudo vim /etc/ros/rosdep/source.list.d/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
6.3.1rosdep update的作用是下载https://github.com/ros/rosdistro里的yaml文件手动downloadZIP
6.3.2在downloads里将下载的压缩包右键extract here,打开downloads/rosdistro-master/rosdep将5个yaml文件移动到/etc/ros/rosdep/下与6.2创建的source.lists.d并列(图中压缩包里source.lists.d是rosdep init做的工作,这里不管它)
//在当前文件夹下右键打开终端
sudo mv base.yaml gentoo.yaml osx-homebrew.yaml python.yaml ruby.yaml /etc/ros/rosdep/
到此就相当于已经手动完成了rosdep init 和rosdep update 可以直接新开终端键入roscore看看ros已经安装好了
7、启动小海龟
// alt+ctrl+t 新开终端
roscore
// alt+ctrl+t 新开终端
rosrun turtlesim turtlesim_node
// alt+ctrl+t 新开终端
rosrun turtlesim turtle_teleop_key
//将鼠标单击进这个终端用上下左右方向键控制小海龟移动