Skip to content

refactor: fire controller - #65

Merged
creeper5820 merged 5 commits into
mainfrom
refactor/fire-controller
Jul 3, 2026
Merged

refactor: fire controller#65
creeper5820 merged 5 commits into
mainfrom
refactor/fire-controller

Conversation

@creeper5820

@creeper5820 creeper5820 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

概括

  • 平移状态存在明显滞后,平移过程噪声太小,速度变化太平滑,而过程噪声太大又受到云台移动影响比较大,所以需要引入动态观测噪声,云台速度比较大的情况下,观测噪声给大点(也可能是控制的问题,给出了错误的前馈)
  • 由于 IMU 与 Image 的时间戳存在延迟,需要引入时间戳同步,对于每一帧图片,大概往回找 8ms 左右的 IMU 位姿
  • 控制上,双 Yaw 运动耦合,导致控制不准确

经测试,高速小陀螺 43 / 63 ≈ 70%,低速小陀螺 56 / 63 ≈ 90%,下面是低速小陀螺的效果视频:

6f5ae92b9c4b789eaba87bc15de16bbb.mp4

本次 PR 重构了火控链路与其与跟踪模块/自动瞄准的联动,重点提升高速、小角度场景下的瞄准稳定性与命中一致性。

  • 火控侧时间延迟补偿与接口统一FireControllerV2 将对外输入统一为 update(Timestamp, double yaw, double pitch) 并缓存 cached_stamp/cached_yaw/cached_pitch;在 aim() 中根据 当前输入时间戳与 trackable 时间戳的差值 计算 increment = shoot_delay + (cached_stamp - trackable.get_timestamp),随后通过 trackable.clone()->jump_into(fly_time + increment) 进行延迟补偿后的未来预测,再结合弹道求解迭代收敛 yaw/pitch。
  • 攻击窗口约束化(速度/加速度驱动)与预瞄状态表达FireControllerV2 新增 max_vel/max_acc 约束,并在 get_attack_window() 中基于周期时间动态收缩 attack_windowAimed 结构体新增 pre_aim 标志,auto_aim 绘制/上色逻辑区分 shoot / pre_aim / 其他,以便可视化瞄准状态差异。
  • ShootEvaluator:窗口与容差的动态缩放 + 稳定/惰性云台判定重做ShootEvaluator 不再依赖 GimbalState/YAML 初始化,改为接收 evaluate(Command, yaw, pitch);其 yaw/pitch 容差基于几何关系进行动态缩放(通过 cos(yaw_angle(center, armor)) 影响容差窗口),并通过 require_stable_commandis_lazy_gimbal 在 yaw/pitch 窗口内执行稳定性与惰性云台判断。
  • Tracker/模型接口统一与调试信息增强:将 Trackable/RobotModel/OutpostModeldirection/aimpoints/timestamp 迁移为 get_direction/get_aimpoints/get_timestamp,并新增 get_rotation_speed();同时在 TrackerV2::Addition 增加 infos 承载多条带文本与点位的调试信息,在前哨站/机器人收敛分支输出旋转角速度与速度分量等。
  • 弹道求解与数据类型调整:弹道相关模块将向量类型迁移为 Point3d,并对 TrajectorySolution 做命名空间与内部实现重构(将常量/估计逻辑收进文件内 details)。
  • 配置与工程规范更新fire_control 配置移除旧的 shoot_evaluator 子结构,改为直接引入速度/加速度约束、稳定/惰性开关以及 yaw/pitch 容差等字段;AGENTS.md 新增基于 clangd --checkclang-tidy -p 的“先静态检查再编译验证”流程;Printer 日志模板/实现改为 const 成员函数以兼容只读调用场景。

整体上,修改把火控决策链从“静态阈值 + 旧接口”升级为“结合时间戳差的延迟补偿预测 + 速度约束的攻击窗口 + 几何驱动的容差窗口与稳定性/惰性云台判定”,并同步完成 tracker/模型接口统一与可视化调试信息增强。

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b2e0b942-c0c9-4334-b712-41ef56fe99a3

📥 Commits

Reviewing files that changed from the base of the PR and between 0c8e4cc and a8b8398.

📒 Files selected for processing (2)
  • src/kernel/fire_control.cpp
  • src/module/tracker/model/robot.hpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/kernel/fire_control.cpp

Walkthrough

本 PR 重构了火控与跟踪链路:射击评估、弹道求解和火控瞄准流程改为新的参数与状态表达;跟踪模型统一 getter 命名并新增旋转速度;同时更新配置结构、调试信息输出、日志 const 限定与开发规范。

Changes

火控/跟踪重构与配套变更

Layer / File(s) Summary
ShootEvaluator 契约与几何窗口判定重构
src/module/fire_control/shoot_evaluator.hpp, src/module/fire_control/shoot_evaluator.cpp
Config/Command 结构体、构造函数与 evaluate 签名改为直接接收 yaw/pitch,并实现基于几何角度窗口的容差与稳定性判定。
TrajectorySolution 常量与坐标访问重构
src/module/fire_control/trajectory_solution.hpp, src/module/fire_control/trajectory_solution.cpp
估算逻辑迁移至 details 命名空间常量与函数,Input::point 类型由 Eigen::Vector3d 改为 Point3d,命名空间调整为 rmcs。
FireControllerV2 配置、瞄准逻辑与 update 接口重构
src/kernel/fire_control.hpp, src/kernel/fire_control.cpp
Config 新增速度/加速度与云台策略字段,Impl 改用 ShootEvaluator 指针与旋转窗口选择逻辑,Aimed 新增 pre_aim 字段,update 重载合并为单一签名。
Trackable 与模型 getter 统一重命名
src/module/tracker/trackable.hpp, src/module/tracker/model/outpost.{hpp,cpp}, src/module/tracker/model/robot.{hpp,cpp}
direction/aimpoints/timestamp 方法统一重命名为 get_ 前缀并新增 get_rotation_speed,同步调整噪声参数。
TrackerV2 调试信息结构与推送
src/kernel/tracker.hpp, src/kernel/tracker.cpp
Addition 新增 Info 结构与 infos 向量,execute 中清空并推送包含旋转角/速度/vx/vy 的调试条目。
AutoAim 调试渲染与瞄准可视化调整
src/kernel/auto_aim.cpp
identifier 结果解包简化,新增基于 tracker infos 的文本绘制,弹道更新调用合并,瞄准点颜色判定新增 PREAIM 状态。
配置、规范与日志接口更新
config/config.yaml, AGENTS.md, src/utility/logging/printer.{hpp,cpp}
fire_control 移除 shoot_evaluator 子块并新增运动约束/容差字段;文档补充构建流程与语法检查规范;Printer 日志接口改为 const。

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: heyeuu

Poem

兔兔蹦进新火线,
窗口一算更分明;
infos 亮起小星点,
get_ 前缀排成行。
🐇🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive 标题与变更主题相关,但过于笼统,无法体现这次对 fire controller、tracker 和接口调整的主要内容。 建议改为更具体的标题,概括核心改动,例如 fire controller 重构及相关接口调整。
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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/fire-controller

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.

@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: 3

🤖 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 `@AGENTS.md`:
- Line 26: The command example uses inconsistent placeholder styling in the
clang-tidy invocation: <构建目录> is wrapped in backticks while <修改的文件路径> uses angle
brackets. Update the example in the documentation to use the same angle-bracket
placeholder style consistently, using the clang-tidy command snippet as the
reference location.

In `@src/kernel/fire_control.cpp`:
- Around line 166-175: The dynamic window in fire_control.cpp is mixing units:
config.attack_window is already in radians, but velocity/acceleration limits in
the physical_limit calculation are being normalized by 2π before comparison,
which can shrink the window too much at high speeds. Update the logic in the
fire_control path so the limits compared against attack_window use consistent
angle units, and verify the returned window values in the function that builds
the dynamic attack window remain in radians.

In `@src/module/fire_control/shoot_evaluator.cpp`:
- Around line 136-137: The pitch stability check in shoot_evaluator.cpp is using
the current gimbal pitch instead of the previous command, which can bypass
require_stable_command for pitch changes. Update the command_stable logic in the
code around in_yaw_window/in_pitch_window to compare last_command->pitch against
command.pitch for the pitch window, keeping the yaw comparison unchanged.
🪄 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: 0c1beb5c-6f00-42a4-a9f9-5ab0dd84a1ad

📥 Commits

Reviewing files that changed from the base of the PR and between 3964c3d and 5221a68.

📒 Files selected for processing (19)
  • AGENTS.md
  • config/config.yaml
  • src/kernel/auto_aim.cpp
  • src/kernel/fire_control.cpp
  • src/kernel/fire_control.hpp
  • src/kernel/tracker.cpp
  • src/kernel/tracker.hpp
  • src/module/fire_control/gimbal_state.hpp
  • src/module/fire_control/shoot_evaluator.cpp
  • src/module/fire_control/shoot_evaluator.hpp
  • src/module/fire_control/trajectory_solution.cpp
  • src/module/fire_control/trajectory_solution.hpp
  • src/module/tracker/model/outpost.cpp
  • src/module/tracker/model/outpost.hpp
  • src/module/tracker/model/robot.cpp
  • src/module/tracker/model/robot.hpp
  • src/module/tracker/trackable.hpp
  • src/utility/logging/printer.cpp
  • src/utility/logging/printer.hpp
💤 Files with no reviewable changes (1)
  • src/module/fire_control/gimbal_state.hpp

Comment thread AGENTS.md Outdated
Comment thread src/kernel/fire_control.cpp Outdated
Comment thread src/module/fire_control/shoot_evaluator.cpp Outdated
@creeper5820
creeper5820 merged commit 202bad2 into main Jul 3, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in RMCS Auto Aim V2 Jul 3, 2026
@creeper5820
creeper5820 deleted the refactor/fire-controller branch July 3, 2026 05:20
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.

1 participant