Skip to content

refactor: single process#59

Merged
creeper5820 merged 6 commits into
mainfrom
refactor/single-process
Jun 10, 2026
Merged

refactor: single process#59
creeper5820 merged 6 commits into
mainfrom
refactor/single-process

Conversation

@creeper5820

@creeper5820 creeper5820 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

单进程架构重构

概述

本 PR 将项目架构从原先的“Component 与 Runtime 两进程”模式重构为“单进程多线程”模式:引入独立的 AutoAim 后台工作线程(AutoAim)并由 AutoAimComponent 主线程通过显式输入/输出接口与之交互,移除独立 runtime 进程/可执行体与对应的 launch 脚本。

核心变更

运行时与启动逻辑

  • 删除 runtime 可执行与入口:
    • 移除 src/runtime.cpp(包含 main)及其完整运行时循环逻辑。
    • 从 CMakeLists.txt 中移除 add_executable(${PROJECT_NAME}_runtime ...) 及其安装配置。
  • 移除 ROS2 launch 描述:
    • 清空 launch/launch.py 中 generate_launch_description() 的实现。

新增与线程化 AutoAim

  • 新增类与实现:
    • 新增头文件 src/kernel/auto_aim.hpp,定义 rmcs::AutoAim(PIMPL),提供线程安全的 with_context/with_command 接口及 command_updated()。
    • 新增实现 src/kernel/auto_aim.cpp:使用 std::jthread 驱动后台循环,执行图像采集、识别、3D 估计、跟踪、火控求解与可视化发布;用互斥锁保护 SystemContext 与 AutoAimState;初始化各子模块并在析构/停止时优雅退出(包括对 SIGINT 的处理与 RclcppNode::shutdown() 的调用)。
  • 交互语义:
    • AutoAim 维护受锁保护的 current_context 与 current_command,并通过 unread_command 原子标记通知命令更新。

组件侧重构

  • 重写 src/component.cpp 中 AutoAimComponent:
    • 移除原有基于 Adapter/RclcppNode/Feishu 的实现与心跳/拉取逻辑,改为直接注册和使用显式输入/输出接口(相机变换、炮管方向、robot id 以及控制/开火与角速度/角加速度等输出)。
    • 新增 before_updating()(用于未就绪输入时设置默认值)并重构 update():将输入写入 AutoAim 的上下文,仅在 auto_aim.command_updated() 为真且命令时间戳在 100ms 内时将命令写回输出;超时只清除 should_control/should_shoot 并将 target_direction 设为 NaN。

适配器移除

  • 删除适配器头文件与类:
    • src/adapter/adapter.hpp、src/adapter/deformable-infantry.hpp、src/adapter/sentry.hpp 中的 rmcs::Adapter 定义与公开方法被移除(注册 /tf 输入与 camera/barrel 查询接口被删)。

数据类型与接口调整

  • 用 Point3d 统一部分位置类型:
    • FireControl::Result::center_position:Eigen::Vector3d → Point3d(接口类型变更)。
    • Snapshot::Kinematics::center_position:Eigen::Vector3d → Point3d(公有结构字段类型变更)。
  • 预测器与 EKF 类型重整:
    • 在 predictor 的实现中引入 detail 命名空间下的别名(NormalEKF = util::EKF<11,4>、OutpostEKF = util::EKF<6,4>),并将相关工厂/后端接口的 EKF 向量类型从 Snapshot::... 切换为 detail::...。
  • 若干内部实现细节调整(对向量转换、局部初始化、返回风格等小变更),不改变外部签名的函数除前述结构字段变更外多数保持兼容。

依赖与构建变更

  • CMakeLists.txt 重构:
    • 从以全局 include_directories 为中心改为围绕新增的共享库 ${PROJECT_NAME}_utility 及现有的 kernel/module/component 使用 target_include_directories/target_link_libraries,并调整 PUBLIC/PRIVATE 传播语义。
    • find_package(OpenCV REQUIRED)(去掉了具体版本约束)并新增 find_package(pluginlib REQUIRED)。
    • 新增共享库目标 ${PROJECT_NAME}_utility(并加入 install(TARGETS ...)),并将组件/库的安装范围扩展以包含该 utility。
    • 安装目录调整:install(DIRECTORY ...) 不再包含 launch/,仅将 config/ 与 models/ 安装到 share/${PROJECT_NAME};运行时可执行不再安装到 lib/${PROJECT_NAME}。
  • 多处 Eigen 头包含被精简(Eigen/Dense → Eigen/Core 或 Eigen/Geometry),以减少头依赖范围。
  • 新增对 utility/math/kalman_filter/ekf.hpp 的直接包含以支持 EKF 类型别名。

文档与配置

  • README.md:
    • 架构说明由“进程分离”改为“单进程多线程”,部署步骤中移除了启动 runtime 的命令,新增自瞄组件的 I/O 接口表与 fast_tf 使用示例。
  • doc/streaming.md:调整模块接口示例的依赖检查注释,移除对 rmcs-runtime 特殊说明。
  • config/config.yaml:
    • 移除 localhost_develop 顶层配置项。
    • capturer.record_enable 从 false → true(启用录制)。
    • outpost_armor_thickness 从 0.02 → 0.022(参数微调)。

图像与可视化 API 调整

  • 可绘制类型调整:
    • 在 src/utility/image/drawable.hpp 中新增一组颜色常量(kRed…kPink),Text 结构从 center 改为 top_left 并新增 color 默认值;Area 的默认 color 调整为 kWhite。
    • src/utility/image/drawable.cpp 中 Canvas::draw(const Text&) 的渲染逻辑依据 top_left 与 color 进行绘制并调整字体缩放与背景描边。

影响与注意事项

  • 接口兼容性:
    • 若依赖外部代码使用 FireControl::Result::center_position 或 Snapshot::Kinematics::center_position 的类型为 Eigen::Vector3d,则需更新为 Point3d。
    • 部分内部类型和工厂函数的 EKF 向量类型名空 间发生改变,需要同步引用。
  • 构建/部署:
    • runtime 可执行与 launch 脚本被移除后,部署流程仅安装 config/ 和 models/,原有通过 runtime 启动的行为须由系统集成方以新的单进程方式适配(即通过组件与节点的组合在同一进程内运行 AutoAimComponent + AutoAim 后台线程)。
  • 代码审查重点建议:
    • 并发模型与锁策略(AutoAim 的互斥与 atomic 标志)正确性与性能影响。
    • 命令/输出超时处理语义(100ms 窗口与只清部分输出的决定)是否满足上层实时性与安全性要求。
    • 移除 Adapter 后的 TF/pose 获取路径(现在由组件直接提供输入)在集成环境下是否完整且健壮。
    • CMake 安装与依赖传播变化对 downstream 包的影响(尤其 ${PROJECT_NAME}_utility 的引入与 PUBLIC/PRIVATE 传播)。

行数与审查工作量

  • 总体行变动较大(示例:src/runtime.cpp 删除 ~234 行;src/kernel/auto_aim.cpp 新增 ~221 行;component.cpp 大幅重写等),多处属于高复杂度重构,估计代码审查工作量为高,需重点关注并发与接口兼容性变更。

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

该PR重构RMCS自瞄系统的运行时架构:移除独立的runtime可执行目标与launch配置,创建新的线程化AutoAim内核在worker线程中执行自瞄算法,同时重写AutoAimComponent以直接驱动该内核并处理ROS接口。删除中间的Adapter抽象层,统一项目中的Vector3d→Point3d类型转换,并整理Eigen头文件依赖。

Changes

AutoAim架构重构与运行时迁移

Layer / File(s) Summary
构建与安装重构
CMakeLists.txt
新增 ${PROJECT_NAME}_utility 库,调整 find_package(OpenCV/pluginlib)、改为 target_include_directories/target_link_libraries 风格并调整 PUBLIC/PRIVATE 传播;移除 ${PROJECT_NAME}_runtime 可执行目标与其安装;仅安装 config/models/share/${PROJECT_NAME}
文档与配置更新
README.md, config/config.yaml, doc/streaming.md
README 重写部署步骤与架构为单进程多线程并新增 IO 接口表与 fast_tf 示例;config.yaml 启用 record 并微调参数;streaming 示例注释改为明确的依赖检查说明。
AutoAim 公共 API 与组件接线
src/kernel/auto_aim.hpp, src/component.cpp
新增 AutoAim 并发访问模板接口(with_context/with_command 与 command_updated);AutoAimComponent 改为直接持有 AutoAim、注册输入输出,并新增 before_updating()/基于 100ms 的命令有效性判断与输出写回逻辑。
AutoAim 后台实现
src/kernel/auto_aim.cpp, src/kernel/auto_aim.hpp
新增 Impl 在 std::jthread 中运行捕获→识别→2D→3D→跟踪→火控→可视化的周期性流水线,负责模块初始化、信号处理、帧率统计和将命令写回到受互斥保护的状态并置位原子标志。
预测/EKF 与 Snapshot 类型迁移
src/module/predictor/*
引入 util::EKF 别名(NormalEKF/OutpostEKF)、将工厂/后端实现参数从 Snapshot::XVec 切换到 detail::XVec,并将 Snapshot::Kinematics.center_position 类型由 Eigen::Vector3d → Point3d。
FireControl 与求解链调整
src/kernel/fire_control.*, src/module/fire_control/*
FireControl::Result.center_position 改为 Point3d;在采样与目标求解代码路径中显式将 center_position 转换为 Eigen::Vector3d;统一多个文件的 Eigen 包含至更精简头。
移除旧 Adapter 与 launch
launch/launch.py, src/adapter/*
删除 launch 描述生成函数与旧 Adapter 头文件,中间层被移除,运行时入口与安装也随之删除(runtime.cpp 已被移除)。
绘图接口与渲染调整
src/utility/image/drawable.hpp, src/utility/image/drawable.cpp
新增一组颜色常量,Text 定位由 center→top_left 并新增 color 默认值,Canvas::draw 改为使用 top-left 基准与 text.color 前景。

Sequence Diagram

sequenceDiagram
  participant Component as AutoAimComponent (主线程)
  participant AutoAim as AutoAim (worker 线程)
  participant Modules as Capturer/Identifier/Tracker/PoseEstimator/FireControl
  Component->>AutoAim: with_context(SystemContext)
  Note over AutoAim: 写入相机变换、炮管方向、时间戳
  AutoAim->>Modules: 执行循环:抓图→识别→估计→跟踪→火控
  Modules-->>AutoAim: 识别/3D/Target → AutoAimState
  AutoAim->>AutoAim: mutex 写 current_command;atomic 设置 unread_command
  Component->>AutoAim: command_updated()
  alt 有命令且时间戳有效
    Component->>AutoAim: with_command(读取状态)
    AutoAim-->>Component: 返回 AutoAimState
    Component->>Component: 应用 yaw/pitch/射击 输出
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

🐰 我跳过旧的 runtime,在线程里忙开花,
互斥与原子保同步,IO 接口表清楚啦,
点位改成 Point3d,绘图色彩也更佳。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题『refactor: single process』准确概括了主要变更内容——从多进程架构重构为单进程多线程架构,与CMakeLists.txt、README.md、src/component.cpp、src/kernel/auto_aim.cpp等核心文件的变更保持一致。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/single-process

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
src/component.cpp

In file included from src/component.cpp:1:
src/kernel/auto_aim.hpp:3:10: fatal error: 'utility/pimpl.hpp' file not found
3 | #include "utility/pimpl.hpp"
| ^~~~~~~~~~~~~~~~~~~
1 error generated.
src/component.cpp:64:36-119:5: ERROR translating statement 'CompoundStmt'
Aborting translation of method 'rmcs::AutoAimComponent::update' in file 'src/component.cpp': "Assert_failure src/clang/cAst_utils.ml:249:53"
Uncaught Internal Error: "Assert_failure src/clang/cAst_utils.ml:249:53"
Error backtrace:
Raised at ClangFrontend__CAst_utils.get_decl_from_typ_ptr in file "src/clang/cAst_utils.ml", line 249, characters 53-65
Called from ClangFrontend__CTrans.CTrans_funct.get_destructor_decl_ref in file "src/clang/cTrans.ml", line 658, characters 12-59
Called from ClangFrontend__CTrans.CTrans_funct.destructor_calls.(fun) in file "src/clang/cTrans.ml", line 2048, characters 12-69
Called from Base__List.rev_filter_map.loop in file "src/list.ml", line 944, characters 13-17
Called fro

... [truncated 2200 characters] ...

src/clang/cFrontend_decl.ml" (inlined), line 54, characters 4-52
Called from ClangFrontend__CFrontend_decl.CFrontend_decl_funct.process_method_decl.add_method_if_create_procdesc in file "src/clang/cFrontend_decl.ml" (inlined), line 123, characters 16-158
Called from ClangFrontend__CFrontend_decl.CFrontend_decl_funct.process_method_decl in file "src/clang/cFrontend_decl.ml", line 126, characters 17-97
Called from ClangFrontend__CFrontend_decl.CFrontend_decl_funct.process_methods in file "src/clang/cFrontend_decl.ml" (inlined), line 270, characters 8-122
Called from Stdlib__List.iter in file "list.ml" (inlined), line 110, characters 12-15
Called from Stdlib__List.iter in file "list.ml" (inlined), line 108, characters 13-64
Called from Base__List0.iter in file "src/list0.ml" (inlined), line 2

src/utility/image/drawable.cpp

In file included from src/utility/image/drawable.cpp:1:
src/utility/image/drawable.hpp:2:10: fatal error: 'utility/image/image.hpp' file not found
2 | #include "utility/image/image.hpp"
| ^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
src/utility/image/drawable.cpp:21:9-16: ERROR translating statement 'ReturnStmt'
Aborting translation of method 'rmcs::details::to_scalar' in file 'src/utility/image/drawable.cpp': "Assert_failure src/clang/cAst_utils.ml:249:53"
Uncaught Internal Error: "Assert_failure src/clang/cAst_utils.ml:249:53"
Error backtrace:
Raised at ClangFrontend__CAst_utils.get_decl_from_typ_ptr in file "src/clang/cAst_utils.ml", line 249, characters 53-65
Called from ClangFrontend__CTrans.CTrans_funct.get_destructor_decl_ref in file "src/clang/cTrans.ml", line 658, characters 12-59
Called from ClangFrontend__CTrans.CTrans_funct.destructor_calls.(fun) in file "src/clang/cTrans.ml", line 2048, characters 12-69
Called from Base__List.rev_filter_map.loop in file

... [truncated 2200 characters] ...

langFrontend__CTrans.CTrans_funct.instruction_log.(fun) in file "src/clang/cTrans.ml", line 4784, characters 10-1023
Called from ClangFrontend__CTrans.CTrans_funct.instruction in file "src/clang/cTrans.ml" (inlined), line 4765, characters 38-71
Called from ClangFrontend__CTrans.CTrans_funct.exec_with_node_creation in file "src/clang/cTrans.ml" (inlined), line 104, characters 20-38
Called from ClangFrontend__CTrans.CTrans_funct.get_clang_stmt_trans in file "src/clang/cTrans.ml" (inlined), line 5395, characters 4-69
Called from ClangFrontend__CTrans.CTrans_funct.get_custom_stmt_trans in file "src/clang/cTrans.ml", line 5401, characters 8-55
Called from ClangFrontend__CTrans.CTrans_funct.exec_trans_instrs.exec_trans_instrs_rev in file "src/clang/cTrans.ml" (inlined), line 5365, characters 28-

src/kernel/auto_aim.cpp

In file included from src/kernel/auto_aim.cpp:1:
src/kernel/auto_aim.hpp:3:10: fatal error: 'utility/pimpl.hpp' file not found
3 | #include "utility/pimpl.hpp"
| ^~~~~~~~~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/54121866c5c3ad62c68aef268dcfbd93672ed1e1-a02f5f9dad849261/tmp/clang_command_.tmp.029243.txt
++Contents of '/tmp/coderabbit-infer/54121866c5c3ad62c68aef268dcfbd93672ed1e1-a02f5f9dad849261/tmp/clang_command_.tmp.029243.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-triple"
"x86_64-u

... [truncated 1120 characters] ...

ang/install/lib/clang/18/include"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-fdeprecated-macro" "-ferror-limit" "19" "-fgnuc-version=4.2.1"
"-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/a02f5f9dad849261/file.o" "-x" "c++"
"src/kernel/auto_aim.cpp" "-O0" "-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@creeper5820 creeper5820 requested a review from heyeuu June 10, 2026 00:06

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
src/component.cpp (1)

73-73: 💤 Low value

可选:记录过时指令的丢弃情况

当指令时间戳超过 100ms 时会被静默丢弃。如果指令频繁过时,可能表明性能瓶颈。建议添加周期性日志或计数器以便诊断:

if (Clock::now() - cmd.timestamp > 100ms) {
    // 可选:添加速率限制的警告日志
    // static auto last_warn = Clock::now();
    // if (Clock::now() - last_warn > 5s) {
    //     logger.warn("Discarding stale command (age: {}ms)", ...);
    //     last_warn = Clock::now();
    // }
    return;
}

这有助于在调试时发现组件更新频率不匹配的问题。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/component.cpp` at line 73, Currently stale commands are silently dropped
when Clock::now() - cmd.timestamp > 100ms; add a rate-limited diagnostic to
surface frequent drops by incrementing a counter or emitting a periodic warning.
Locate the check using Clock::now() and cmd.timestamp in the handler (the if
that returns on >100ms) and implement either a static timestamp (e.g.,
last_warn) or a counter with a time window to call logger.warn("Discarding stale
command (age: {}ms)", age) only every few seconds (or when a threshold count is
reached), or increment a metrics counter so operators can detect frequent
stale-command drops.
src/kernel/auto_aim.cpp (1)

159-159: ⚡ Quick win

建议显式转换信号处理函数

当前使用无捕获 lambda 作为信号处理器,可以隐式转换为函数指针。为提高可读性和明确意图,建议使用一元 + 运算符显式转换:

-std::signal(SIGINT, [](int) { util::set_running(false); });
+std::signal(SIGINT, +[](int) { util::set_running(false); });

或者使用 extern "C" 函数以确保 C 链接:

extern "C" void sigint_handler(int) {
    util::set_running(false);
}
std::signal(SIGINT, sigint_handler);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/kernel/auto_aim.cpp` at line 159, The current call std::signal(SIGINT,
[](int){ util::set_running(false); }) relies on implicit conversion of a
no-capture lambda to a function pointer; change it to an explicit conversion or
a C-linkage handler to make intent clear and safe: either use the unary +
operator to convert the lambda to a function pointer when passing to
std::signal, or replace the lambda with an extern "C" function (e.g.,
sigint_handler) that calls util::set_running(false) and pass that to
std::signal; update the signal registration accordingly to reference
std::signal, SIGINT, the converted lambda or sigint_handler.
src/kernel/auto_aim.hpp (1)

15-27: 💤 Low value

可选:考虑允许回调返回值

当前 with_contextwith_command 的返回类型为 auto(推导为 void),回调函数的返回值被丢弃。如果希望支持从回调中提取数据的用例,可以改为返回回调的结果:

template <typename WithFunc>
    requires std::invocable<WithFunc, SystemContext&>
auto with_context(WithFunc&& func) -> decltype(auto) {
    std::lock_guard lock(context_mutex);
    return func(current_context);
}

template <typename WithFunc>
    requires std::invocable<WithFunc, const AutoAimState&>
auto with_command(WithFunc&& func) -> decltype(auto) {
    std::lock_guard lock(command_mutex);
    return func(current_command);
}

这样调用方可以选择返回值或仅执行副作用。当前设计仅用于副作用也是合理的,此建议为可选改进。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/kernel/auto_aim.hpp` around lines 15 - 27, with_context and with_command
currently discard the callback return value (they deduce to void); change both
to return the callback result by using a trailing return type -> decltype(auto)
and returning func(...) while still holding the lock (for with_context: use
decltype(auto) return, lock context_mutex, return func(current_context); for
with_command: use decltype(auto) return, lock command_mutex, return
func(current_command)); keep the existing requires constraints
(std::invocable<WithFunc, SystemContext&> and std::invocable<WithFunc, const
AutoAimState&>) and the same mutex/variable names to locate the change.
src/module/fire_control/aim_point_chooser.hpp (1)

3-13: ⚡ Quick win

多个头文件存在同一根因:include 分组顺序不符合仓库约定。

以上位置都应统一为“本地头文件 → 标准库 → 第三方库”,并用空行分组;这是同一规范问题,建议一次性批量修正,避免后续冲突和风格漂移。

As per coding guidelines, “Header files should follow the order: local headers, standard library, third-party libraries, with blank lines separating these groups”。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/module/fire_control/aim_point_chooser.hpp` around lines 3 - 13, The
include order in aim_point_chooser.hpp violates the project's grouping
convention; reorder the `#include` lines so local headers (e.g.
"utility/pimpl.hpp", "utility/robot/armor.hpp") come first, then C++ standard
library headers (e.g. <expected>, <optional>, <span>, <string>), and finally
third‑party/externals (e.g. <eigen3/Eigen/Core>, <yaml-cpp/yaml.h>), with a
blank line between each group; apply the same grouped ordering consistently to
any other files that use these headers to avoid style drift.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/component.cpp`:
- Around line 59-60: The pitch sign is inconsistent between visualization and
control: ensure you document or align the convention by either removing the
negation in visual.update_aiming_direction(-cmd.pitch) or explicitly explaining
the reason for the flip; add a clear comment in src/component.cpp around
ctx.pitch and where ctx.yaw is passed to fire.solve describing the chosen
Z-axis/pitch sign convention, and add matching comments in
trajectory_solution.cpp (where pitch = std::atan2(target_h, target_d) produces
result->pitch) and in src/kernel/auto_aim.cpp
(visual.update_aiming_direction(cmd.yaw, -cmd.pitch)) that state how
/auto_aim/barrel_direction and aim_point/target_position.z define positive Z and
why visualization negates pitch, so future readers know whether to flip or not
and avoid semantic mismatches.

---

Nitpick comments:
In `@src/component.cpp`:
- Line 73: Currently stale commands are silently dropped when Clock::now() -
cmd.timestamp > 100ms; add a rate-limited diagnostic to surface frequent drops
by incrementing a counter or emitting a periodic warning. Locate the check using
Clock::now() and cmd.timestamp in the handler (the if that returns on >100ms)
and implement either a static timestamp (e.g., last_warn) or a counter with a
time window to call logger.warn("Discarding stale command (age: {}ms)", age)
only every few seconds (or when a threshold count is reached), or increment a
metrics counter so operators can detect frequent stale-command drops.

In `@src/kernel/auto_aim.cpp`:
- Line 159: The current call std::signal(SIGINT, [](int){
util::set_running(false); }) relies on implicit conversion of a no-capture
lambda to a function pointer; change it to an explicit conversion or a C-linkage
handler to make intent clear and safe: either use the unary + operator to
convert the lambda to a function pointer when passing to std::signal, or replace
the lambda with an extern "C" function (e.g., sigint_handler) that calls
util::set_running(false) and pass that to std::signal; update the signal
registration accordingly to reference std::signal, SIGINT, the converted lambda
or sigint_handler.

In `@src/kernel/auto_aim.hpp`:
- Around line 15-27: with_context and with_command currently discard the
callback return value (they deduce to void); change both to return the callback
result by using a trailing return type -> decltype(auto) and returning func(...)
while still holding the lock (for with_context: use decltype(auto) return, lock
context_mutex, return func(current_context); for with_command: use
decltype(auto) return, lock command_mutex, return func(current_command)); keep
the existing requires constraints (std::invocable<WithFunc, SystemContext&> and
std::invocable<WithFunc, const AutoAimState&>) and the same mutex/variable names
to locate the change.

In `@src/module/fire_control/aim_point_chooser.hpp`:
- Around line 3-13: The include order in aim_point_chooser.hpp violates the
project's grouping convention; reorder the `#include` lines so local headers (e.g.
"utility/pimpl.hpp", "utility/robot/armor.hpp") come first, then C++ standard
library headers (e.g. <expected>, <optional>, <span>, <string>), and finally
third‑party/externals (e.g. <eigen3/Eigen/Core>, <yaml-cpp/yaml.h>), with a
blank line between each group; apply the same grouped ordering consistently to
any other files that use these headers to avoid style drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 295d6e36-cdf2-4618-aca9-c902c2065afe

📥 Commits

Reviewing files that changed from the base of the PR and between 933504c and 860d01b.

📒 Files selected for processing (28)
  • CMakeLists.txt
  • README.md
  • config/config.yaml
  • doc/streaming.md
  • launch/launch.py
  • src/adapter/adapter.hpp
  • src/adapter/deformable-infantry.hpp
  • src/adapter/sentry.hpp
  • src/component.cpp
  • src/kernel/auto_aim.cpp
  • src/kernel/auto_aim.hpp
  • src/kernel/fire_control.cpp
  • src/kernel/fire_control.hpp
  • src/module/fire_control/aim_point_chooser.hpp
  • src/module/fire_control/shoot_evaluator.hpp
  • src/module/fire_control/solver/aim_point_sampling.cpp
  • src/module/fire_control/solver/aim_point_sampling.hpp
  • src/module/fire_control/solver/target_solution_solver.cpp
  • src/module/fire_control/solver/target_solution_solver.hpp
  • src/module/fire_control/trajectory_solution.hpp
  • src/module/predictor/outpost/snapshot.cpp
  • src/module/predictor/outpost/snapshot.hpp
  • src/module/predictor/regular/snapshot.cpp
  • src/module/predictor/regular/snapshot.hpp
  • src/module/predictor/snapshot.cpp
  • src/module/predictor/snapshot.hpp
  • src/runtime.cpp
  • src/utility/math/solve_armors.cpp
💤 Files with no reviewable changes (6)
  • src/adapter/sentry.hpp
  • launch/launch.py
  • src/runtime.cpp
  • src/adapter/deformable-infantry.hpp
  • src/adapter/adapter.hpp
  • CMakeLists.txt

Comment thread src/component.cpp
Comment thread src/component.cpp Outdated
Comment thread src/component.cpp
Comment thread config/config.yaml
heyeuu
heyeuu previously approved these changes Jun 10, 2026

@heyeuu heyeuu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CMakeLists.txt`:
- Line 35: 在 CMakeLists.txt 中为目标 ${PROJECT_NAME}_component 明确添加 pluginlib
的传递依赖:因为 src/component.cpp 引入了 <pluginlib/class_list_macros.hpp> 并使用
PLUGINLIB_EXPORT_CLASS(...),所以在定义 ${PROJECT_NAME}_component 的地方(当前只设置了
${rmcs_description_INCLUDE_DIRS}/${rmcs_executor_INCLUDE_DIRS}/${rmcs_executor_LIBRARIES})需要把
pluginlib 的 include 和链接依赖补上;修改方法为对该 target 使用 ament_target_dependencies(...
pluginlib) 或在 target_include_directories/target_link_libraries 中加入
${pluginlib_INCLUDE_DIRS}/${pluginlib_LIBRARIES} 以确保编译和链接时可见 pluginlib 符号。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1b0b8a36-69a5-4fa2-88e4-6e08f16bd24e

📥 Commits

Reviewing files that changed from the base of the PR and between 860d01b and 5412186.

📒 Files selected for processing (5)
  • CMakeLists.txt
  • src/component.cpp
  • src/kernel/auto_aim.cpp
  • src/utility/image/drawable.cpp
  • src/utility/image/drawable.hpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/component.cpp
  • src/kernel/auto_aim.cpp

Comment thread CMakeLists.txt
@creeper5820 creeper5820 merged commit c001167 into main Jun 10, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in RMCS Auto Aim V2 Jun 10, 2026
@creeper5820 creeper5820 deleted the refactor/single-process branch June 10, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants