Skip to content

feat: add UiRobotCenterOverlay for flight referee UI#87

Open
zlq04222 wants to merge 5 commits into
mainfrom
feat/robot-center-overlay
Open

feat: add UiRobotCenterOverlay for flight referee UI#87
zlq04222 wants to merge 5 commits into
mainfrom
feat/robot-center-overlay

Conversation

@zlq04222

@zlq04222 zlq04222 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

feat: add UiRobotCenterOverlay for flight referee UI

本次变更主要为飞行裁判 UI 新增 UiRobotCenterOverlay/AutoAimUi 相关能力,并配套完善执行器与运行时基础设施:

  • 新增 AutoAimUi 组件插件,实现基于 /tf 相机位姿、robot_centershould_shoot 的屏幕投影与准星绘制逻辑;当输入无效或投影越界时隐藏图形,满足条件时显示圆环、十字线及状态颜色切换。
  • 将该组件注册到插件系统,并在飞行配置中加入对应组件映射与参数节点。
  • rmcs_executor 升级为 C++23,并重构执行线程调度:加入更新频率校验、线程配置应用、周期统计与 5 秒窗口的性能上报。
  • 新增 ThreadConfig,支持解析并应用线程名、CPU 亲和力、调度策略、优先级和 nice。
  • 新增 TDigest 统计实现,用于记录更新耗时、迟到分布等运行指标。
  • main 中组件参数读取逻辑改为直接获取,不再显式在缺失时抛出异常。

@zlq04222 zlq04222 requested a review from creeper5820 July 7, 2026 07:24
@github-project-automation github-project-automation Bot moved this to Todo in RMCS Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

新增AutoAimUi瞄准UI插件组件及其配置绑定;重构rmcs_executor更新线程为带TDigest统计的周期调度;新增rmcs_utility下的TDigest统计摘要与ThreadConfig线程配置解析/应用工具;更新CMake的C++标准为23;简化main.cpp参数读取逻辑。

Changes

AutoAimUi瞄准UI组件接入

Layer / File(s) Summary
组件核心实现:坐标投影与UI绘制
rmcs_ws/src/rmcs_core/src/referee/app/ui/auto_aim.cpp
新增AutoAimUi组件,基于TF相机位姿与robot_center输入计算屏幕投影点,绘制圆环与十字准星,并根据should_shoot切换颜色与显隐。
插件注册与运行时配置
rmcs_ws/src/rmcs_core/plugins.xml, rmcs_ws/src/rmcs_bringup/config/flight.yaml
注册AutoAimUi插件类并绑定auto_aim_ui配置节点,新增offset_x/y/z参数。

执行器线程调度统计与工具库

Layer / File(s) Summary
TDigest统计摘要数据结构
rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp
新增TDigest模板类,支持插入、合并、分位数与累积分布计算。
ThreadConfig线程配置解析与应用
rmcs_ws/src/rmcs_utility/include/rmcs_utility/thread_config.hpp
新增线程配置字符串解析、校验与应用到当前线程的调度策略/优先级/亲和力/命名逻辑。
更新线程重构:统计驱动的周期调度
rmcs_ws/src/rmcs_executor/src/executor.hpp
将更新线程改为基于TDigest统计的周期调度,记录起床迟到与更新耗时,计算跳过周期数并周期性输出统计日志。
构建标准更新与参数读取简化
rmcs_ws/src/rmcs_executor/CMakeLists.txt, rmcs_ws/src/rmcs_utility/CMakeLists.txt, rmcs_ws/src/rmcs_executor/src/main.cpp
CMake显式设置C++23标准,main.cpp简化components参数读取,移除显式异常抛出。

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

Sequence Diagram(s)

sequenceDiagram
  participant rmcs_executor
  participant AutoAimUi
  participant TF
  participant UI图形

  rmcs_executor->>AutoAimUi: update()
  AutoAimUi->>AutoAimUi: 校验robot_center是否有限/非零
  alt 数据无效
    AutoAimUi->>UI图形: hide_all()
  else 数据有效
    AutoAimUi->>TF: lookup_transform(相机位姿)
    TF-->>AutoAimUi: 相机变换
    AutoAimUi->>AutoAimUi: reproject()计算像素坐标
    alt 坐标越界或NaN
      AutoAimUi->>UI图形: hide_all()
    else 坐标在屏幕内
      AutoAimUi->>UI图形: 更新圆环颜色/半径
      AutoAimUi->>UI图形: 按should_shoot显示/隐藏十字线
    end
  end
Loading
sequenceDiagram
  participant Executor
  participant ThreadConfig
  participant thread_main
  participant TDigest

  Executor->>Executor: 校验update_rate并读取thread_config
  Executor->>ThreadConfig: 构造并解析spec
  Executor->>thread_main: 启动线程(period, thread_config)
  thread_main->>ThreadConfig: apply_to_current_thread()
  loop 每轮迭代
    thread_main->>thread_main: execute_update_iteration()
    thread_main->>TDigest: 记录start_lateness/update_duration
    thread_main->>thread_main: calculate_next_iteration_time()
    alt 达到上报周期
      thread_main->>TDigest: 合并并计算分位数
      thread_main->>thread_main: 输出累计与窗口统计日志
    end
  end
Loading

Possibly related PRs

  • Alliance-Algorithm/RMCS#85: 该PR同样围绕/auto_aim/should_shoot触发信号,在射击控制侧联动同一语义输入。
  • Alliance-Algorithm/RMCS#88: 同样修改rmcs_executor/src/executor.hpp的调度/统计逻辑并涉及ThreadConfigTDigestmain.cpp参数读取方式,代码路径高度重叠。

Suggested reviewers: creeper5820

Poem

兔子敲键盘,瞄准镜里画圆圈,
十字线闪烁,追踪机器人不倦,
线程滴答转,TDigest记下每一拍,
配置解析好,调度精准不出岔,
洞里蹦一蹦,代码合并笑开怀 🐰✨

🚥 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 标题概括了为飞行裁判 UI 新增中心点覆盖层这一主要功能,和本次变更整体方向一致。
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 feat/robot-center-overlay

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

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 `@rmcs_ws/src/rmcs_core/src/referee/app/ui/robot_center_overlay.cpp`:
- Around line 80-87: The boundary check in robot_center_overlay.cpp lets values
like u/v near the maximum screen edge pass, but RobotCenterOverlay::hide_all and
the later std::lround conversion can still produce out-of-range pixel indices.
Update the coordinate handling in the overlay update path so the rounded results
are clamped to the valid screen range before being stored in the ui/vi pixel
variables, using the existing screen_width and screen_height bounds as the
reference.
🪄 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: 0b31389a-4df4-475e-a6f9-0d2414333535

📥 Commits

Reviewing files that changed from the base of the PR and between 2c63c7d and a431649.

📒 Files selected for processing (3)
  • rmcs_ws/src/rmcs_bringup/config/flight.yaml
  • rmcs_ws/src/rmcs_core/plugins.xml
  • rmcs_ws/src/rmcs_core/src/referee/app/ui/robot_center_overlay.cpp

Comment thread rmcs_ws/src/rmcs_core/src/referee/app/ui/robot_center_overlay.cpp Outdated

static constexpr uint16_t screen_width = 1920, screen_height = 1080;

static constexpr double fx_ = 730.7267062695;

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.

常量的命名规则为:kXxxxXxxx,比如:kFy, kCx

Comment thread rmcs_ws/src/rmcs_core/src/referee/app/ui/robot_center_overlay.cpp Outdated
, cross_right_{Shape::Color::GREEN, 2, 0, 0, 0, 0, false} {
offset_x_ = get_parameter_or("offset_x", 0.000);
offset_y_ = get_parameter_or("offset_y", 0.000);
offset_z_ = get_parameter_or("offset_z", 0.202);

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.

默认值给 0

}

void update() override {
using namespace Eigen;

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.

No using

const double r4 = r2 * r2;
const double r6 = r4 * r2;

const double radial = 1.0 + k1_ * r2 + k2_ * r4 + k3_ * r6;

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.

将重投影提取成一个函数 reproject( ... )

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@creeper5820 creeper5820 force-pushed the feat/robot-center-overlay branch from 955cc52 to 2953667 Compare July 7, 2026 14:48
zlq04222 and others added 3 commits July 7, 2026 23:33
- Rename camera constants to kXxxxXxxx convention
- Move shape construction to member definition site
- Change offset_z default to 0
- Remove using namespace Eigen, use explicit Eigen:: prefix
- Extract reproject() function for coordinate projection pipeline
- Add optional `thread_config` support for the executor update thread
- Log cumulative and 5s window timing stats for start lateness, update duration, skipped cycles, and top component costs
- Vendor a local `TDigest` utility for percentile reporting
- Switch affected packages to C++23 for `std::format` and `std::expected`
- Allow starting the executor with an empty `components` list for  testing

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
rmcs_ws/src/rmcs_executor/src/executor.hpp (1)

224-231: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

大幅落后时会重复输出累计统计日志(仅观感问题)。

current_time 相对 next_report_time 落后超过一个上报间隔(例如长时间停顿导致跨越多个 5s 窗口)时,while 循环会执行多次:首次迭代已 reset_window_stats,后续迭代 log_window_statsexecuted_count == 0 提前返回,但 log_cumulative_stats 仍会重复打印相同的累计内容。功能无碍,可按需在追补 next_report_time 时跳过中间空窗口。

🤖 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 `@rmcs_ws/src/rmcs_executor/src/executor.hpp` around lines 224 - 231, The issue
is in log_due_reports, where the while loop can emit the same cumulative stats
multiple times when current_time is far behind stats.next_report_time. Update
the catch-up logic in log_due_reports so it advances stats.next_report_time
across missed 5s intervals without repeatedly calling log_cumulative_stats for
empty windows, or otherwise ensure only one cumulative log is produced per
actual report cycle while still preserving the window reset behavior.
🤖 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 `@rmcs_ws/src/rmcs_core/src/referee/app/ui/auto_aim.cpp`:
- Around line 66-71: The clamp_x and clamp_y lambdas in auto_aim.cpp are
clamping in uint16_t, which can wrap negative int values to the screen maximum
instead of 0. Update these helpers to first call std::clamp on the int input
using an int range, then cast the clamped result to std::uint16_t so negative
coordinates stay pinned to the left/top edge.

In `@rmcs_ws/src/rmcs_executor/CMakeLists.txt`:
- Around line 6-7: The CMakeLists.txt currently only sets the C++23 standard,
but it does not enforce the minimum compiler/standard library versions needed
for std::expected and std::format. Update the build configuration around
CMAKE_CXX_STANDARD/CMAKE_CXX_STANDARD_REQUIRED to also validate the toolchain
(for example in the rmcs_executor target or top-level CMake logic) and fail
early unless GCC/libstdc++ or libc++ meets the required minimum versions. Add
the same requirement to CI checks so the build cannot proceed on unsupported
environments.

---

Nitpick comments:
In `@rmcs_ws/src/rmcs_executor/src/executor.hpp`:
- Around line 224-231: The issue is in log_due_reports, where the while loop can
emit the same cumulative stats multiple times when current_time is far behind
stats.next_report_time. Update the catch-up logic in log_due_reports so it
advances stats.next_report_time across missed 5s intervals without repeatedly
calling log_cumulative_stats for empty windows, or otherwise ensure only one
cumulative log is produced per actual report cycle while still preserving the
window reset behavior.
🪄 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: 24865d3a-6280-4160-bdc3-37c7f83e3ab7

📥 Commits

Reviewing files that changed from the base of the PR and between 57eec77 and a45e3f9.

📒 Files selected for processing (9)
  • rmcs_ws/src/rmcs_bringup/config/flight.yaml
  • rmcs_ws/src/rmcs_core/plugins.xml
  • rmcs_ws/src/rmcs_core/src/referee/app/ui/auto_aim.cpp
  • rmcs_ws/src/rmcs_executor/CMakeLists.txt
  • rmcs_ws/src/rmcs_executor/src/executor.hpp
  • rmcs_ws/src/rmcs_executor/src/main.cpp
  • rmcs_ws/src/rmcs_utility/CMakeLists.txt
  • rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp
  • rmcs_ws/src/rmcs_utility/include/rmcs_utility/thread_config.hpp

Comment on lines +66 to +71
constexpr auto clamp_x = [](int x) {
return std::clamp<std::uint16_t>(x, 0, kScreenW - 1);
};
constexpr auto clamp_y = [](int y) {
return std::clamp<std::uint16_t>(y, 0, kScreenH - 1);
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 确认 clamp 辅助函数的调用方确实会产生负实参
sed -n '62,105p' rmcs_ws/src/rmcs_core/src/referee/app/ui/auto_aim.cpp

Repository: Alliance-Algorithm/RMCS

Length of output: 1998


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the file and inspect the relevant region with line numbers.
git ls-files 'rmcs_ws/src/rmcs_core/src/referee/app/ui/auto_aim.cpp'
echo '---'
cat -n rmcs_ws/src/rmcs_core/src/referee/app/ui/auto_aim.cpp | sed -n '62,105p'
echo '---'
# Show all clamp_x/clamp_y references in the file for call-site context.
rg -n 'clamp_[xy]\(' rmcs_ws/src/rmcs_core/src/referee/app/ui/auto_aim.cpp

Repository: Alliance-Algorithm/RMCS

Length of output: 1969


先在 int 域内 clamp,避免负坐标回绕到屏幕最大边缘 std::clamp<std::uint16_t> 会先把 int 实参转成 uint16_t,所以靠近左上角时的负值会被夹到上界而不是 0。改成先 std::clamp(x, 0, ...),再转换为 uint16_t

🤖 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 `@rmcs_ws/src/rmcs_core/src/referee/app/ui/auto_aim.cpp` around lines 66 - 71,
The clamp_x and clamp_y lambdas in auto_aim.cpp are clamping in uint16_t, which
can wrap negative int values to the screen maximum instead of 0. Update these
helpers to first call std::clamp on the int input using an int range, then cast
the clamped result to std::uint16_t so negative coordinates stay pinned to the
left/top edge.

Comment on lines +6 to +7
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

minimum GCC and Clang versions for std::expected and std::format support

💡 Result:

The availability of std::expected and std::format depends primarily on the underlying standard library (libstdc++ for GCC, libc++ for Clang) rather than the compiler executable itself. std::format (C++20) - GCC: Supported starting with GCC 13 (via libstdc++) [1][2]. - Clang: Supported starting with Clang 14 when using libc++ [2]. Note that Clang users often encounter issues when using older versions of libstdc++; using -stdlib=libc++ is recommended for best compatibility [3][2][4]. std::expected (C++23) - GCC: Supported starting with GCC 13 (via libstdc++) [5]. - Clang: Supported in libc++ (the LLVM C++ standard library) [6]. Be aware that Clang often defaults to using the host system's libstdc++ (e.g., from an older GCC installation), which may lack support for C++23 features like std::expected even if the Clang version is modern [3][7][8]. Explicitly configuring Clang to use libc++ with the -stdlib=libc++ flag is often required to access this feature [3][7][8]. General Requirements For both features, you must compile with the appropriate C++ standard flag (e.g., -std=c++20 or -std=c++23) [9][2]. If you are using Clang and encounter "header not found" or "no template named" errors despite having a modern Clang version, it is typically because the linked standard library (often libstdc++) is outdated [3][8][4]. Switching to libc++ is the standard solution for Clang users on Linux to ensure compatibility with modern C++ library features [8][2].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the target CMake file and the headers mentioned in the comment.
for f in \
  rmcs_ws/src/rmcs_executor/CMakeLists.txt \
  rmcs_ws/src/rmcs_executor/include/thread_config.hpp \
  rmcs_ws/src/rmcs_executor/include/executor.hpp
do
  echo "===== $f ====="
  wc -l "$f"
  echo
done

echo "===== CMakeLists ====="
cat -n rmcs_ws/src/rmcs_executor/CMakeLists.txt

echo
echo "===== thread_config.hpp (relevant lines) ====="
rg -n "std::expected|std::format|`#include`" rmcs_ws/src/rmcs_executor/include/thread_config.hpp

echo
echo "===== executor.hpp (relevant lines) ====="
rg -n "std::expected|std::format|`#include`" rmcs_ws/src/rmcs_executor/include/executor.hpp

echo
echo "===== package metadata mentions ====="
rg -n "ubuntu|jammy|focal|humble|iron|jazzy|gcc|clang|c\\+\\+23|c\\+\\+20|std::expected|std::format" rmcs_ws/src/rmcs_executor -g '!**/build/**' -g '!**/install/**' -g '!**/log/**'

Repository: Alliance-Algorithm/RMCS

Length of output: 1969


🌐 Web query:

libc++ std::expected minimum version and libstdc++ std::expected GCC version; libc++ std::format minimum version and libstdc++ std::format GCC version

💡 Result:

Support for std::expected and std::format in libc++ and libstdc++ is as follows: libc++: - std::expected: First released in libc++ 16.0 [1]. - std::format: First released in libc++ 14.0 (as part of the C++20 format library implementation) [2][3]. libstdc++: - std::expected: First supported in GCC 12 (libstdc++) [4][5]. - std::format: First supported in GCC 13 (libstdc++) [6]. Note: For both libraries, these features require compiling with appropriate C++ standard flags (typically -std=c++23 for std::expected and -std=c++20 or later for std::format) [4][6]. Earlier versions of libc++ required the -fexperimental-library flag to enable these features before they were considered stable [1][7].

Citations:


补充 C++23 标准库最低版本约束
std::expected 需要 libstdc++(GCC 12+) 或 libc++ 16+,std::format 需要 libstdc++(GCC 13+) 或 libc++ 14+。Ubuntu 22.04 默认 GCC 11/libstdc++ 不满足要求,CI 和部署镜像若不升级编译器/标准库会直接编译失败;建议把最低工具链版本写入构建约束或 CI 检查中。

🤖 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 `@rmcs_ws/src/rmcs_executor/CMakeLists.txt` around lines 6 - 7, The
CMakeLists.txt currently only sets the C++23 standard, but it does not enforce
the minimum compiler/standard library versions needed for std::expected and
std::format. Update the build configuration around
CMAKE_CXX_STANDARD/CMAKE_CXX_STANDARD_REQUIRED to also validate the toolchain
(for example in the rmcs_executor target or top-level CMake logic) and fail
early unless GCC/libstdc++ or libc++ meets the required minimum versions. Add
the same requirement to CI checks so the build cannot proceed on unsupported
environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants