当前位置: 首页 > news >正文

[具身智能-716]:ros2 pkg list 的功能以及 ros2 是如何知道自己安装了多少功能包的?

一、ros2 pkg list功能说明

作用

扫描并列出系统中所有 ROS2 功能包(package)

bash

运行

ros2 pkg list # 过滤查找某个包 ros2 pkg list | grep yahboom

配套常用命令:

bash

运行

ros2 pkg describe 包名 # 查看包信息 ros2 pkg executables 包名 # 查看包内可执行文件

二、核心问题:ROS2 依靠什么找到所有功能包?

核心机制:AMENT_PREFIX_PATH环境变量

ROS2不会全局扫描硬盘,完全依靠环境变量定位包。

1. 原理拆解

  1. 每个 ROS2 功能包编译安装后,文件夹内一定存在一个标记文件:package.xml只要一个目录包含合法package.xml,它就是一个 ROS2 package。

  2. AMENT_PREFIX_PATH保存一系列目录路径格式示例:

plaintext

/opt/ros/humble /home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install
  • /opt/ros/humble:系统预装 ROS 官方包(joy、rclcpp、rclpy 等)
  • xxx/install:你自己工作空间编译出来的自定义包
  1. 当执行ros2 pkg list: ROS2 底层 ament 工具循环遍历AMENT_PREFIX_PATH里每一条路径在每一条路径下搜寻share/*/package.xml每找到一个合法package.xml→ 识别为 1 个功能包,汇总展示。

目录标准布局(install 目录内部)

plaintext

install/yahboomcar_ctrl/ ├─ share/ │ └─ yahboomcar_ctrl/ │ └─ package.xml ←【识别功能包的核心凭证】 └─ lib/

✅ 关键点:必须存在 share/<包名>/package.xml

三、延伸:source 命令在这里扮演什么角色?

执行:

bash

运行

source install/setup.bash

这条命令本质就是:把当前工作空间的 install 路径追加到AMENT_PREFIX_PATH

举个时序例子(小车开发流程)

  1. 编译colcon build→ 文件输出到./install
  2. source install/setup.bash→ 将~/yahboomcar_ws/install写入环境变量AMENT_PREFIX_PATH
  3. ros2 pkg list扫描环境变量内路径 → 发现 yahboomcar_ctrl

❗新开终端默认没有这条路径,所以找不到自己编译的包,必须 source!

四、容易混淆的几个关键点

  1. ROS2 不扫描 src 源码目录!src下面的源码哪怕有 package.xml,如果没有编译 + source,`ros2 pkg list看不到。 它只读取install 目录,不读取源码。

  2. 环境变量叠加顺序(覆盖优先级)AMENT_PREFIX_PATH靠前路径优先

plaintext

/workspace/install:/opt/ros/humble

自定义工作空间在前 → 可以覆盖系统同名功能包(overlay 工作空间机制)

  1. 如何查看当前搜索路径(验证)

bash

运行

echo $AMENT_PREFIX_PATH

五、极简总结

  1. ros2 pkg list:遍历AMENT_PREFIX_PATH内所有路径,搜寻share/*/package.xml,输出所有识别到的功能包。
  2. ROS 识别功能包两大必要条件:
    • 路径被写入AMENT_PREFIX_PATH
    • 路径下存在合法share/包名/package.xml
  3. source setup.bash的核心作用:将工作空间 install 目录添加进AMENT_PREFIX_PATH

补充调试命令(方便你排查找不到包的问题)

bash

运行

# 查看当前包搜索路径 echo $AMENT_PREFIX_PATH # 只查看某个路径下的包(底层ament原生工具) ament_packages find /home/sunrise/xxx/install

sunrise@ubuntu:~$ echo AMENT_PREFIX_PATH
AMENT_PREFIX_PATH
sunrise@ubuntu:~$ echo $AMENT_PREFIX_PATH
/home/sunrise/workspce_test/src/install/pkg_helloworld_py:/home/sunrise/workspce_test/src/install/pkg_helloworld_cpp:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/ydlidar_ros2_driver:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/web_video_server:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/usb_cam:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/teb_local_planner:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/teb_msgs:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/sllidar_ros2:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/slam_gmapping:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/robot_localization:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/openslam_gmapping:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/costmap_converter:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/costmap_converter_msgs:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/cartographer_rviz:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/cartographer_ros:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/cartographer_ros_msgs:/home/sunrise/yahboomcar_ros2_ws/software/library_ws/install/ascamera:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_web_savmap_interfaces:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_voice_ctrl_depth:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_voice_ctrl:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_vision:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_nav:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_multi:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_msgs:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_mediapipe:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_laser:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_description:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_depth:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_ctrl:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_bringup:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_base_node:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_astra:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/yahboomcar_app_save_map:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/text_chat:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/robot_pose_publisher_ros2:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/multi_brains:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/laserscan_to_point_publisher:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/largemodel:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/interfaces:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/auto_interfaces:/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/auto_drive:/opt/ros/humble
sunrise@ubuntu:~$

http://www.jsqmd.com/news/1315023/

相关文章:

  • 深圳零基础化妆学校揭秘:开启美妆学习新旅程,助你轻松入门! - 米諾
  • 2026年衡水钢格栅生产厂家实力梳理 鑫诺帆等企业核心优势盘点 - Fan_00
  • AI Agent白手起家12: 深度解析DeepSeek火爆背后的技术突破与推理模型本质
  • 大模型时代最被低估的环节(灵感转化漏斗图首次公开):92%的AI项目死在这一步
  • 2026年8月大庆税务变更/代理记账哪家好|大庆好快记财务法务地址电话核对|营业时间与到店准备|2026年8月2日资料更新 - geo88
  • 2026 年当下,东平热门的27SiMn无缝钢管厂商竞争格局,揭秘:为什么你的管材选择错了? - 行业推荐官[官方】--
  • DataEase开源BI工具:零门槛构建企业级数据可视化平台
  • 2026 年 8 月苏州市非急救病患转运市场分析及合规转运服务商介绍 - 官方推广
  • 程序员必备1700专业词汇:构建技术沟通与高效学习的核心基石
  • 单片机毕设项目:可自定义阈值的单片机水质浊度温度监测系统设计 基于 STM32/51 单片机与 OLED 的水质实时检测报警设备开发(021601)
  • 涿州全屋定制怎么选?老王匠工厂售后体系让人安心 - 米諾
  • 链表 —— 142 环形链表Ⅱ 难点拆解!快慢指针如何找到环入口?动图解原理!
  • 【备忘】Linux服务器基础配置与常用操作指南
  • 2026下半年栾川婚纱摄影推荐:高性价比品牌蒙娜丽萨全维度解析 - 米諾
  • 2026 年 8 月合肥非急救康复转运行业调研报告及正规护送机构详解 - 官方推广
  • file box
  • 2026年8月大庆财务外包/税务筹划服务地址整理|电话与到店准备|大庆好快记财务法务有限公司推荐 - geo88
  • 2026 年 8 月天津市非急救病患转运市场分析及合规转运服务商介绍 - 官方推广
  • 2026年3C检测直线模组选型:3个关键指标帮你选对产品
  • 2026安徽安庆女生中考失利想学安稳专业?高科宠物护理起薪高越老越吃香!怎么报名?在哪报名?联系方式多少? - 最新资讯
  • 美团外卖系统架构解析:从智能调度到实时追踪的完整流程
  • 2026安徽滁州高考分数尴尬只能报差专科?工贸预科班低进高出性价比高!怎么报名?在哪报名?联系方式多少? - 最新资讯
  • 罗浩聪等8位作者论文:弥合DRAM读取干扰实验表征与器件级建模的差距!
  • 张家界私人定制旅游五日游服务网点核对:星途漫旅旅行社地址、电话与到店准备|2026年8月2日资料更新 - geo88
  • UE5开发实战避坑指南:从环境配置到性能优化的核心问题解析
  • 【紧急预警】AI部署前必做的3项边界穿透测试:错过第2项,92%项目将在6个月内遭遇不可逆信任崩塌
  • MBeautifier:MATLAB代码格式化的终极解决方案
  • Print Settings [black and white printing]
  • 2026 年 8 月成都市非急救病患转运市场分析及合规转运服务商介绍 - 官方推广
  • 2026年度深圳国际学校备考机构全景盘点:19家机构综合测评 头部梯队评分正式发布 - 互联网科技品牌测评