Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file
CONTRIBUTING
Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file
CONTRIBUTING
Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file
CONTRIBUTING
Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file
CONTRIBUTING
Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file
CONTRIBUTING
Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file
CONTRIBUTING
Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file
CONTRIBUTING
Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file
CONTRIBUTING
Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file
CONTRIBUTING
Repository Summary
| Description | |
| Checkout URI | https://github.com/homalozoa/ros2_for_beginners_code.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2026-07-14 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
| Name | Version |
|---|---|
| ch2_node_cpp | 0.0.1 |
| ch2_node_py | 0.0.1 |
| ch2_pkg_cpp | 0.0.1 |
| ch2_pkg_py | 0.0.1 |
| ch3_component | 0.0.1 |
| ch3_launch | 0.0.1 |
| ch3_logging_cpp | 0.0.1 |
| ch3_logging_py | 0.0.1 |
| ch3_param_bringup | 0.0.1 |
| ch3_param_cpp | 0.0.1 |
| ch3_param_py | 0.0.1 |
| ch3_plugin_alpha | 0.0.1 |
| ch3_plugin_base | 0.0.1 |
| ch3_plugin_beta | 0.0.1 |
| ch3_plugin_main | 0.0.1 |
| ch4_service_cpp | 0.0.1 |
| ch4_service_py | 0.0.1 |
| ch4_topic_cpp | 0.0.1 |
| ch4_topic_py | 0.0.1 |
| ch5_action_cpp | 0.0.1 |
| ch5_action_interfaces | 0.0.1 |
| ch5_action_py | 0.0.1 |
| ch5_v_interfaces | 0.0.1 |
| ch5_tf2_cpp | 0.0.1 |
| ch6_bag_cpp | 0.0.1 |
| ch6_debug_cpp | 0.0.1 |
| ch6_unittest_cpp | 0.0.1 |
| ch7_diagnostics_cpp | 0.0.1 |
| ch7_msgfltr_cpp | 0.0.1 |
| ch7_msgfltr_py | 0.0.1 |
README
ros2_for_beginners_code

一、简介
本项目囊括了书籍《ROS 2机器人编程实战——基于现代C++和Python 3》的各章节配套代码,意在将书中例程完整呈现,以便帮助读者更好地理解书中内容。
二、开发环境配置
本仓库以 GitHub Actions 的完整构建和测试结果作为版本支持依据,目前支持以下组合:
| ROS 2 版本 | 推荐 Ubuntu 版本 | 官方生命周期 | 本仓库 CI |
|---|---|---|---|
| Humble | Jammy 22.04 | LTS,支持至 2027 年 5 月 | ✅ |
| Jazzy | Noble 24.04 | LTS,支持至 2029 年 5 月 | ✅ |
| Lyrical | Resolute 26.04 | LTS,支持至 2031 年 5 月 | ✅ |
| Rolling | Resolute 26.04 | 持续开发版本 | ✅ |
具体构建矩阵见 .github/workflows/ci.yml。Rolling 会随 ROS 2
上游持续变化,CI 当前使用 ros2-testing 软件源验证最新可用软件包,不建议将其作为长期稳定的生产环境基线。
ROS 2 Foxy 已于 2023 年 6 月停止官方维护,本仓库不再为 Foxy 提供持续集成和兼容性保证。 历史代码仍可用于学习,但新项目建议选择上表中的受支持 LTS 版本。
1. 安装 ROS 2
建议在对应的 Ubuntu 版本上使用官方二进制软件包安装 ROS 2:
- Humble / Ubuntu Jammy 安装说明
- Jazzy / Ubuntu Noble 安装说明
- Lyrical / Ubuntu Resolute 安装说明
- Rolling / Ubuntu Resolute 安装说明
Windows、macOS 及源码安装方式请从对应版本的官方安装页面进入;本仓库当前只对上表中的 Ubuntu 组合提供自动化构建保证。此部分可结合书中 1.1.3~1.1.4 节完成。
2. 构建与测试本仓库
安装 ROS 2、ros-dev-tools 和 colcon 后,可创建独立工作空间进行构建:
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p ~/ros2_ws/src
git clone https://github.com/homalozoa/ros2_for_beginners_code.git \
~/ros2_ws/src/ros2_for_beginners_code
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src --rosdistro "$ROS_DISTRO" -r -y
colcon build --symlink-install
colcon test
colcon test-result --verbose
每次打开新终端时,都需要先加载对应 ROS 2 环境;构建完成后再执行
source ~/ros2_ws/install/setup.bash 即可运行本仓库中的节点和示例。
三、示例代码简介
1.功能包的构建与测试
本节对应书中2.1.2节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
通过ros2 pkg生成功能包ch2_pkg_cpp以及ch2_pkg_py的过程
-
如何配置并修改package.xml、setup.py及CmakeLists.txt
-
尝试merge以及symlink两种构建指令,比较构建结果的不同,以及构建指令与test指令的关系
ros2_for_beginners_code
|
|-ch2
|
|-package
|-ch2_pkg_cpp
|-ch2_pkg_py
2.节点与节点执行器
本节对应书中2.2.1节的内容,在此项目中目录结构如下图,学习的关键点为以下几点:
-
节点的创建方法
-
节点与线程、进程的关系
-
节点执行器的配置,包括线程配置和回调操作配置
-
节点的package.xml及CmakeLists.txt配置
-
节点的简单调试
```
File truncated at 100 lines see the full file