参考网址:https://blog.csdn.net/qq_40936141/article/details/86241910
记录一下安装过程
Ubuntu16.04 安装ROS Kinetic
ROS_6">一、 安装ROS
ROS_8">1、添加ROS软件源
打开命令行输入以下代码:
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://ha.pool.sks-keyservers.net:80 --recv-key 0xB01FA116
3、更新软件包
$ sudo apt-get update
ROS_Kinetic_31">4、安装ROS Kinetic
(建议安装完整包,会省去许多麻烦。命令如下:)
$ sudo apt-get install ros-kinetic-desktop-full
如果想安装其他ROS功能包,可以使用apt-cache命令搜索ros-kinetic开头的所有功能包。
$ apt-cache search ros-kinetic
如果想安装个别功能包,请使用如下命令。
$ sudo apt-get install ros-kinetic-[功能包名称]
例如:
~$ sudo apt-get install ros-kinetic-slam-gmapping
ROS_55">5、初始化ROS
- 首先需要先初始化 rosdep,具体如下:
$ sudo rosdep init
- rosdep update
$ rosdep update
ROS_68">rosdep init ROS安装问题解决方案
参考文章:https://www.guyuehome.com/12640
问题简述
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.
于是试着通过浏览器访问error中提及的网址:浏览器启动发现网址都无法打开,于是尝试以下代码,ping一下这个网址
ping raw.githubusercontent.com
发现其实通过终端ping的方式,我们是可以访问上述网页地址的
于是在安装好ROS的电脑上翻看了相关文件,发现在/etc/ros/rosdep/sources.list.d文件目录下有一个名称为20-default.list文件,通过对比发现,该文档的内容与error返回网址的内容一致,于是笔者猜测sudo rosdep init为链接上述网址,下载相关文件(20-default.list)到上述目录中,并且通过rosdep update访问该文件中的相关地址,下载相关文件。
解决方案
解决方案0x01
如果你正遇到这个问题,那么第一个解决方案就是,更换网络,你可以尝试使用你的手机热点,然后继续尝试以下指令,如果你成功了,那么你可以结束本文章的阅读,当然欢迎你继续阅读。
sudo rosdep init
rosdep update
解决方案0x02
该解决方案是针对由于以下两个无法正常访问,但可以ping通,于是修改hosts文件,加入以下两个网址的IP地址实现访问。
sudo gedit /etc/hosts
199.232.28.133 raw.githubusercontent.com
151.101.228.133 raw.github.com
修改完成后,在终端执行
sudo rosdep init
rosdep update
解决方案0x03
如果使用解决方案0x01仍然无法解决你的问题,那么你可以尝试以下步骤,此解决方案的原理是基于手动完成sudo rosdep init的步骤,然后再通过rosdep update完成整个方案的实施。 步骤一:首先打开一个终端,执行以下指令创建root并切换至root用户
sudo passwd //接着提示输入UNIX密码,输入你的用户密码即可
sudo su //或者su root 然后输入密码切换至root用户
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
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
步骤三:执行以下指令
exit //退出root用户
rosdep update
如果你成功了,那么你可以结束本文章的阅读,当然欢迎你继续阅读。 但也许你会遇到如下图所示的问题,发现20-default.list中的地址都无法连接,此时你可以将20-default.list中的内容替换如下,即将raw.githubusercontent.com替换为raw.github.com后保存文件,在终端中执行
rosdep update
如果你成功了,那么你可以结束本文章的阅读,当然欢迎你继续阅读
在这里插入图片描述
# 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.github.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 su
sudo gedit /etc/hosts
在hosts中添加以下内容并保存,在执行完后继续rosdep update
199.232.28.133 raw.githubusercontent.com
151.101.228.133 raw.github.com
但是我到这里还是不行
上述网址的来源是这里:
- 打开网址:https://site.ip138.com
输入raw.githubusercontent.com
随便挑选一个ip地址(参考来源:https://blog.csdn.net/weixin_44692299/article/details/105869229)
一般这里都成功了。
但是!!!! 我出现了禁止查询该域名的问题。
于是最后我找到这篇大佬写的:https://blog.csdn.net/leida_wt/article/details/115120940
由于近期国内Github Raw的可用IP越来越少,通过修改hosts文件解决rosdep update超时问题的方法已经不太好用,本文通过修改rosdep源码中下载资源的函数来解决这一问题。
网站https://ghproxy.com/支持github的资源代理,非常好用,我们将用此代理加速rosdep对Github Raw的访问,进而解决rosdep update超时问题。
首先定位rosdep资源下载函数。从报错信息中得知,该函数名为download_rosdep_data,位于/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py。
首先,先获取根文件的访问权限。
$ sudo nautilus
现在可以直接修改了。
我们修改这一函数,添加:
url="https://ghproxy.com/"+url
应用ghproxy的代理服务。
用同样的方法修改/usr/lib/python2.7/dist-packages/rosdistro/__init__.py
里面的DEFAULT_INDEX_URL
即将DEFAULT_INDEX_URL 进行如下替换:
DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
除此处外,下述文件中也含有github地址,分别是:
/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py 36行
/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py 72行
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py 39行
/usr/lib/python2.7/dist-packages/rosdistro/manifest_provider/github.py 68行 119行
均可通过在地址前添加https://ghproxy.com/
前缀来应用代理服务。
再次尝试执行rosdep update
,问题解决。
6、安装rosinstall
这是安装ROS各种功能包的程序。很有用的工具,务必安装。
$ sudo apt-get install python-rosinstall
ROS_249">二、搭建ROS开发环境
1、加载环境设置文件
$ source /opt/ros/kinetic/setup.bash
2、创建并初始化工作目录
新版本ROS使用名为catkin的工具来构建系统,为了使用它需要创建并初始化catkin工作目录。
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace
在所创建的catkin工作目录,使用catkin_make命令来构建。
$ cd ~/catkin_ws/
$ catkin_make
执行catkin_make时Python版本要是2.7。
$ source ~/catkin_ws/devel/setup.bash
ROS_290">三、ROS的配置
1、使用gedit打开bashrc文件
$ gedit ~/.bashrc
2、IP地址
打开后不要修改其他设置,移动到最底部添加以下内容(xxx.xxx.xxx.xxx是用户的IP地址,会根据所连网络改变,使用ifconfig查看,inet addr后面)。输入后,保存更改并退出gedit。
# Set ROS Kinetic
source /opt/ros/kinetic/setup.bash
source ~/catkin_ws/devel/setup.bash
# Set ROS Network
export ROS_HOSTNAME=xxx.xxx.xxx.xxx
export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311
# Set ROS alias command
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'
输入以下命令,使更改生效。
$ source ~/.bashrc
如果用户在一台PC上运行所有功能包,则可以指定localhost而不是特定IP。第二部分改为:
# Set ROS Network
export ROS_HOSTNAME=localhost
export ROS_MASTER_URI=http://localhost:11311
ROS_343">四、测试ROS是否安装成功
1、打开终端数入:
roscore
2、再打开一个新的终端(Termial),输入以下命令,弹出一个小乌龟窗口:
rosrun turtlesim turtlesim_node
3、再打开一个终端,用键盘控制小乌龟运动:
rosrun turtlesim turtle_teleop_key
可以看到小乌龟可以移动,键盘移动的之前要点一下最后一个终端。