[具身智能-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. 原理拆解每个 ROS2 功能包编译安装后文件夹内一定存在一个标记文件package.xml只要一个目录包含合法package.xml它就是一个 ROS2 package。AMENT_PREFIX_PATH保存一系列目录路径格式示例plaintext/opt/ros/humble /home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/install/opt/ros/humble系统预装 ROS 官方包joy、rclcpp、rclpy 等xxx/install你自己工作空间编译出来的自定义包当执行ros2 pkg list ROS2 底层 ament 工具循环遍历AMENT_PREFIX_PATH里每一条路径在每一条路径下搜寻share/*/package.xml每找到一个合法package.xml→ 识别为 1 个功能包汇总展示。目录标准布局install 目录内部plaintextinstall/yahboomcar_ctrl/ ├─ share/ │ └─ yahboomcar_ctrl/ │ └─ package.xml ←【识别功能包的核心凭证】 └─ lib/✅ 关键点必须存在 share/包名/package.xml三、延伸source 命令在这里扮演什么角色执行bash运行source install/setup.bash这条命令本质就是把当前工作空间的 install 路径追加到AMENT_PREFIX_PATH举个时序例子小车开发流程编译colcon build→ 文件输出到./installsource install/setup.bash→ 将~/yahboomcar_ws/install写入环境变量AMENT_PREFIX_PATHros2 pkg list扫描环境变量内路径 → 发现 yahboomcar_ctrl❗新开终端默认没有这条路径所以找不到自己编译的包必须 source四、容易混淆的几个关键点ROS2 不扫描 src 源码目录src下面的源码哪怕有 package.xml如果没有编译 sourceros2 pkg list看不到。 它只读取install 目录不读取源码。环境变量叠加顺序覆盖优先级AMENT_PREFIX_PATH靠前路径优先plaintext/workspace/install:/opt/ros/humble自定义工作空间在前 → 可以覆盖系统同名功能包overlay 工作空间机制如何查看当前搜索路径验证bash运行echo $AMENT_PREFIX_PATH五、极简总结ros2 pkg list遍历AMENT_PREFIX_PATH内所有路径搜寻share/*/package.xml输出所有识别到的功能包。ROS 识别功能包两大必要条件路径被写入AMENT_PREFIX_PATH路径下存在合法share/包名/package.xmlsource setup.bash的核心作用将工作空间 install 目录添加进AMENT_PREFIX_PATH。补充调试命令方便你排查找不到包的问题bash运行# 查看当前包搜索路径 echo $AMENT_PREFIX_PATH # 只查看某个路径下的包底层ament原生工具 ament_packages find /home/sunrise/xxx/installsunriseubuntu:~$ echo AMENT_PREFIX_PATHAMENT_PREFIX_PATHsunriseubuntu:~$ 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/humblesunriseubuntu:~$

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/10/1 19:32:24
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/9/30 21:32:07
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/9/30 19:41:56
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/10/1 19:32:23
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/1 19:32:35
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/9/30 21:32:11

日新闻

周新闻

月新闻