LXR | KVM | PM | Time | Interrupt | Systems Performance | Bootup Optimization

ROS2(2):ROS2 Humble源码下载、编译、软件包说明及其架构

 ROS 2(Robot Operating System 2)是一个开源的机器人开发框架,旨在提供模块化、可扩展的机器人软件开发工具。ROS 2 的源码基于现代 C++ 和 Python,支持多种操作系统(如 Linux、Windows 和 macOS)和硬件平台。

1 环境准备

ROS 2 Humble 是 ROS 2 的一个长期支持(LTS)版本,适用于 Ubuntu 22.04 (Jammy Jellyfish)。安装必要的依赖项,使用 rosdep 安装所有依赖项。

sudo apt update
sudo apt install -y git python3-vcstool build-essential
sudo apt install -y python3-rosdep
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers"

2 下载 ROS 2 Humble 源码

使用 vcs 工具下载 ROS 2 Humble 的源码。

mkdir -p ~/ros2_humble/src
cd ~/ros2_humble
wget https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos
vcs import src < ros2.repos

ros2.repos中保存了相关源码仓库列表:

复制代码
repositories:
  ament/ament_cmake:
    type: git
    url: https://github.com/ament/ament_cmake.git
    version: humble
  ament/ament_index:
    type: git
    url: https://github.com/ament/ament_index.git
    version: humble
...
  ros2/urdf:
    type: git
    url: https://github.com/ros2/urdf.git
    version: humble
  ros2/yaml_cpp_vendor:
    type: git
    url: https://github.com/ros2/yaml_cpp_vendor.git
    version: humble
复制代码

3 编译源码

使用 colcon 工具编译源码。

cd ~/ros2_humble
colcon build --symlink-install

编译完成后:

复制代码
.
├── build--编译生成的中间文件和构建日志。
│   ├── actionlib_msgs
│   ├── action_msgs
│   ├── action_tutorials_cpp
...
│   ├── yaml_cpp_vendor
│   └── zstd_vendor
├── install--安装目录,包含编译后的可执行文件、库和资源。
│   ├── actionlib_msgs
│   ├── action_msgs
...
│   ├── yaml_cpp_vendor
│   └── zstd_vendor
├── install.txt
├── log--构建过程中的日志文件。
│   ├── build_2025-01-07_23-40-23
│   ├── COLCON_IGNORE
│   ├── latest -> latest_build
│   └── latest_build -> build_2025-01-07_23-40-23
├── ros2.repos
└── src--源码目录,包含所有 ROS 2 包的源码。
    ├── ament
    ├── eclipse-cyclonedds
    ├── eclipse-iceoryx
    ├── eProsima
    ├── ignition
    ├── osrf
    ├── ros
    ├── ros2
    ├── ros-perception
    ├── ros-planning
    ├── ros-tooling
    └── ros-visualization
复制代码

4 解读源码

复制代码
src/
├── ament                            # ROS 2 构建工具和依赖管理
│   ├── ament_cmake                  # CMake 构建系统扩展
│   ├── ament_index                  # ROS 2 包索引工具
│   ├── ament_lint                   # 代码静态检查工具
│   ├── ament_package                # 包定义和依赖管理
│   ├── google_benchmark_vendor      # Google Benchmark 性能测试库
│   ├── googletest                   # Google Test 单元测试框架
│   └── uncrustify_vendor            # 代码格式化工具
├── eclipse-cyclonedds               # Cyclone DDS 实现
│   └── cyclonedds                   # Cyclone DDS 核心库
├── eclipse-iceoryx                  # Iceoryx 零拷贝通信库
│   └── iceoryx                      # Iceoryx 核心库
├── eProsima                         # eProsima 相关库
│   ├── Fast-CDR                     # Fast CDR 序列化库
│   ├── Fast-DDS                     # Fast DDS 实现
│   └── foonathan_memory_vendor      # 内存分配器库
├── ignition                         # Ignition 相关库
│   ├── ignition_cmake2_vendor       # Ignition CMake 工具
│   └── ignition_math6_vendor        # Ignition 数学库
├── osrf                             # OSRF 工具库
│   ├── osrf_pycommon                # Python 通用工具
│   └── osrf_testing_tools_cpp       # C++ 测试工具
├── ros                              # ROS 1 兼容库和工具
│   ├── class_loader                 # 类加载器
│   ├── kdl_parser                   # KDL 解析器
│   ├── pluginlib                    # 插件库
│   ├── resource_retriever           # 资源检索工具
│   ├── robot_state_publisher        # 机器人状态发布器
│   ├── ros_environment              # ROS 环境配置
│   ├── ros_tutorials                # ROS 教程示例
│   ├── urdfdom                      # URDF 解析库
│   └── urdfdom_headers              # URDF 头文件
├── ros2                             # ROS 2 核心库和工具
│   ├── ament_cmake_ros              # ROS 2 CMake 工具
│   ├── common_interfaces            # 通用消息和服务接口
│   ├── console_bridge_vendor        # 控制台桥接库
│   ├── demos                        # ROS 2 演示示例
│   ├── eigen3_cmake_module          # Eigen3 CMake 模块
│   ├── example_interfaces           # 示例消息接口
│   ├── examples                     # ROS 2 示例代码
│   ├── geometry2                    # 几何库(TF2 等)
│   ├── launch                       # 启动系统
│   ├── launch_ros                   # ROS 2 启动工具
│   ├── libyaml_vendor               # YAML 解析库
│   ├── message_filters              # 消息过滤器
│   ├── mimick_vendor                # 函数 mocking 工具
│   ├── orocos_kdl_vendor            # KDL 运动学库
│   ├── performance_test_fixture     # 性能测试工具
│   ├── pybind11_vendor              # Python-C++ 绑定库
│   ├── python_cmake_module          # Python CMake 模块
│   ├── rcl                          # ROS 2 客户端库(C)
│   ├── rclcpp                       # ROS 2 客户端库(C++)
│   ├── rcl_interfaces               # ROS 2 接口定义
│   ├── rcl_logging                  # ROS 2 日志库
│   ├── rclpy                        # ROS 2 客户端库(Python)
│   ├── rcpputils                    # C++ 实用工具
│   ├── rcutils                      # C 实用工具
│   ├── realtime_support             # 实时支持库
│   ├── rmw                          # ROS 中间件抽象层
│   ├── rmw_connextdds               # Connext DDS 实现
│   ├── rmw_cyclonedds               # Cyclone DDS 实现
│   ├── rmw_dds_common               # DDS 通用工具
│   ├── rmw_fastrtps                 # Fast DDS 实现
│   ├── rmw_implementation           # RMW 实现工具
│   ├── ros2cli                      # ROS 2 命令行工具
│   ├── ros2cli_common_extensions    # ROS 2 CLI 扩展
│   ├── ros2_tracing                 # ROS 2 跟踪工具
│   ├── rosbag2                      # ROS 2 数据记录工具
│   ├── rosidl                       # ROS 2 接口定义语言工具
│   ├── rosidl_dds                   # ROS 2 DDS 接口支持
│   ├── rosidl_defaults              # ROS 2 默认接口
│   ├── rosidl_python                # ROS 2 Python 接口生成
│   ├── rosidl_runtime_py            # ROS 2 Python 运行时支持
│   ├── rosidl_typesupport           # ROS 2 类型支持工具
│   ├── rosidl_typesupport_fastrtps  # Fast DDS 类型支持
│   ├── ros_testing                  # ROS 2 测试工具
│   ├── rpyutils                     # Python 实用工具
│   ├── rviz                         # ROS 2 可视化工具
│   ├── spdlog_vendor                # 日志库
│   ├── sros2                        # ROS 2 安全工具
│   ├── system_tests                 # 系统测试工具
│   ├── test_interface_files         # 测试接口文件
│   ├── tinyxml2_vendor              # TinyXML2 解析库
│   ├── tinyxml_vendor               # TinyXML 解析库
│   ├── tlsf                         # 实时内存分配器
│   ├── unique_identifier_msgs       # 唯一标识符消息
│   ├── urdf                         # URDF 解析工具
│   └── yaml_cpp_vendor              # YAML C++ 解析库
├── ros-perception                   # ROS 感知相关库
│   ├── image_common                 # 图像处理工具
│   └── laser_geometry               # 激光几何库
├── ros-planning                     # ROS 规划相关库
│   └── navigation_msgs              # 导航消息定义
├── ros-tooling                      # ROS 工具库
│   ├── keyboard_handler             # 键盘输入处理
│   └── libstatistics_collector      # 统计信息收集库
└── ros-visualization                # ROS 可视化工具
    ├── interactive_markers          # 交互式标记工具
    ├── python_qt_binding            # Python-Qt 绑定
    ├── qt_gui_core                  # Qt GUI 核心库
    ├── rqt                          # RQt 框架
    ├── rqt_action                   # RQt 动作工具
    ├── rqt_bag                      # RQt 数据记录工具
    ├── rqt_console                  # RQt 控制台
    ├── rqt_graph                    # RQt 节点图工具
    ├── rqt_msg                      # RQt 消息查看器
    ├── rqt_plot                     # RQt 数据绘图工具
    ├── rqt_publisher                # RQt 消息发布工具
    ├── rqt_py_console               # RQt Python 控制台
    ├── rqt_reconfigure               # RQt 动态参数配置工具
    ├── rqt_service_caller           # RQt 服务调用工具
    ├── rqt_shell                    # RQt 命令行工具
    ├── rqt_srv                      # RQt 服务查看器
    ├── rqt_topic                    # RQt 话题工具
    └── tango_icons_vendor           # Tango 图标库
复制代码

模块按功能层次分为:依赖模块、核心模块、工具模块 和 扩展模块。

模块简要说明:

  • 依赖模块:提供底层支持(如通信、渲染、数学计算)。
  • 核心模块:构建在依赖模块之上,提供 ROS 2 的基本功能(如节点、通信、接口定义)。
  • 工具模块:依赖于核心模块和依赖模块,提供高级功能(如数据记录、安全、可视化)。
  • 扩展模块:依赖于核心模块和工具模块,提供特定领域功能(如感知、规划、开发工具)。

模块间依赖关系:依赖模块 → 核心模块 → 工具模块 → 扩展模块,逐层依赖,形成清晰的层次结构。

复制代码
+---------------------------------------------------+
|                  依赖模块                        |
+---------------------------------------------------+
|  Fast-DDS (DDS 实现)                              |
|  Cyclone DDS (DDS 实现)                           |
|  Iceoryx (零拷贝通信库)                           |
|  Ogre (3D 渲染引擎)                               |
|  Eigen3 (数学库)                                  |
|  spdlog (日志库)                                  |
|  TinyXML2 (XML 解析库)                            |
|  libyaml (YAML 解析库)                            |
|  pybind11 (Python-C++ 绑定库)                     |
|  orocos_kdl (运动学库)                            |
|  tlsf (实时内存分配器)                            |
+---------------------------------------------------+
          |           |           |           |
          v           v           v           v
+---------+-----------+-----------+-----------+-----+
|                   ROS 2 核心模块                  |
+---------------------------------------------------+
|  rclcpp (C++ 客户端库)                            |
|  rclpy (Python 客户端库)                          |
|  rcl (C 客户端库)                                 |
|  rmw (中间件抽象层)                               |
|  rosidl (接口定义语言工具)                        |
|  launch (启动系统)                                |
|  ros2cli (命令行工具)                             |
|  rcl_interfaces (ROS 2 接口定义)                  |
|  rcl_logging (日志库)                             |
|  rcpputils (C++ 实用工具)                         |
|  rcutils (C 实用工具)                             |
|  realtime_support (实时支持库)                    |
+---------------------------------------------------+
          |           |           |           |
          v           v           v           v
+---------+-----------+-----------+-----------+-----+
|                   ROS 2 工具模块                  |
+---------------------------------------------------+
|  rosbag2 (数据记录工具)                           |
|  sros2 (安全工具)                                 |
|  ros2_tracing (跟踪工具)                          |
|  rviz (可视化工具)                                |
|  rqt (GUI 工具框架)                               |
|  ros2doctor (诊断工具)                            |
|  ros2interface (接口工具)                         |
|  ros2param (参数工具)                             |
|  ros2pkg (包管理工具)                             |
+---------------------------------------------------+
          |           |           |           |
          v           v           v           v
+---------+-----------+-----------+-----------+-----+
|                  扩展模块                        |
+---------------------------------------------------+
|  ros-perception (感知相关库)                      |
|  ├── image_common (图像处理工具)                  |
|  └── laser_geometry (激光几何库)                  |
|  ros-planning (规划相关库)                        |
|  └── navigation_msgs (导航消息定义)               |
|  ros-visualization (可视化工具)                   |
|  ├── interactive_markers (交互式标记工具)         |
|  ├── python_qt_binding (Python-Qt 绑定)           |
|  ├── qt_gui_core (Qt GUI 核心库)                  |
|  ├── rqt (RQt 框架)                               |
|  ├── rqt_action (RQt 动作工具)                    |
|  ├── rqt_bag (RQt 数据记录工具)                   |
|  ├── rqt_console (RQt 控制台)                     |
|  ├── rqt_graph (RQt 节点图工具)                   |
|  ├── rqt_msg (RQt 消息查看器)                     |
|  ├── rqt_plot (RQt 数据绘图工具)                  |
|  ├── rqt_publisher (RQt 消息发布工具)             |
|  ├── rqt_py_console (RQt Python 控制台)           |
|  ├── rqt_reconfigure (RQt 动态参数配置工具)       |
|  ├── rqt_service_caller (RQt 服务调用工具)        |
|  ├── rqt_shell (RQt 命令行工具)                   |
|  ├── rqt_srv (RQt 服务查看器)                     |
|  └── rqt_topic (RQt 话题工具)                     |
|  ros-tooling (开发工具)                           |
|  ├── keyboard_handler (键盘输入处理)              |
|  └── libstatistics_collector (统计信息收集库)     |
+---------------------------------------------------+
复制代码

5 相关资料

官方文档: ROS 2 Humble Documentation
源码仓库:ROS 2 GitHub
教程:ROS 2 Tutorials

posted on   ArnoldLu  阅读(556)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-01-12 QEMU搭建虚拟化开发环境(QEMU 5.2.0)
2020-01-12 /proc/<pid>/status简要分析

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示