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

本文详细介绍了在Ubuntu系统上安装ROS(机器人操作系统)的步骤,包括设置软件源、添加密钥、更新包列表、安装Melodic版本,以及配置环境变量和Python依赖。遇到的问题和解决方案也一并分享。

本章记录一下关于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平台的安装。
接下来后面怎么小乌龟呢~请各位再自行百度即可啦!各位先安装成功所需的环境。
人工智能未来的路上你我砥砺前行!

### Skiplist 数据结构概述 Skiplist 是一种基于概率的数据结构,用于高效地实现有序集合的操作。它通过构建多层链表的方式,在保持数据有序的同时支持快速的插入、删除和查找操作。每层链表中的节点数量逐级减少,从而形成类似于二分查找的效果。 在 Redis 中,Skiplist 被用来实现 `zset`(sorted set),即有序集合对象的一部分[^1]。具体来说,一个 `zset` 同时包含一个字典和一个跳跃表,其中字典负责映射成员与其分数的关系,而跳跃表则维护按分数排序的成员序列。 以下是关于如何实现或使用 Skiplist 的详细介绍: --- ### Skiplist 的基本组成 #### 1. **节点定义** 每个节点通常包含以下几个字段: - 成员值(member) - 分数值(score),表示成员的权重 - 下一层指向相同位置的指针数组(level) ```c typedef struct skiplistNode { char *member; // 成员名称 double score; // 成员对应的分数 struct skiplistLevel { struct skiplistNode *forward; // 指向下一层的指针 unsigned int span; // 当前跨度(可选优化项) } level[]; } skiplistNode; ``` #### 2. **头结点与层数控制** 为了方便管理整个跳跃表,还需要定义一个头部节点以及一些元信息来记录当前的最大层数和其他属性。 ```c typedef struct skiplist { struct skiplistNode *header; // 头部节点 unsigned long length; // 总节点数 int level; // 最大层数 } skiplist; ``` --- ### Skiplist 的核心算法 #### 1. **随机化层数** 每次创建新节点时,都需要为其分配合适的层数。这一步骤决定了性能的关键特性——时间复杂度接近于 O(log n)。Redis 使用如下方法计算随机层数: ```c #include <stdlib.h> #define MAX_LEVEL 32 // 假设最大可能层数为32 int randomLevel(void) { int level = 1; while ((rand() & 0xFFFF) < (REDIS_SKIPLIST_P << 16)) { // REDIS_SKIPLIST_P 表示提升的概率,默认为0.25 level += 1; } return (level < MAX_LEVEL) ? level : MAX_LEVEL; } ``` #### 2. **插入操作** 插入过程分为两步:先定位合适的位置并更新路径上的所有前置节点;再根据随机化的层数调整各级链接关系。 ```c void insert(skiplist *sl, double score, char *member) { skiplistNode *update[MAX_LEVEL]; // 记录各层需修改的前驱节点 skiplistNode *x; x = sl->header; for (int i = sl->level - 1; i >= 0; i--) { while (x->level[i].forward && compare(x->level[i].forward, member, score) < 0) { x = x->level[i].forward; } update[i] = x; // 更新第i层的前驱节点 } int new_level = randomLevel(); // 随机决定新增节点的高度 if (new_level > sl->level) { for (int i = sl->level; i < new_level; i++) { update[i] = sl->header; } sl->level = new_level; } x = createNode(new_level, score, member); // 创建新的节点 for (int i = 0; i < new_level; i++) { x->level[i].forward = update[i]->level[i].forward; update[i]->level[i].forward = x; } sl->length++; } ``` #### 3. **查找操作** 利用跳跃表的特点,从最高层开始逐步缩小范围直至找到目标元素为止。 ```c skiplistNode* find(skiplist *sl, double score, char *member) { skiplistNode *x = sl->header; for (int i = sl->level - 1; i >= 0; i--) { while (x->level[i].forward && compare(x->level[i].forward, member, score) < 0) { x = x->level[i].forward; } } x = x->level[0].forward; if (x != NULL && equal(x, member, score)) { return x; } return NULL; } ``` #### 4. **删除操作** 删除逻辑较为简单,只需沿着之前保存的路径逐一断开对应连接即可。 ```c void remove(skiplist *sl, double score, char *member) { skiplistNode *update[MAX_LEVEL]; skiplistNode *x = sl->header; for (int i = sl->level - 1; i >= 0; i--) { while (x->level[i].forward && compare(x->level[i].forward, member, score) < 0) { x = x->level[i].forward; } update[i] = x; } x = x->level[0].forward; if (x != NULL && equal(x, member, score)) { for (int i = 0; i < sl->level; i++) { if (update[i]->level[i].forward == x) { update[i]->level[i].forward = x->level[i].forward; } } freeNode(x); sl->length--; while (sl->level > 1 && sl->header->level[sl->level - 1].forward == NULL) { sl->level--; } } } ``` --- ### Skiplist 的实际应用 除了 Redis 中的 `zset` 实现外,Skiplist 还可以广泛应用于其他场景,例如分布式系统的路由表设计、日志文件的时间戳索引等。其主要优势在于能够以较低的空间代价换取较高的访问速度。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值