Skip to content

feat: refine visualization granularity with multi-layered debug control#45

Merged
creeper5820 merged 2 commits intomainfrom
refactor/visualization-config
May 4, 2026
Merged

feat: refine visualization granularity with multi-layered debug control#45
creeper5820 merged 2 commits intomainfrom
refactor/visualization-config

Conversation

@heyeuu
Copy link
Copy Markdown
Member

@heyeuu heyeuu commented May 4, 2026

PR 摘要:完善可视化函数的多层级调试控制

概述

本PR通过引入细粒度的可视化配置控制,增强了调试可视化功能的灵活性。用户现在可以通过配置文件独立启用或禁用各项可视化功能,包括图像发送、装甲识别、机器人预测、相机位置、瞄准方向和MPC规划等。

主要变更

配置文件改动 (config/config.yaml)

  • visualization 部分新增6个布尔配置项:
    • image_enabled:控制图像流发送
    • visible_armors_enabled:控制装甲可视化
    • visible_robot_enabled:控制机器人可视化
    • camera_pose_enabled:控制相机位置可视化
    • aiming_direction_enabled:控制瞄准方向可视化
    • mpc_plan_enabled:控制MPC规划可视化
  • 重新组织了监控主机/端口/流类型的配置注释布局

可视化模块改动 (src/kernel/visualization.cpp)

  • Visualization::Impl::Config 结构体中新增6个布尔字段,用于运行时控制各项可视化功能的启用状态
  • 扩展了 Config 的序列化元数据 (metas),包含所有新增布尔字段
  • Config 实例从 initialize 函数内的局部变量提升为 Impl 类成员变量
  • send_image 和各 update_* 方法中添加早期返回机制,根据对应的配置标志决定是否执行可视化操作

运行时控制流改动 (src/runtime.cpp)

  • 重新组织了目标追踪阶段的可视化调用逻辑:
    • update_visible_robot() 现在在获取预测装甲后立即调用
    • update_aiming_direction() 在完成火力控制求解后调用
    • update_mpc_plan() 现在条件性地执行,仅当 command.feedforward_valid 为真时才调用(之前无条件调用)

这一调整使MPC规划的可视化与前馈有效性状态保持同步,避免在无效前馈情况下进行不必要的可视化更新。

影响范围

  • 公有API保持不变,所有改动均为内部实现细节
  • 向后兼容:配置文件中的所有新增项均默认为 true,保持现有行为

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

@heyeuu has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ 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: c7316a31-c19e-48f3-bafa-e57546316c72

📥 Commits

Reviewing files that changed from the base of the PR and between 94048da and 9fee19a.

📒 Files selected for processing (1)
  • src/runtime.cpp

总览

该PR为可视化系统添加了运行时配置的启用/禁用标志,包括图像发布、可见装甲/机器人、相机姿态、瞄准方向和MPC计划。配置项从YAML扩展到内部结构,所有可视化方法现通过早期返回执行条件控制。

改动

可视化配置与条件控制

层级 / 文件 概述
配置数据定义
config/config.yaml, src/kernel/visualization.cpp (36-60行)
visualization 配置新增六个布尔标志(image_enabledvisible_armors_enabledvisible_robot_enabledcamera_pose_enabledaiming_direction_enabledmpc_plan_enabled),Visualization::Impl::Config 结构体随之扩展,并将配置实例从本地变量提升为类成员变量。
条件执行逻辑
src/kernel/visualization.cpp (83-196行)
initialize 方法改为从YAML序列化成员configsend_image 和各 update_* 方法在相应标志禁用时早期返回,实现运行时的细粒度控制。
运行时集成
src/runtime.cpp (175-202行)
调整可视化方法的调用时序和条件:update_visible_robot 在控制求解后立即执行,update_mpc_plan 仅在 command.feedforward_valid 为真时执行,避免无效数据的可视化输出。

代码审查工作量估计

🎯 2 (简单) | ⏱️ ~10 分钟

该变更主要涉及配置扩展和标志线程的添加,逻辑简单直观。虽然涉及三个文件,但改动分布均衡且无复杂交互,每处变更都是标准的早期返回guard或配置序列化,易于验证。

🐰✨ 配置标志闪闪亮,

可视化流动有章法,

条件与守卫共舞蹈,

运行时之选尽在手中,

素描图景,删繁就简。 🎨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes across all three modified files: adding runtime-configurable visualization toggles in the config, implementing multi-layered debug control flags in the visualization implementation, and reorganizing visualization calls based on control conditions.
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.

✏️ 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 refactor/visualization-config

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 38 minutes.

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/kernel/visualization.cpp (1)

123-126: ⚡ Quick win

把“禁用图像”当成成功的 no-op。

image_enabled=false 时这里直接返回 false,会把有意关闭可视化和真正的传输失败混在一起。对未来调用方来说,这个状态位更适合表示“本次没有发送”,而不是“出错了”。

♻️ 建议调整返回语义
-        if (!config.image_enabled) return false;
+        if (!config.image_enabled) return true;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/kernel/visualization.cpp` around lines 123 - 126, In send_image(const
Image& image) noexcept the current early return of false when
config.image_enabled is false conflates an intentional no-op with an actual send
failure; change the logic so that if !config.image_enabled the function returns
true (indicating a successful no-op) while keeping the existing false return for
!is_initialized and actual failures, and update any inline comment to document
that config.image_enabled=false is treated as a successful no-op; reference
send_image, is_initialized and config.image_enabled when making the change.
src/runtime.cpp (1)

174-178: ⚡ Quick win

把 visible_robot 的更新从控制分支里拆出来。

现在 visible_robot_enabled 只有在 allow_control && snapshot 成立时才会生效;如果目标是“多层可视化开关”,这会让控制关闭时的机器人层完全失效。建议只依赖 snapshot 的存在性来刷新这层,或者在控制关闭时显式清空它。

♻️ 建议拆分可视化更新
-        if (target.allow_control && target.snapshot) {
-            auto& snapshot = target.snapshot;
-            auto armors    = snapshot->predicted_armors(Clock::now());
-            visualization.update_visible_robot(armors);
-
+        if (target.snapshot) {
+            visualization.update_visible_robot(target.snapshot->predicted_armors(Clock::now()));
+        }
+
+        if (target.allow_control && target.snapshot) {
+            auto& snapshot = target.snapshot;
             const auto control = target.tracking_confirmed;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/runtime.cpp` around lines 174 - 178, The visible_robot update is
currently gated by target.allow_control which disables the visualization when
control is off; instead, use only the presence of target.snapshot to refresh the
robot layer (or explicitly clear it when snapshot is null). Move the
visualization.update_visible_robot(...) call out of the if (target.allow_control
&& target.snapshot) block and call it when target.snapshot is non-null using
snapshot->predicted_armors(Clock::now()), and ensure when target.snapshot is
null (or if you prefer to keep control gating) you call
visualization.clear_visible_robot() (or equivalent) so the layer isn’t left
stale; update locations: the block that references target.allow_control,
target.snapshot, snapshot, predicted_armors, and
visualization.update_visible_robot.
🤖 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/runtime.cpp`:
- Around line 194-198: 当 command.feedforward_valid 为 false 时当前代码跳过调用
visualization.update_mpc_plan,导致 MpcPlanVisualizer 使用的
geometry_msgs::msg::Vector3Stamped 留下上帧轨迹。修改方法:在检测到 command.feedforward_valid ==
false 时,显式清除或覆盖旧的 MPC 轨迹—例如在该分支调用 visualization 的一个清除方法(如
visualization.clear_mpc_plan 或类似命名),或发送空/零向量类型的 Vector3Stamped
消息以覆盖旧发布内容;确保修改点在使用 visualization.update_aiming_direction 和 update_mpc_plan
的同一位置以保证行为一致。

---

Nitpick comments:
In `@src/kernel/visualization.cpp`:
- Around line 123-126: In send_image(const Image& image) noexcept the current
early return of false when config.image_enabled is false conflates an
intentional no-op with an actual send failure; change the logic so that if
!config.image_enabled the function returns true (indicating a successful no-op)
while keeping the existing false return for !is_initialized and actual failures,
and update any inline comment to document that config.image_enabled=false is
treated as a successful no-op; reference send_image, is_initialized and
config.image_enabled when making the change.

In `@src/runtime.cpp`:
- Around line 174-178: The visible_robot update is currently gated by
target.allow_control which disables the visualization when control is off;
instead, use only the presence of target.snapshot to refresh the robot layer (or
explicitly clear it when snapshot is null). Move the
visualization.update_visible_robot(...) call out of the if (target.allow_control
&& target.snapshot) block and call it when target.snapshot is non-null using
snapshot->predicted_armors(Clock::now()), and ensure when target.snapshot is
null (or if you prefer to keep control gating) you call
visualization.clear_visible_robot() (or equivalent) so the layer isn’t left
stale; update locations: the block that references target.allow_control,
target.snapshot, snapshot, predicted_armors, and
visualization.update_visible_robot.
🪄 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: f6e269f9-f0b9-46d3-9e6e-2639feb002f2

📥 Commits

Reviewing files that changed from the base of the PR and between 9ca4aad and 94048da.

📒 Files selected for processing (3)
  • config/config.yaml
  • src/kernel/visualization.cpp
  • src/runtime.cpp

Comment thread src/runtime.cpp Outdated
@heyeuu heyeuu requested a review from creeper5820 May 4, 2026 05:34
@creeper5820 creeper5820 merged commit a0d91c0 into main May 4, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in RMCS Auto Aim V2 May 4, 2026
@creeper5820 creeper5820 deleted the refactor/visualization-config branch May 4, 2026 13:22
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