Skip to content

vt13 test#78

Open
qzhhhi wants to merge 4 commits into
mainfrom
dev/vt13-test
Open

vt13 test#78
qzhhhi wants to merge 4 commits into
mainfrom
dev/vt13-test

Conversation

@qzhhhi
Copy link
Copy Markdown
Member

@qzhhhi qzhhhi commented May 20, 2026

概述

本PR进行了硬件架构的重构和升级,主要包括:移除了多个旧的机器人硬件组件实现;新增了遥控器设备驱动(Vt13和RemoteControl),支持新型遥控系统;调整了Dr16类的API接口和实现机制;更新了底层库依赖版本;同时扩展了环形缓冲区的功能。

核心变更

新增遥控器驱动支持

  • 新增Vt13类rmcs_core/src/hardware/device/vt13.hpp):实现新型遥控器设备的UART数据接收与解析,支持遥控数据帧和裁判系统数据帧的CRC校验,管理模式切换、鼠标和键盘状态
  • 新增RemoteControl类rmcs_core/src/hardware/device/remote_control.hpp):统一封装遥控器输出接口,根据Vt13的模式切换动态选择从Dr16或Vt13读取鼠标/键盘数据

Dr16类重构

  • API调整:将构造函数从显式接收Component参数改为默认构造;修改store_status()参数格式,由指针+长度改为std::span
  • 返回类型变更:摇杆返回值由按值返回改为const引用返回;增加noexcept修饰符
  • 内部实现优化:数据解析逻辑分离为store_status()(存储原始数据)和update_status()(更新状态),提高线程安全性
  • 移除公开类型:删除了Vector、Switch、Mouse、Keyboard等公开嵌套类型

硬件组件精简

移除了以下过时的硬件组件实现:

  • DeformableInfantryOmnideformable-infantry-omni.cpp
  • DeformableInfantryV2deformable-infantry-steering.cpp
  • Sentrysentry.cpp
  • SteeringInfantrysteering-infantry.cpp

OmniInfantry更新

  • 底层板卡实现从librmcs::agent::CBoard升级为librmcs::agent::RmcsBoardLite
  • 集成新的Vt13和RemoteControl驱动
  • 调整UART数据接收流程,新增uart0通道用于Vt13数据接收

依赖库升级

更新CMakeLists.txt中librmcs的版本从v3.1.0升级至v3.2.0rc0,同步更新SHA256校验值

工具库扩展

RingBuffer<T>中新增peek_front_n()方法,支持批量窥视缓冲区中的元素,用于数据处理优化

影响范围

  • 删除代码量:约4686行(多个完整的硬件组件文件)
  • 新增代码量:约329行(两个新的设备驱动类)
  • 修改文件:Dr16、OmniInfantry等关键硬件驱动
  • API破坏性变更:Dr16的构造函数、store_status()和多个getter方法发生了变更,依赖代码需要更新

Review Change Stack

@qzhhhi
Copy link
Copy Markdown
Member Author

qzhhhi commented May 20, 2026

@coderabbitai pause

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Note

Reviews paused

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

该 PR 重构遥控器设备抽象架构,将耦合的 Dr16 分解为独立设备层;新增 Vt13 协议设备,引入 RemoteControl 管理层统一输出注册和状态路由;升级 librmcs 依赖,更新 OmniInfantry 整合新架构和 RmcsBoardLite 板卡;增强 RingBuffer 工具类。同时删除多个过时的机器人硬件实现。

Changes

Remote Control Device Abstraction Refactoring

Layer / File(s) Summary
Dr16 device refactoring and decoupling
rmcs_ws/src/rmcs_core/src/hardware/device/dr16.hpp
Dr16 解耦于 rmcs_executor::Component:构造函数变为 default,store_status 改为 std::span 接口并使用原子缓存,update_status 仅更新内部状态不再写输出,所有 getter 返回 const 引用并标记 noexcept,删除 Vector/Switch/Mouse/Keyboard 等公开嵌套类型。
Vt13 protocol device implementation
rmcs_ws/src/rmcs_core/src/hardware/device/vt13.hpp
新增 Vt13 类从固定容量环形缓冲区解析遥控器与裁判风格两类协议帧:store_status 写入 UART 字节,update_status 按帧类型分派并用 std::variant 处理不完整/校验失败/成功三种结果,执行 CRC 校验和帧长计算,提供模式切换、鼠标、键盘等状态访问器。
RemoteControl output manager and mode routing
rmcs_ws/src/rmcs_core/src/hardware/device/remote_control.hpp
新增 RemoteControl 类向 Component 注册摇杆、开关、旋钮、鼠标、键盘输出接口;update() 依据 Vt13 模式判定从 Vt13 或 Dr16 路由鼠标/键盘数据,电影模式下强制开关为 DOWN,旋钮始终从 Dr16 读取。
OmniInfantry board and remote control integration
rmcs_ws/src/rmcs_core/src/hardware/omni_infantry.cpp
OmniInfantry 从 CBoard 改为 RmcsBoardLite 私有继承,新增 Vt13 和 RemoteControl 成员初始化绑定;新建 uart0_receive_callback 路由数据到 Vt13,update() 调用 Vt13 和 RemoteControl 更新,dr16 store_status 参数改为 span 形式,CAN/UART 发送初始化展开为多行明确格式。
librmcs dependency version update
rmcs_ws/src/rmcs_core/CMakeLists.txt
FetchContent librmcs 版本从 v3.1.0 升级至 v3.2.0rc0,更新对应 SHA256 哈希值。

Utility Enhancement and Hardware Consolidation

Layer / File(s) Summary
RingBuffer peek_front_n non-destructive read interface
rmcs_ws/src/rmcs_utility/include/rmcs_utility/ring_buffer.hpp
RingBuffer 新增 peek_front_n 模板方法,在不销毁元素情况下对前部最多 count 个可读元素按 FIFO 顺序执行 void(T&) noexcept 回调;计算可读数量、裁剪 count、处理环形回绕分片、返回实际访问元素数。
Hardware component removals
rmcs_ws/src/rmcs_core/src/hardware/deformable-infantry-omni.cpp, rmcs_ws/src/rmcs_core/src/hardware/deformable-infantry-steering.cpp, rmcs_ws/src/rmcs_core/src/hardware/sentry.cpp, rmcs_ws/src/rmcs_core/src/hardware/steering-infantry.cpp
删除过时机器人硬件实现:DeformableInfantryOmni(769 行)、DeformableInfantryV2(876 行)、Sentry(500 行)、SteeringInfantry(537 行),包含各自的板卡控制、CAN/UART 回调、TF 变换、状态服务等逻辑及 PLUGINLIB_EXPORT_CLASS 导出声明。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 设备分离展新姿,Dr16 独立显轻盈,

Vt13 应声添协议,RemoteControl 统筹云门前,

OmniInfantry 穿新装,RmcsBoardLite 驾旧驹去,

遥控之塔重构时,架构清晰万事兴!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.63% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive PR标题'vt13 test'过于简陋,无法准确反映此次变更的实际内容。变更涉及删除多个硬件组件(OmniInfantry改造、删除多个Steering组件)、新增遥控器设备支持(Vt13、RemoteControl、Dr16重构)等重大更改,但标题未体现这些核心变化。 建议使用更具体的标题,如'Refactor remote control device handling and remove legacy hardware components'或类似表述,以准确概括此次大规模硬件架构变更的主要目标。
✅ 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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/vt13-test

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

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

🤖 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/hardware/device/dr16.hpp`:
- Around line 21-39: store_status currently publishes parts independently
(data_part1_, data_part2_, data_part3_), allowing readers in
dbus_receive_callback() / update() to observe a mixed-frame snapshot; change to
publish a consistent frame snapshot atomically by adding a version/seqlock or
double-buffer: e.g. introduce an atomic<uint32_t> status_seq_ (or seqlock) that
writers increment to an odd value before writing the three parts in store_status
and increment to even when done, and modify readers in
update()/dbus_receive_callback() to read status_seq_ before and after reading
data_part1_/data_part2_/data_part3_ and retry if the seq changed (or implement a
double-buffer struct and atomically swap a pointer to the completed buffer);
ensure kStatusSize checks remain and use the existing
data_part1_/data_part2_/data_part3_ storage but gate visibility via the new
sequence/atomic swap.

In `@rmcs_ws/src/rmcs_core/src/hardware/device/vt13.hpp`:
- Around line 178-187: 当前逻辑只在 readable < total_frame_size 时返回 Incomplete,当
header.data_length 导致 total_frame_size 超过本地环形缓冲区最大容量(data_buffer_
的容量)时会永远卡住坏帧头;请在计算 total_frame_size 后增加不可达上限检查(比较 data_buffer_.capacity()
或等效最大容量),如果 total_frame_size 超出容量则按 VerificationFailed 处理并丢弃该坏帧头(从 data_buffer_
弹出相应的头部字节以解除阻塞),确保引用的符号为
RefereeFrameHeader、header.data_length、total_frame_size、data_buffer_、Incomplete 和
VerificationFailed 以便定位修改点。
🪄 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: 00970d8c-0268-4961-b122-85e86ad35eb0

📥 Commits

Reviewing files that changed from the base of the PR and between 7578778 and cf635ff.

📒 Files selected for processing (11)
  • rmcs_ws/src/rmcs_core/CMakeLists.txt
  • rmcs_ws/src/rmcs_core/src/hardware/deformable-infantry-omni.cpp
  • rmcs_ws/src/rmcs_core/src/hardware/deformable-infantry-steering.cpp
  • rmcs_ws/src/rmcs_core/src/hardware/device/dr16.hpp
  • rmcs_ws/src/rmcs_core/src/hardware/device/remote_control.hpp
  • rmcs_ws/src/rmcs_core/src/hardware/device/vt13.hpp
  • rmcs_ws/src/rmcs_core/src/hardware/omni_infantry.cpp
  • rmcs_ws/src/rmcs_core/src/hardware/sentry.cpp
  • rmcs_ws/src/rmcs_core/src/hardware/steering-hero.cpp
  • rmcs_ws/src/rmcs_core/src/hardware/steering-infantry.cpp
  • rmcs_ws/src/rmcs_utility/include/rmcs_utility/ring_buffer.hpp
💤 Files with no reviewable changes (5)
  • rmcs_ws/src/rmcs_core/src/hardware/steering-hero.cpp
  • rmcs_ws/src/rmcs_core/src/hardware/deformable-infantry-steering.cpp
  • rmcs_ws/src/rmcs_core/src/hardware/steering-infantry.cpp
  • rmcs_ws/src/rmcs_core/src/hardware/sentry.cpp
  • rmcs_ws/src/rmcs_core/src/hardware/deformable-infantry-omni.cpp

Comment on lines +21 to 39
void store_status(std::span<const std::byte> uart_data) {
if (uart_data.size() != kStatusSize)
return;

// Avoid using reinterpret_cast here because it does not account for pointer alignment.
// Dr16DataPart structures are aligned, and using reinterpret_cast on potentially unaligned
// uart_data can cause undefined behavior on architectures that enforce strict alignment
// requirements (e.g., ARM).
// Directly accessing unaligned memory through a casted pointer can lead to crashes,
// inefficiencies, or incorrect data reads. Instead, std::memcpy safely copies the data from
// unaligned memory to properly aligned structures without violating alignment or strict
// aliasing rules.
auto* cursor = uart_data.data();

uint64_t part1{};
std::memcpy(&part1, uart_data, 6);
uart_data += 6;
std::memcpy(&part1, cursor, kPart1Size);
cursor += kPart1Size;
data_part1_.store(part1, std::memory_order::relaxed);

uint64_t part2{};
std::memcpy(&part2, uart_data, 8);
uart_data += 8;
std::memcpy(&part2, cursor, kPart2Size);
cursor += kPart2Size;
data_part2_.store(part2, std::memory_order::relaxed);

uint32_t part3{};
std::memcpy(&part3, uart_data, 4);
uart_data += 4;
std::memcpy(&part3, cursor, kPart3Size);
data_part3_.store(part3, std::memory_order::relaxed);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "检查 Dr16 的生产/消费路径:"
rg -n -C2 'dr16_\.store_status|dr16_\.update_status|dbus_receive_callback|update\(\) override' rmcs_ws/src/rmcs_core/src/hardware

echo
echo "检查 Dr16 是否存在帧级同步:"
rg -n -C2 'data_part[123]_\.store|data_part[123]_\.load|memory_order|sequence|version|mutex|lock_guard' rmcs_ws/src/rmcs_core/src/hardware/device/dr16.hpp

Repository: Alliance-Algorithm/RMCS

Length of output: 2758


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== OmniInfantry class definition ==="
rg -n "class OmniInfantry" rmcs_ws/src/rmcs_core/src/hardware/ -A 30

echo
echo "=== Check if dbus_receive_callback is called from interrupt/thread ==="
rg -n "dbus_receive_callback|register.*callback|set_callback" rmcs_ws/src/rmcs_core/src/hardware/ -B 2 -A 2

echo
echo "=== Check OmniInfantry initialization and threading ==="
rg -n "OmniInfantry\s*\(" rmcs_ws/src/rmcs_core/src/hardware/ -B 3 -A 5

echo
echo "=== Search for executor/thread pool ==="
rg -n "executor|thread_pool|thread|async|executor_" rmcs_ws/src/rmcs_core/src/hardware/omni_infantry.hpp -i

Repository: Alliance-Algorithm/RMCS

Length of output: 6176


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Search for RmcsBoardLite definition ==="
find . -type f \( -name "*.hpp" -o -name "*.h" \) | xargs rg -l "class RmcsBoardLite" 2>/dev/null | head -5

echo
echo "=== Search for where dbus_receive_callback registration happens ==="
rg -n "dbus_receive_callback|on_receive|RegisterCallback" rmcs_ws/src/rmcs_core/src/hardware/ -B 3 -A 3

echo
echo "=== Check if Component/executor provides thread safety guarantees ==="
find . -type f \( -name "*.hpp" -o -name "*.h" \) | xargs rg -l "class Component" | grep executor | head -3

echo
echo "=== Look for any synchronization in Dr16 class ==="
rg -n "class Dr16|private:|protected:" rmcs_ws/src/rmcs_core/src/hardware/device/dr16.hpp -A 20 | head -60

Repository: Alliance-Algorithm/RMCS

Length of output: 113


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Dr16 class full definition ==="
cat rmcs_ws/src/rmcs_core/src/hardware/device/dr16.hpp

echo
echo "=== Check surrounding context in omni_infantry.cpp ==="
sed -n '290,300p' rmcs_ws/src/rmcs_core/src/hardware/omni_infantry.cpp

echo
echo "=== Check update_status full implementation ==="
sed -n '42,80p' rmcs_ws/src/rmcs_core/src/hardware/device/dr16.hpp

echo
echo "=== Search for memory barriers or synchronization ==="
rg -n "acquire|release|seq_cst|barrier|fence" rmcs_ws/src/rmcs_core/src/hardware/device/

Repository: Alliance-Algorithm/RMCS

Length of output: 9647


不要把一帧状态拆成 3 个独立原子发布。

虽然单字段上没有竞争,但没有保证帧级一致性。由于 dbus_receive_callback()update() 运行在不同的执行上下文中,读者可能观察到摇杆、鼠标、键盘来自不同的帧(例如 part1 来自帧 N,part2/part3 来自帧 N+1)。应该使用版本号、seqlock 或双缓冲来一次性发布完整快照。

🤖 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/hardware/device/dr16.hpp` around lines 21 - 39,
store_status currently publishes parts independently (data_part1_, data_part2_,
data_part3_), allowing readers in dbus_receive_callback() / update() to observe
a mixed-frame snapshot; change to publish a consistent frame snapshot atomically
by adding a version/seqlock or double-buffer: e.g. introduce an atomic<uint32_t>
status_seq_ (or seqlock) that writers increment to an odd value before writing
the three parts in store_status and increment to even when done, and modify
readers in update()/dbus_receive_callback() to read status_seq_ before and after
reading data_part1_/data_part2_/data_part3_ and retry if the seq changed (or
implement a double-buffer struct and atomically swap a pointer to the completed
buffer); ensure kStatusSize checks remain and use the existing
data_part1_/data_part2_/data_part3_ storage but gate visibility via the new
sequence/atomic swap.

Comment thread rmcs_ws/src/rmcs_core/src/hardware/device/vt13.hpp
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

✅ Actions performed

Reviews paused.

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.

1 participant