其他分享
首页 > 其他分享> > 【2022ROS系统melodic版本安装试错】

【2022ROS系统melodic版本安装试错】

作者:互联网

本章记录一下关于ROS系统的安装:

我们可以从各ROS讲解的视频或者书籍之中来详细了解到目前最主流的机器人框架平台ROS的相关介绍(并非是一套真正的的操作系统,而是类似于各类虚拟机或者Docker这种运行于宿主机上的一套环境框架,其主要作用是将各作动器和传感器之间的消息来进行关联嫁接,将复杂的机器通信对接变得简单(可以这么说吧应该。。),这套框架赋予了咱们的宿主机操作系统来调用接口实施接口相关操作的能力)。
<需要注意,开源的ROS框架普遍每个稳定版本官方最长维护周期是5年>;
那么现在最主要的步骤呢 就是先来安装这套通用机器框架。动手吧!
本章沿用了官方安装教程

“https://wiki.ros.org/noetic/Installation/Ubuntu”

使用操作系统为Ubuntu aarch版本。

  1. 首先我们需要创建一个用来读取相关ros软件源的文件(一个写有索引软件源地址路径的文件):
    可以顺便查看一下这条命令产生的文件。可以看见创建了一个ros-latest.list的文件,这个文件内录入了一条http://mirrors.tuna.tsinghua.edu.cn/该网址的索引信息。在这里我用的网址是国内清华大学的软件源地址。
ubuntu@ubuntu-desktop:~$ sudo sh -c 'sh /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
ubuntu@ubuntu-desktop:~$ ll /etc/apt/sources.list.d/
cuda-l4t-10-2-local.list        ros-latest.list                 visionworks-sfm-repo.list
nvidia-l4t-apt-source.list      visionworks-repo.list           visionworks-tracking-repo.list
ubuntu@ubuntu-desktop:~$ cat /etc/apt/sources.list.d/ros-latest.list
deb http://mirrors.ustc.edu.cn/ros/ubuntu bionic main
  1. 接下来添加一个能够授权软件下载的秘钥:
ubuntu@ubuntu-desktop:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116   --可以自行定义
gpg: key 5523BAEEB01FA116: public key "ROS Builder <rosbuild@ros.org>" imported
gpg: Total number processed: 1
gpg:               imported: 1
ubuntu@ubuntu-desktop:~$
  1. 再安装一个用来验证签名的公钥:
ubuntu@ubuntu-desktop:~$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
Executing: /tmp/apt-key-gpghome.Xg2moig1B0/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
gpg: key F42ED6FBAB17C654: public key "Open Robotics <info@osrfoundation.org>" imported
gpg: Total number processed: 1
gpg:               imported: 1
ubuntu@ubuntu-desktop:~$
  1. 因为是刚刚才添加的ROS软件源地址,目前ubuntu系统中还不包含ROS的软件,所以需要更新一下系统的软件包列表,通过这一次更新软件包列表,将ROS软件包一同更新到系统软件列表内:也可以
    sudo apt-get update && sudo apt-get upgrade

软件源更新

  1. 接下来安装melodic系统:

ros-melodic-full
安装Rosdep工具(ros依赖包检查工具):

ubuntu@ubuntu-desktop:~$ sudo rosdep init
[sudo] password for ubuntu:
sudo: rosdep: command not found
ubuntu@ubuntu-desktop:~$ sudo rosdep init
sudo: rosdep: command not found
  1. 在这里提示未找到rosdep 于是我在网上看到了需要安装个python-rosdep:
ubuntu@ubuntu-desktop:~$ sudo apt-get install python-rosdep
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-rosdep is already the newest version (0.21.0-1).
The following packages were automatically installed and are no longer required:
  apt-clone archdetect-deb bogl-bterm busybox-static cryptsetup-bin dpkg-repack gir1.2-timezonemap-1.0 gir1.2-xkl-1.0
  grub-common kde-window-manager kinit kio kpackagetool5 kwayland-data kwin-common kwin-data kwin-x11
  libdebian-installer4 libkdecorations2-5v5 libkdecorations2private5v5 libkf5activities5 libkf5attica5
  libkf5completion-data libkf5completion5 libkf5declarative-data libkf5declarative5 libkf5doctools5
  libkf5globalaccel-data libkf5globalaccel5 libkf5globalaccelprivate5 libkf5idletime5 libkf5jobwidgets-data
  libkf5jobwidgets5 libkf5kcmutils-data libkf5kcmutils5 libkf5kiocore5 libkf5kiontlm5 libkf5kiowidgets5
  libkf5newstuff-data libkf5newstuff5 libkf5newstuffcore5 libkf5package-data libkf5package5 libkf5plasma5
  libkf5quickaddons5 libkf5solid5 libkf5solid5-data libkf5sonnet5-data libkf5sonnetcore5 libkf5sonnetui5
  libkf5textwidgets-data libkf5textwidgets5 libkf5waylandclient5 libkf5waylandserver5 libkf5xmlgui-bin
  libkf5xmlgui-data libkf5xmlgui5 libkscreenlocker5 libkwin4-effect-builtins1 libkwineffects11 libkwinglutils11
  libkwinxrenderutils11 libqgsttools-p1 libqt5multimedia5 libqt5multimedia5-plugins libqt5multimediaquick-p5
  libqt5multimediawidgets5 libxcb-composite0 libxcb-cursor0 libxcb-damage0 os-prober python3-dbus.mainloop.pyqt5
  python3-icu python3-pam python3-pyqt5 python3-pyqt5.qtsvg python3-pyqt5.qtwebkit
  qml-module-org-kde-kquickcontrolsaddons qml-module-qtmultimedia qml-module-qtquick2 rdate tasksel tasksel-data
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

相关python-rosdep安装完了,但是rosdep init又报错提示什么The read operation timed out
读取超时。。。

ubuntu@ubuntu-desktop:~$ sudo rosdep init

ERROR: Rosdep experienced an error: ('The read operation timed out',)
Please go to the rosdep page [1] and file a bug report with the stack trace below.
[1] : http://www.ros.org/wiki/rosdep

rosdep version: 0.21.0

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 146, in rosdep_main
    exit_code = _rosdep_main(args)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 441, in _rosdep_main
    return _no_args_handler(command, parser, options, args)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 450, in _no_args_handler
    return command_handlers[command](options)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 594, in command_init
    data = download_default_sources_list()
  File "/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py", line 340, in download_default_sources_list
    f = urlopen(url, timeout=DOWNLOAD_TIMEOUT)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1248, in https_open
    context=self._context)
  File "/usr/lib/python2.7/urllib2.py", line 1208, in do_open
    r = h.getresponse(buffering=True)
  File "/usr/lib/python2.7/httplib.py", line 1178, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 452, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 408, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
  File "/usr/lib/python2.7/ssl.py", line 754, in recv
    return self.read(buflen)
  File "/usr/lib/python2.7/ssl.py", line 641, in read
    v = self._sslobj.read(len)
SSLError: ('The read operation timed out',)


ubuntu@ubuntu-desktop:~$
  1. 于是我按照这里面的报错信息登录到官方按照官方给的提示重新执行了一遍sudo apt-get install python-rosdep
    然后sudo rosdep init 就又可以了。。。真是迷糊啊(后来反应过来应该是我当时所处的环境网络不好的原因导致的):
ubuntu@ubuntu-desktop:~$ sudo rosdep init
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run

        rosdep update

ubuntu@ubuntu-desktop:~$

官方给出的init步骤

  1. 在这里官方说这个init命令只需要调用一次即可 不必过于频繁。 在下一条rosdep update时
    因为使用的时ubuntu操作系统,都会习惯在每一条命令前加上’sudo’来提权执行命令,但是这里官方提示给出的是不建议sudo提权运行此命令,说是因为提权运行该更新的话会导致某些权限的错误,所以只需要直接输入rosdep
    update即可:
ubuntu@ubuntu-desktop:~$ rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Add distro "foxy"
Add distro "galactic"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/ubuntu/.ros/rosdep/sources.cache

可以看到 已经更新了sources.cache文件(*请注意啦!请注意啦!在这一步update成功之前,其实作者已经试验了2天了。为啥呢,是开始进行update时会失败提示,告知我什么什么超时~~~当时我心里都MMP(此处省略国粹精华)。大家可以先用自己当前的浏览器一个一个加载20-default.list文件内的几个yaml链接文件看看能不能正常加载出来下面的图片内容,如果可以则执行rosdep update很小概率会出错,如果网页加载不出来~额咳。。作者劝你想办法找个网速快点的地方更新完再拿走就是喽。。。我这个是后来到公司用的企业级带宽才更新完成的)。
加载yaml配置文件

  1. 接下来添加一下环境变量在本地bashrc文件内:
ubuntu@ubuntu-desktop:~$ echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
ubuntu@ubuntu-desktop:~$ tail -n 1 .bashrc
source /opt/ros/melodic/setup.bash
ubuntu@ubuntu-desktop:~$
  1. 在我的最后一行已经添加进了环境变量 然后使用source ~/.bashrc来重新刷新生效一下bashrc文件。
    安装一下相关的python依赖包: 再初始化一下python-rosdep
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
ubuntu@ubuntu-desktop:~$ sudo apt install python-rosdep  --我这一步可以说纯属多余,因为上面就执行过了。
[sudo] password for ubuntu:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-rosdep is already the newest version (0.21.0-1).
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
ubuntu@ubuntu-desktop:~$
  1. 然后因为我安装完成后执行roscore提示没有该命令,但是有个rosco命令,需要应该是环境变量没有成功刷起来,我是直接给sudo
    reboot重启主机了。。。(没错,万问题皆可重启解决) 重启完之后就有roscore了:
ubuntu@ubuntu-desktop:~$ roscore
... logging to /home/ubuntu/.ros/log/c066cf20-856b-11ec-9508-82771950a190/roslaunch-ubuntu-desktop-8154.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://ubuntu-desktop:43551/
ros_comm version 1.14.12


SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.12

NODES

auto-starting new master
process[master]: started with pid [8164]
ROS_MASTER_URI=http://ubuntu-desktop:11311/

setting /run_id to c066cf20-856b-11ec-9508-82771950a190
process[rosout-1]: started with pid [8177]
started core service [/rosout]

好啦!作者给每一步的步骤标上了序号,大概是总共11步即可完成ros平台的安装。
接下来后面怎么小乌龟呢~请各位再自行百度即可啦!各位先安装成功所需的环境。
人工智能未来的路上你我砥砺前行!

标签:melodic,试错,sudo,list,desktop,rosdep,ubuntu,ros,2022ROS
来源: https://blog.csdn.net/Insupport/article/details/122521829