Skip to content

refactor: update AutoAimState with center position, adapt Adapter and…#44

Merged
creeper5820 merged 1 commit intomainfrom
fix/fix-default-config
May 3, 2026
Merged

refactor: update AutoAimState with center position, adapt Adapter and…#44
creeper5820 merged 1 commit intomainfrom
fix/fix-default-config

Conversation

@heyeuu
Copy link
Copy Markdown
Member

@heyeuu heyeuu commented May 3, 2026

… sync component.cpp

PR 摘要

概述

本PR重构了自动瞄准系统的核心状态管理结构,增加了机器人中心位置追踪功能,并相应更新了适配器和组件的实现。主要涉及配置参数调整、新增Adapter类、以及对多个运行时组件的同步更新。

主要变更

配置参数调整 (config/config.yaml)

  • 关闭相机图像反转功能 (capturer.invert_image: true → false)
  • 提升初始弹速数值 (initial_bullet_speed: 21.0 → 24.2)
  • 移除偏航偏移 (yaw_offset: 2.5 → 0.0)
  • 降低前哨站撤离角度阈值 (outpost_leaving_angle: 50.0 → 30.0)
  • 禁用惰性云台模式 (is_lazy_gimbal: true → false)

新增适配器模块 (src/adapter/adapter.hpp)

  • 创建新的 rmcs::Adapter 类,用于统一管理TF(Transform Frames)数据访问
  • 核心接口包括:
    • ready(): 检查TF系统准备状态
    • camera_transform(): 获取OdomImu → CameraLink的变换矩阵(Eigen::Isometry3d)
    • barrel_direction(): 获取枪管方向向量(Eigen::Vector3d)

状态结构重构 (src/utility/shared/context.hpp)

  • AutoAimState 增加 robot_center 字段,用于追踪机器人中心位置
  • 引入 static constexpr kNaN 常量,替代分散的 std::numeric_limits<double>::quiet_NaN() 调用
  • 统一所有浮点型字段(yaw、pitch、速率、加速度等)的NaN初始化方式
  • 提升代码可读性和可维护性

组件核心逻辑更新 (src/component.cpp)

  • 注册新输出端口 /auto_aim/robot_center,以支持中心位置的发布
  • 新增 set_default_command() 辅助函数,用于初始化每帧的默认输出
  • 优化控制流逻辑:
    • 每个控制周期执行默认命令设置
    • 使用 latest.has_value() 进行早期返回,处理缺失的飞书命令
    • 超时情况下回退到默认状态,而非显式修改控制标志
  • 扩展命令到输出的映射,新增 robot_center、速率/加速度和前馈有效性等字段
  • 更新适配器依赖:从 adapter/sentry.hpp 切换到 adapter/adapter.hpp

运行时初始化优化 (src/runtime.cpp)

  • 补充缺失的 <filesystem> 标准库头文件
  • 新增 utility/math/linear.hpp 依赖
  • 规范化所有组件对象的初始化风格(统一花括号和间距格式)
  • 扩展可视化功能范围:在主控制循环中调用 visualization.update_mpc_plan() 传递命令的偏航/俯仰角及其对应的速率和加速度参数

技术意义

  • 状态管理增强:引入机器人中心位置追踪,为更精确的目标瞄准和轨迹规划提供基础
  • 代码质量提升:通过NaN常量重构消除代码重复,提高可维护性
  • TF集成规范化:新Adapter类统一了变换数据的访问接口,简化了系统依赖关系
  • 可视化功能扩展:MPC计划可视化现在包含完整的动态状态信息,便于调试

变更统计

  • config/config.yaml: 5 处新增,5 处删除
  • src/adapter/adapter.hpp: 29 行新增(新文件)
  • src/component.cpp: 35 行新增,15 行删除
  • src/runtime.cpp: 15 行新增,10 行删除
  • src/utility/shared/context.hpp: 13 行新增,15 行删除

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 3, 2026

Walkthrough

该PR更新了自动瞄准系统的配置参数,引入了新的Adapter类来封装TF接口,并重构了组件命令处理和默认值初始化逻辑,同时将NaN常量进行了统一化管理。

Changes

自动瞄准系统重构与配置调优

Layer / File(s) Summary
数据结构与常量
src/utility/shared/context.hpp
AutoAimStateSystemContext引入static constexpr kNaN常量,将分散的quiet_NaN()调用统一为kNaN引用,简化成员初始化逻辑。
TF访问适配器
src/adapter/adapter.hpp
新增rmcs::Adapter类,通过rmcs_executor::Component的TF输入接口提供camera_transform()barrel_direction()等变换查询方法。
组件命令处理与输出
src/component.cpp
组件头文件由adapter/sentry.hpp切换为adapter/adapter.hpp;新增/auto_aim/robot_center输出;重构update()流程引入set_default_command()方法初始化命令状态;从Feishu命令中提取并传递yaw_ratepitch_rateyaw_accpitch_accfeedforward_valid等字段。
运行时集成与可视化
src/runtime.cpp
添加<filesystem>utility/math/linear.hpp头文件;规范化组件对象和计数器的初始化格式;在可视化更新中新增visualization.update_mpc_plan()调用,传递命令的姿态和速度/加速度信息。
系统参数配置
config/config.yaml
相机图像反演由true改为false;初始弹速由21.0提升至24.2;yaw偏移由+2.5清零至0.0;哨岗离开角度由50.0°降低至30.0°;激光云台自动模式由true改为false

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Fix/18 coordinate transform and fixmes #19:两个PR都涉及里程计坐标系与相机坐标系的变换语义更新,该PR新增Adapter暴露OdomImu→CameraLink变换,而相关PR则更新了camera2world到odom_to_camera的API使用及ControlState、运行时和位姿估计器的相关逻辑。

Suggested reviewers

  • creeper5820

Poem

🐰 嗨呀!新的适配器来报到
TF变换不再迷茫,数据整整齐齐
默认指令初初们排好队
从配置到组件,一条龙无缝对接
自动瞄准的小兔子,又长本领啦! 🎯✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive 标题不完整且含糊不清,使用省略号"and…"表示被截断,未能充分传达变更的全部内容。 建议完善标题为完整的单句描述,例如:"refactor: update AutoAimState with center position and adapt Adapter interface"
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 fix/fix-default-config

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

@heyeuu heyeuu self-assigned this May 3, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 (1)
src/component.cpp (1)

27-27: ⚡ Quick win

把注册初值也同步到 NaN 语义。

这里已经把“无指令”统一成 kNaN / kVectorNaN,但 register_output 里的 control_directionyaw_ratepitch_rateyaw_accpitch_acc 仍然以 0 注册。若下游在首次 update() 前读取这些输出,会拿到看起来合法的零值而不是“无效态”。建议把注册初值一起改掉,和 set_default_command() 保持一致。

建议修改
-        register_output("/auto_aim/control_direction", target_direction, Eigen::Vector3d::Zero());
+        register_output("/auto_aim/control_direction", target_direction, kVectorNaN);
         register_output("/auto_aim/robot_center", robot_center, kVectorNaN);
         register_output("/auto_aim/should_shoot", should_shoot, false);
-        register_output("/auto_aim/yaw_rate", yaw_rate, 0.0);
-        register_output("/auto_aim/pitch_rate", pitch_rate, 0.0);
-        register_output("/auto_aim/yaw_acc", yaw_acc, 0.0);
-        register_output("/auto_aim/pitch_acc", pitch_acc, 0.0);
+        register_output("/auto_aim/yaw_rate", yaw_rate, kNaN);
+        register_output("/auto_aim/pitch_rate", pitch_rate, kNaN);
+        register_output("/auto_aim/yaw_acc", yaw_acc, kNaN);
+        register_output("/auto_aim/pitch_acc", pitch_acc, kNaN);

Also applies to: 114-124

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/component.cpp` at line 27, The registered output initial values for
control signals are still 0 while the rest of the module uses NaN semantics;
update the register_output calls for control_direction, yaw_rate, pitch_rate,
yaw_acc, and pitch_acc to use kVectorNaN or kNaN as appropriate (matching the
types used by set_default_command) so downstream readers before the first
update() see an invalid/NaN state rather than zeros; locate these in the
register_output invocations and replace the zero defaults with the corresponding
kNaN/kVectorNaN constants to keep semantics consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/utility/shared/context.hpp`:
- Line 15: context.hpp uses std::numeric_limits<double>::quiet_NaN() (kNaN and
another usage at line ~45) but does not explicitly include <limits>; add an
explicit `#include` <limits> in context.hpp to satisfy header self-containment and
update the include ordering so standard headers (like <limits>) appear in the
standard-library group (between local and third-party groups with a single blank
line separating groups) before including "utility/math/linear.hpp".

---

Nitpick comments:
In `@src/component.cpp`:
- Line 27: The registered output initial values for control signals are still 0
while the rest of the module uses NaN semantics; update the register_output
calls for control_direction, yaw_rate, pitch_rate, yaw_acc, and pitch_acc to use
kVectorNaN or kNaN as appropriate (matching the types used by
set_default_command) so downstream readers before the first update() see an
invalid/NaN state rather than zeros; locate these in the register_output
invocations and replace the zero defaults with the corresponding kNaN/kVectorNaN
constants to keep semantics consistent.
🪄 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: 7953ac86-c40a-490a-805d-8460d8ba4845

📥 Commits

Reviewing files that changed from the base of the PR and between 4e0e27b and c1dc963.

📒 Files selected for processing (5)
  • config/config.yaml
  • src/adapter/adapter.hpp
  • src/component.cpp
  • src/runtime.cpp
  • src/utility/shared/context.hpp

Comment thread src/utility/shared/context.hpp
@creeper5820 creeper5820 merged commit 9ca4aad into main May 3, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in RMCS Auto Aim V2 May 3, 2026
@creeper5820 creeper5820 deleted the fix/fix-default-config branch May 3, 2026 16:15
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