使用 rosdep 管理 ROS 2 依赖项

2023-11-06 01:52
文章标签 使用 依赖 管理 ros rosdep

本文主要是介绍使用 rosdep 管理 ROS 2 依赖项,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

系列文章目录


文章目录

  • 系列文章目录
  • 前言 清华源镜像使用
  • 一、什么是 `rosdep`?
  • 二、关于 `package.xml` 文件的一些小知识
  • 三、`rosdep` 是如何工作的?
  • 四、如何知道在 `package.xml` 中输入哪些 `key` ?
  • 五、如何使用 rosdep 工具?
    • 5.1 rosdep 安装
    • 5.2 rosdep 使用
  • 六、rosdep 说明
  • `如果觉得内容不错,请点赞、收藏、关注`


前言 清华源镜像使用

本教程将介绍如何使用 rosdep 管理外部依赖关系。

目前,rosdep 只能在 Linux 和 macOS 上运行,不支持 Windows。长期计划是在
https://github.com/ros-infrastructure/rosdep 中添加对 Windows 的支持。

在 rosdep 使用流程中,我们会有如下两个步骤

sudo rosdep init
rosdep update

我们替换为以下步骤

# 手动模拟 rosdep init
sudo mkdir -p /etc/ros/rosdep/sources.list.d/
sudo curl -o /etc/ros/rosdep/sources.list.d/20-default.list https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
# 为 rosdep update 换源
export ROSDISTRO_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml
rosdep update# 每次 rosdep update 之前,均需要增加该环境变量
# 为了持久化该设定,可以将其写入 .bashrc 中,例如
echo 'export ROSDISTRO_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml' >> ~/.bashrc

一、什么是 rosdep

rosdep 是一种依赖性管理工具,可以处理软件包和外部库。rosdep 本身并不是一个软件包管理器;它是一个元软件包管理器,利用自身对系统和依赖关系的了解,在特定平台上找到合适的软件包进行安装。实际安装是通过系统软件包管理器(如 Debian/Ubuntu 上的 apt、Fedora/RHEL 上的 dnf 等)完成的。

它通常在构建工作区之前被调用,用于安装工作区中的依赖包。

它可以在单个软件包或软件包目录(如工作区)上运行。

从名字上看,rosdep 是为 ROS 设计的,但其实它与 ROS 是半对立的。你可以将它作为一个独立的 Python 软件包安装,在非
ROS 软件项目中使用这个强大的工具。成功运行 rosdep 依赖于可用的 rosdep 密钥,只需几条简单的命令就能从公共 git
仓库下载。

二、关于 package.xml 文件的一些小知识

package.xml 是软件中的一个文件,rosdep 会在其中找到一系列依赖项。package.xml 中的依赖关系列表必须完整、正确,这样所有工具才能确定软件包的依赖关系。缺少或不正确的依赖关系会导致用户无法使用软件包,工作区中的软件包被无序构建,以及软件包无法发布。

package.xml 文件中的依赖关系通常被称为 “rosdep keys”。这些依赖关系由软件包的创建者手动填充到 package.xml 文件中,并应详尽无遗地列出软件包所需的所有非构建库和软件包。

它们用以下标记表示(完整规范请参见 REP-149):

  1. <depend>
    这些是软件包在构建和运行时都应提供的依赖项。对于 C++ 软件包,毫无疑问,请使用此标记。纯 Python 软件包通常没有联编阶段,因此不应使用此标记,而应使用 <exec_depend>
  2. <build_depend>
    如果只在构建软件包时而不是在执行时使用特定的依赖关系,可以使用 <build_depend> 标签。
    有了这种依赖关系,软件包的已安装二进制文件就不需要安装该特定软件包了。
    不过,如果你的软件包导出的头文件包含了该依赖的头文件,那就会产生问题。在这种情况下,您还需要使用 <build_export_depend>
  3. <build_export_depend>
    如果您导出的头文件包含依赖包中的头文件,那么其他 <build_depend> 依赖于您的软件包也会需要该头文件。这主要适用于头文件和 CMake 配置文件。由您导出的库引用的库包通常应指定 ,因为在执行时也需要它们。
  4. <exec_depend>
    该标签声明了运行软件包时所需的共享库、可执行文件、Python 模块、启动脚本和其他文件的依赖关系。
  5. <test_depend>
    此标记声明仅测试需要的依赖项。此处的依赖项不应与 <build_depend><exec_depend><depend> 指定的键重复。

三、rosdep 是如何工作的?

rosdep 会检查其路径中的 package.xml 文件或特定软件包,并查找其中存储的 rosdep 密钥。然后,这些密钥会与中央索引相互参照,在各种软件包管理器中找到相应的 ROS 软件包或软件库。最后,一旦找到软件包,它们就会被安装并准备就绪!

rosdep 的工作方式是在本地计算机上检索中央索引,这样它就不必在每次运行时访问网络(在 Debian/Ubuntu 上,其配置存储在 /etc/ros/rosdep/sources.list.d/20-default.list 中)。

中央索引被称为 rosdistro,可以在网上找到。我们将在下一节进一步探讨。

四、如何知道在 package.xml 中输入哪些 key

问得好,很高兴你这么问!

如果您想在软件包中依赖的软件包是基于 ROS 的,并且已经发布到 ROS 生态系统 1 中,例如 nav2_bt_navigator,那么您只需使用软件包的名称即可。你可以在 https://github.com/ros/rosdistro 的 <distro>/distribution.yaml (例如 humble/distribution.yaml)中找到所有已发布的 ROS 软件包的列表。

如果你想依赖一个非 ROS 软件包(通常称为 “系统依赖”),就需要找到特定库的密钥。一般来说,有两个文件值得关注:

  • rosdep/base.yaml 包含 apt 系统依赖项

  • rosdep/python.yaml 包含 Python 依赖项

要查找密钥,请在这些文件中搜索您的库并找到名称。这就是要放入 package.xml 文件的密钥。

例如,假设一个软件包依赖于 doxygen,因为它是一个注重文档质量的伟大软件(提示提示)。我们会在 rosdep/base.yaml 中搜索 doxygen,然后找到

doxygen:arch: [doxygen]debian: [doxygen]fedora: [doxygen]freebsd: [doxygen]gentoo: [app-doc/doxygen]macports: [doxygen]nixos: [doxygen]openembedded: [doxygen@meta-oe]opensuse: [doxygen]rhel: [doxygen]ubuntu: [doxygen]

这意味着我们的 rosdep 密钥是 doxygen,它可以在不同操作系统的软件包管理器中解析为不同的名称进行安装。

五、如何使用 rosdep 工具?

5.1 rosdep 安装

如果将 rosdep 与 ROS 结合使用,它将与 ROS 发行版一起打包,非常方便。这是获取 rosdep 的推荐方法,你可以用以下方法安装它:

apt-get install python3-rosdep

在 Debian 和 Ubuntu 上,还有一个类似的软件包,名为 python3-rosdep2。如果已安装了该软件包,请确保在安装
python3-rosdep 前将其删除。

如果您在 ROS 之外使用 rosdep,系统软件包可能不可用。在这种情况下,您可以直接从 https://pypi.org 安装:

pip install rosdep

5.2 rosdep 使用

既然我们已经对 rosdep、package.xml 和 rosdistro 有了一定的了解,那么我们就可以使用该工具本身了!首先,如果这是第一次使用 rosdep,必须通过以下方式对其进行初始化:

sudo rosdep init
rosdep update

这将初始化 rosdep,而 update 将更新本地缓存的 rosdistro 索引。偶尔更新一下 rosdep 以获取最新索引是个好主意。

最后,我们可以运行 rosdep install 安装依赖包。通常情况下,我们会在一个包含许多软件包的工作区中一次性调用该程序,以安装所有依赖包。如果在工作区的根目录下,src 目录包含源代码,则会出现如下调用。

rosdep install --from-paths src -y --ignore-src
rosdep install -i --from-path src --rosdistro iron -y

如下:

  • –from-paths src 指定了检查 package.xml 文件的路径,以便为其解析密钥。

  • -y表示对软件包管理器的所有提示默认为 “是”,安装时无需提示

  • –ignore-src "表示如果软件包本身也在工作区中,即使存在 rosdep 密钥,也会忽略安装依赖包。

还有其他参数和选项可用。使用 rosdep -h 查看这些参数和选项,或访问 http://docs.ros.org/en/independent/api/rosdep/html/ 查看更完整的 rosdep 文档。

六、rosdep 说明

Usage: rosdep [options] <command> <args>Commands:rosdep check <stacks-and-packages>...check if the dependencies of package(s) have been met.rosdep install <stacks-and-packages>...download and install the dependencies of a given package or packages.rosdep dbgenerate the dependency database and print it to the console.rosdep initinitialize rosdep sources in /etc/ros/rosdep.  May require sudo.rosdep keys <stacks-and-packages>...list the rosdep keys that the packages depend on.rosdep resolve <rosdeps>resolve <rosdeps> to system dependenciesrosdep updateupdate the local rosdep database based on the rosdep sources.rosdep what-needs <rosdeps>...print a list of packages that declare a rosdep on (at leastone of) <rosdeps>rosdep where-defined <rosdeps>...print a list of yaml files that declare a rosdep on (at leastone of) <rosdeps>rosdep fix-permissionsRecursively change the permissions of the user's ros home directory.May require sudo.  Can be useful to fix permissions after calling"rosdep update" with sudo accidentally.Options:-h, --help            show this help message and exit--os=OS_NAME:OS_VERSIONOverride OS name and version (colon-separated), e.g.ubuntu:lucid-c SOURCES_CACHE_DIR, --sources-cache-dir=SOURCES_CACHE_DIROverride /home/kuanli/.ros/rosdep/sources.cache-v, --verbose         verbose display--version             print just the rosdep version, then exit--all-versions        print rosdep version and version of installers, thenexit--reinstall           (re)install all dependencies, even if alreadyinstalled-y, --default-yes     Tell the package manager to default to y or fail wheninstalling-s, --simulate        Simulate install-r                    Continue installing despite errors.-q                    Quiet. Suppress output except for errors.-a, --all             select all packages-n                    Do not consider implicit/recursive dependencies.  Onlyvalid with 'keys', 'check', and 'install' commands.-i, --ignore-packages-from-source, --ignore-srcAffects the 'check', 'install', and 'keys' verbs. Ifspecified then rosdep will ignore keys that are foundto be catkin or ament packages anywhere in theROS_PACKAGE_PATH, AMENT_PREFIX_PATH or in any of thedirectories given by the --from-paths option.--skip-keys=SKIP_KEYSAffects the 'check' and 'install' verbs. The specifiedrosdep keys will be ignored, i.e. not resolved and notinstalled. The option can be supplied multiple times.A space separated list of rosdep keys can also bepassed as a string. A more permanent solution tolocally ignore a rosdep key is creating a local rosdeprule with an empty list of packages (include it in/etc/ros/rosdep/sources.list.d/ before the defaults).--filter-for-installers=FILTER_FOR_INSTALLERSAffects the 'db' verb. If supplied, the output of the'db' command is filtered to only list packages whoseinstaller is in the provided list. The option can besupplied multiple times. A space separated list ofinstallers can also be passed as a string. Example:`--filter-for-installers "apt pip"`--from-paths          Affects the 'check', 'keys', and 'install' verbs. Ifspecified the arguments to those verbs will beconsidered paths to be searched, acting on all catkinpackages found there in.--rosdistro=ROS_DISTROExplicitly sets the ROS distro to use, overriding thenormal method of detecting the ROS distro using theROS_DISTRO environment variable. When used with the'update' verb, only the specified distro will beupdated.--as-root=INSTALLER_KEY:<bool>Override whether sudo is used for a specificinstaller, e.g. '--as-root pip:false' or '--as-root"pip:no homebrew:yes"'. Can be specified multipletimes.--include-eol-distrosAffects the 'update' verb. If specified end-of-lifedistros are being fetched too.-t DEPENDENCY_TYPES, --dependency-types=DEPENDENCY_TYPESDependency types to install, can be given multipletimes. Choose from {'exec', 'buildtool','buildtool_export', 'test', 'build_export', 'doc','build'}. Default: all except doc.

如果觉得内容不错,请点赞、收藏、关注

这篇关于使用 rosdep 管理 ROS 2 依赖项的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/353811

相关文章

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

每天认识几个maven依赖(ActiveMQ+activemq-jaxb+activesoap+activespace+adarwin)

八、ActiveMQ 1、是什么? ActiveMQ 是一个开源的消息中间件(Message Broker),由 Apache 软件基金会开发和维护。它实现了 Java 消息服务(Java Message Service, JMS)规范,并支持多种消息传递协议,包括 AMQP、MQTT 和 OpenWire 等。 2、有什么用? 可靠性:ActiveMQ 提供了消息持久性和事务支持,确保消

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]

软考系统规划与管理师考试证书含金量高吗?

2024年软考系统规划与管理师考试报名时间节点: 报名时间:2024年上半年软考将于3月中旬陆续开始报名 考试时间:上半年5月25日到28日,下半年11月9日到12日 分数线:所有科目成绩均须达到45分以上(包括45分)方可通过考试 成绩查询:可在“中国计算机技术职业资格网”上查询软考成绩 出成绩时间:预计在11月左右 证书领取时间:一般在考试成绩公布后3~4个月,各地领取时间有所不同