【精华】ROS学习(一):Ubuntu18.04安装ROS+测试ROS

  • Post author:
  • Post category:其他




Ubuntu18.04安装ROS+测试ROS


ROS官方安装说明



1 更换镜像源

这里可以换成阿里云的镜像



2 添加ROS软件源

sudo apt update
# 官方源
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'# 清华源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'# 中科大源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'

注意:更换镜像源后,需执行

sudo apt update

更新镜像源。



3 添加密钥

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



4 安装依赖

sudo apt install build-essential
sudo apt install libvtk6-jni libvtk6-java libvtk6-dev libvtk6-qt-dev libpcl-dev
sudo apt install ros-melodic-pcl-conversions ros-melodic-pcl-ros ros-melodic-perception-pcl ros-melodic-perception
sudo apt install python-rosdep 
sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool 



5 安装ROS

# 安装ROS
sudo apt install ros-melodic-desktop-full
# 初始化ROS (若报错,请参考异常问题1)
sudo rosdep init
# 更新ROS (若报错,请参考异常问题2)
rosdep update
# 设置环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc



6 测试ROS


(1) 测试小海龟

# 打开3个终端
# 终端1:激活ROS核心
roscore
# 终端2:打开小海龟视图
rosrun turtlesim turtlesim_node
# 终端3:操作小海龟(通过键盘的上下左右键)
rosrun turtlesim turtle_teleop_key

img


(2) 测试Rviz

# 打开2个终端
# 终端1:激活ROS核心
roscore
# 终端2:打开Rviz
rosrun rviz rviz

img



7 异常报错



1 异常问题1

执行

sudo rosdep init

,抛出异常。

img


问题原因

:

网址为外链,国内无法正常链接。


解决方案

:

查询网址对应IP,并添加到hosts中。


实现方式

:


IP查询工具


(1) 输入网址https://raw.githubusercontent.com进行查询

在这里插入图片描述


(2) 将ip添加到hosts中

sudo gedit /etc/hosts
127.0.0.1	localhost
127.0.1.1	leezhao-System-Product-Name
185.199.110.133 raw.githubusercontent.com  # 添加此行

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


(3) 重新执行

sudo rosdep init

在这里插入图片描述



2 异常问题2

执行

rosdep update

,抛出异常。

在这里插入图片描述


问题原因

:

境外资源被屏蔽。


解决方案

:

百度或google搜索,解决方式有多种(https://github.com/ros/rosdistro/issues/9721),可惜在 ubuntu20.04 下,集体失效。

新思路:将相关资源备份到

gitee

,修改 rosdep 源码,重新定位资源。


实现方式

:

使用

https://gitee.com/zhao-xuzuo/rosdistro

重新定位资源


(1) 修改

20-default.list

文件

sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
# os-specific listings first
# yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
yaml https://gitee.com/zhao-xuzuo/rosdistro/raw/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

yaml https://gitee.com/zhao-xuzuo/rosdistro/raw/master/rosdep/base.yaml
yaml https://gitee.com/zhao-xuzuo/rosdistro/raw/master/rosdep/python.yaml
yaml https://gitee.com/zhao-xuzuo/rosdistro/raw/master/rosdep/ruby.yaml
gbpdistro https://gitee.com/zhao-xuzuo/rosdistro/raw/master/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead


(2) 修改

__init__.py

sudo gedit /usr/lib/python2.7/dist-packages/rosdistro/__init__.py
# DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
DEFAULT_INDEX_URL = 'https://gitee.com/zhao-xuzuo/rosdistro/raw/master/index-v4.yaml'


(3) 修改

gbpdistro_support.py

sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
# FUERTE_GBPDISTRO_URL = 'https://raw.githubusercontent.com/ros/rosdistro/' \
#     'master/releases/fuerte.yaml'
FUERTE_GBPDISTRO_URL = 'https://gitee.com/zhao-xuzuo/rosdistro/raw/master/releases/fuerte.yaml'


(4) 修改

rep3.py

sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
# REP3_TARGETS_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'
REP3_TARGETS_URL = 'https://gitee.com/zhao-xuzuo/rosdistro/raw/master/releases/targets.yaml'



8 优化操作


(1) 安装terminator(方便多窗口展示)

sudo apt install terminator

在这里插入图片描述



版权声明:本文为qq_36722887原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。