Skip to content

fix: fix armor selection logic#46

Merged
creeper5820 merged 8 commits intomainfrom
fix/choose-incoming-armor
May 6, 2026
Merged

fix: fix armor selection logic#46
creeper5820 merged 8 commits intomainfrom
fix/choose-incoming-armor

Conversation

@heyeuu
Copy link
Copy Markdown
Member

@heyeuu heyeuu commented May 6, 2026

装甲选择逻辑修复

核心变更

装甲选择算法优化 (aim_point_chooser.cpp)

重新设计了装甲优先级选择机制,引入了基于预期来弹角度 (preferred_incoming) 的新优先级键。该键根据偏航角增量和角速度动态计算,实现了对旋转方向的感知选择。选择对比从4元组扩展至5元组,提升了复杂场景下的装甲选择准确性。

错误处理现代化 (aim_point_sampling.cpp/hpp)

将错误处理模式从 std::optional 迁移至 std::expected,更好地支持错误信息传播。sample_aim_point_at() 返回类型从 std::optional<Eigen::Vector3d> 改为 std::expected<Eigen::Vector3d, std::string>,当无法选中装甲时返回描述性错误消息。

测试覆盖

新增三个单元测试验证装甲选择在不同旋转场景下的正确行为:

  • PreferIncomingArmorWhenSpinPositive: 正向快速旋转时优先选择来弹区内的装甲
  • PreferIncomingArmorWhenSpinNegative: 反向快速旋转时优先选择对应方向的装甲
  • KeepAbsoluteDeltaPriorityWhenSpinZero: 无旋转时保持绝对偏航角优先级

参数调优

火控配置参数微调以适应改进的选择逻辑:

  • 初始弹速: 21.4 m/s (原 24.2 m/s)
  • 射击延迟: 0.07 s (原 0.1 s)
  • 来弹角度窗口: 70° (原 60°)

代码清理

  • 调整引入头文件从 adapter/sentry.hpp 改为 adapter/adapter.hpp
  • 格式化和代码对齐优化

@heyeuu heyeuu added this to the 火控及控制模块 milestone May 6, 2026
@heyeuu heyeuu requested a review from creeper5820 May 6, 2026 12:54
@heyeuu heyeuu self-assigned this May 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@creeper5820 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 44 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8233b328-5ec7-43ab-8d3d-159ebfd1163a

📥 Commits

Reviewing files that changed from the base of the PR and between 3eaf726 and e24dbd1.

📒 Files selected for processing (6)
  • .github/workflows/gtest.yml
  • CMakeLists.txt
  • package.xml
  • src/kernel/fire_control.cpp
  • test/CMakeLists.txt
  • test/feishu_test.cpp

高层总结

本PR更新了火力控制配置参数,改进了目标装甲选择的优先级排序算法,将错误处理从optional迁移至expected风格,并增加了三项新的单元测试以验证装甲选择行为。

变更内容

配置与组件初始化

层级 / 文件 摘要
配置参数调优
config/config.yaml
初始子弹速度从24.2降至21.4 m/s,射击延迟从0.1降至0.07 s,来弹角从60.0增至70.0度。
组件集成
src/component.cpp
适配器头文件从adapter/sentry.hpp切换至adapter/adapter.hppSystemContext初始化格式调整为SystemContext {}

火力控制算法与错误处理

层级 / 文件 摘要
装甲选择优先级
src/module/fire_control/aim_point_chooser.cpp
优先级键从4元组(绝对角度差、惩罚值、ID、索引)扩展为5元组,新增preferred_incoming字段基于偏航角与角速度计算,改变候选装甲的字典序排序。
采样错误处理迁移
src/module/fire_control/solver/aim_point_sampling.hppsrc/module/fire_control/solver/aim_point_sampling.cpp
sample_aim_point_at方法返回值从std::optional<Eigen::Vector3d>改为std::expected<Eigen::Vector3d, std::string>;在无装甲选中时返回带错误消息的std::unexpected;态度求解失败时显式传播错误。
测试验证
test/aim_point_chooser.cpp
新增三项单元测试:PreferIncomingArmorWhenSpinPositivePreferIncomingArmorWhenSpinNegativeKeepAbsoluteDeltaPriorityWhenSpinZero,验证自旋角速度对装甲选择的影响。

预估代码审查工作量

🎯 3 (中等复杂度) | ⏱️ ~20 分钟

可能相关的PR

  • Alliance-Algorithm/rmcs_auto_aim_v2#44:同时修改component.cpp中的适配器头文件包含,切换至adapter/adapter.hpp,并涉及火力控制配置参数的调整,代码级别有重叠。

建议标签

bug

建议审查者

  • creeper5820

庆祝诗

🐰 弹速调整,延迟缩短,
新的优先级序列闪闪发光,
装甲选择更聪慧,错误处理更可靠,
自旋角速度指引前路,
三项新测试为真理作证!🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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 The pull request title directly describes the main change: updating the armor selection logic to prefer incoming armor based on spin direction, which is reflected across multiple files including configuration updates and the core selection algorithm in aim_point_chooser.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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/choose-incoming-armor

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.

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.

🧹 Nitpick comments (1)
src/module/fire_control/aim_point_chooser.cpp (1)

107-117: 💤 Low value

命名建议:preferred_incoming 与值语义相反,易误读。

该 lambda 实际上返回的是“是否为离开侧”的惩罚位:delta 与旋向同号(已转过中线、正在离开)时返回 1,否则返回 0;再借助 std::tuple< 比较让 0(incoming)胜出。这与下面 line 116 的 last_penalty(1 = 有惩罚)写法不一致,建议统一为“penalty”语义,使排序方向更直观。

♻️ 命名/语义统一示例
-        const auto priority_key = [&](size_t index) {
-            const auto preferred_incoming = [&] {
-                const auto delta = candidate_evals[index].delta_yaw;
-                if (angular_velocity > 0.0) return (delta > 0.0) ? 1 : 0;
-                if (angular_velocity < 0.0) return (delta < 0.0) ? 1 : 0;
-                return 0;
-            }();
+        const auto priority_key = [&](size_t index) {
+            // 1 = 已越过中线/正在离开侧,排序中受惩罚;0 = incoming,优先
+            const auto leaving_penalty = [&] {
+                const auto delta = candidate_evals[index].delta_yaw;
+                if (angular_velocity > 0.0) return (delta > 0.0) ? 1 : 0;
+                if (angular_velocity < 0.0) return (delta < 0.0) ? 1 : 0;
+                return 0;
+            }();
             const auto abs_delta = std::abs(candidate_evals[index].delta_yaw);
             const auto id        = armors[index].id;
             const auto is_last = last_chosen_armor_id.has_value() && (id == *last_chosen_armor_id);
             const auto last_penalty = is_last ? 0 : 1;
-            return std::tuple { preferred_incoming, abs_delta, last_penalty, id, index };
+            return std::tuple { leaving_penalty, abs_delta, last_penalty, id, index };
         };
🤖 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.cpp` around lines 107 - 117, The
variable preferred_incoming has inverted/ambiguous semantics (it returns 1 when
the target is leaving) which conflicts with last_penalty’s meaning and makes
tuple-based ordering confusing; change it to an explicit penalty flag (e.g.,
leaving_penalty or side_penalty) that returns 1 when
(candidate_evals[index].delta_yaw and angular_velocity have the same sign) and 0
otherwise, then use that new penalty variable in the returned std::tuple
alongside abs_delta, last_penalty, id, index so the numeric meanings (1 =
penalized, 0 = preferred) are consistent across preferred/last penalties and
comparisons.
🤖 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.

Nitpick comments:
In `@src/module/fire_control/aim_point_chooser.cpp`:
- Around line 107-117: The variable preferred_incoming has inverted/ambiguous
semantics (it returns 1 when the target is leaving) which conflicts with
last_penalty’s meaning and makes tuple-based ordering confusing; change it to an
explicit penalty flag (e.g., leaving_penalty or side_penalty) that returns 1
when (candidate_evals[index].delta_yaw and angular_velocity have the same sign)
and 0 otherwise, then use that new penalty variable in the returned std::tuple
alongside abs_delta, last_penalty, id, index so the numeric meanings (1 =
penalized, 0 = preferred) are consistent across preferred/last penalties and
comparisons.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af56cb1b-e312-4306-9465-fa2b04bcff44

📥 Commits

Reviewing files that changed from the base of the PR and between 8b11496 and 3eaf726.

📒 Files selected for processing (6)
  • config/config.yaml
  • src/component.cpp
  • src/module/fire_control/aim_point_chooser.cpp
  • src/module/fire_control/solver/aim_point_sampling.cpp
  • src/module/fire_control/solver/aim_point_sampling.hpp
  • test/aim_point_chooser.cpp

Copy link
Copy Markdown
Collaborator

@creeper5820 creeper5820 left a comment

Choose a reason for hiding this comment

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

AC

@creeper5820 creeper5820 merged commit a06e498 into main May 6, 2026
3 checks passed
@creeper5820 creeper5820 deleted the fix/choose-incoming-armor branch May 6, 2026 15:33
@github-project-automation github-project-automation Bot moved this from Todo to Done in RMCS Auto Aim V2 May 6, 2026
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