在Ubuntu16/18/20系统中,安装对应版本的ROS软件,注意记录和分析所遇到的各式问题和解决措施。
熟悉ROS基本命令,并运行小海龟demo例子,通过键盘控制小海龟运动。同时用话题查看器查看两个node之间的消息传递;
用C++或python写一个程序,控制小海龟走一个圆形。
一、ROS的介绍
ROS (Robot Operating System, 机器人操作系统) 提供一系列程序库和工具以帮助软件开发者创建机器人应用软件。它提供了硬件抽象、设备驱动、库函数、可视化、消息传递和软件包管理等诸多功能。
二、ROS软件安装
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 keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
3.安装ROS
sudo apt update
sudo apt-get install ros-melodic-desktop-full
4.初始化rosdep
sudo rosdep init
rosdep update
(1)使用sudo rodep init出现sudo rosdep:找不到命令提示的错误
解决:sudo apt install python-rosdep
(2)出现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.的错误
解决方法:
cd /etc
sudo gedit hosts
在文本后面添加(ip是通过https://site.ip138.com进行输入raw.githubusercontent.com查询获取得到,任意选择一个)
ip raw.githubusercontent.com
不过这里存在网络问题,如果使用的是移动网通过上面方法也无法解决问题,最终用电信网解决。
(3)出现ERROR: error loading sources list: <urlopen error <urlopen error timed out
本地安装的方式
①下载相关文件
②解压文件
unzip rosdistro-master.zip -d rosdistro
③修改20-default.list文件
sudo nano /etc/ros/rosdep/sources.list.d/20-default.list
修改如下:
#os-specific listings first
yaml file:///home/lyy/ros/rosdistro/rosdep/osx-homebrew.yaml osx
#generic
yaml file:///home/lyy/ros/rosdistro/rosdep/base.yaml
yaml file:///home/lyy/ros/rosdistro/rosdep/python.yaml
yaml file:///home/lyy/ros/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/lyy/ros/rosdistro/releases/fuerte.yaml fuerte
#newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
④修改source_list.py文件
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
将原DEFAULT_SOURCES_LIST_URL一行注释,在其后添加如下内容
DEFAULT_SOURCES_LIST_URL = 'file:///home/lyy/ros/rosdistro/rosdep/sources.list.d/20-default.list'
⑤修改rep3.py文件
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
将原REP3_TARGETS_URL一行注释,在其后添加如下内容:
REP3_TARGETS_URL = 'file:///home/lyy/ros/rosdistro/releases/targets.yaml'
⑥修改__init__.py文件
sudo gedit /usr/lib/python2.7/dist-packages/rosdistro/__init__.py
将原DEFAULT_INDEX_URL一行注释,在其后添加如下内容
DEFAULT_INDEX_URL = 'file:///home/lyy/ros/rosdistro/index-v4.yaml'
修改完成后:rosdep update
5.设置环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
6.安装rosinstall
sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essentia
三、小海龟
1.启动ROS Master:roscore
2.启动小海龟仿真器:rosrun turtlesim turtlesim_node
3.启动海龟控制节点:rosrun turtlesim turtle_teleop_key
PS:每个步骤分明需要打开一个终端,小海龟的运行路径是在最后一个终端上,通过上下左右按键控制的。
四.总结
安装ROS的整个过程,首先需要选择对应版本的ROS,接着就是在网络问题上的处理。