Skip to content

适配VT13#4

Merged
llLeo306 merged 2 commits intoQDU-Robomaster:devfrom
Rui-Xiaoyu:master-offline-merge
Apr 13, 2026
Merged

适配VT13#4
llLeo306 merged 2 commits intoQDU-Robomaster:devfrom
Rui-Xiaoyu:master-offline-merge

Conversation

@Rui-Xiaoyu
Copy link
Copy Markdown
Contributor

@Rui-Xiaoyu Rui-Xiaoyu commented Apr 13, 2026

Summary by Sourcery

Add support for multiple RC input sources and centralize selection logic for command processing.

New Features:

  • Introduce an RC input source enumeration to distinguish between DR16 and VT13 remote controllers.
  • Add input source–aware RC feeding API while keeping a backward-compatible default interface.
  • Implement logic to select the active RC input source based on online status and activity thresholds, with automatic fallback when sources go offline.

Enhancements:

  • Refactor command processing to use selected RC data while maintaining existing AI blending behavior.
  • Improve encapsulation by adding helper utilities for RC input online/activity checks and offline defaults.
  • Clean up includes and consistently qualify member access within the CMD application class.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 13, 2026

Reviewer's Guide

Add VT13 as an additional RC input source and introduce logic to select and track the active RC source while refactoring CMD to store RC inputs per source and updating processing/publish logic accordingly.

Sequence diagram for RC multi-source input selection and publishing

sequenceDiagram
    participant RC_DR16
    participant RC_VT13
    participant CMD
    participant LibXR_Event as Event
    participant Topic_Chassis as ChassisTopic
    participant Topic_Gimbal as GimbalTopic
    participant Topic_Fire as FireTopic

    RC_DR16->>CMD: FeedRC(Data rc_dr16)
    activate CMD
    CMD->>CMD: FeedRC(RCInputSource_RC_INPUT_DR16, rc_dr16)
    CMD->>CMD: rc_input_data_[DR16] = rc_dr16
    CMD->>CMD: rc_input_seq_[DR16] = ++rc_update_seq_
    CMD->>CMD: IsRCInputActive(rc_dr16)
    alt DR16 data is active and online
        CMD->>CMD: active_rc_input_ = RC_INPUT_DR16
    end
    CMD->>CMD: ProcessAndPublish()
    deactivate CMD

    RC_VT13->>CMD: FeedRC(RCInputSource_RC_INPUT_VT13, Data rc_vt13)
    activate CMD
    CMD->>CMD: rc_input_data_[VT13] = rc_vt13
    CMD->>CMD: rc_input_seq_[VT13] = ++rc_update_seq_
    CMD->>CMD: IsRCInputActive(rc_vt13)
    alt VT13 data is active and online
        CMD->>CMD: active_rc_input_ = RC_INPUT_VT13
    end
    CMD->>CMD: ProcessAndPublish()

    CMD->>CMD: SelectRCData()
    alt active_rc_input_ online
        CMD->>CMD: use rc_input_data_[active]
    else active source offline
        alt other source online
            CMD->>CMD: switch active_rc_input_ to other source
            CMD->>CMD: use rc_input_data_[new_active]
        else both offline
            CMD->>CMD: MakeOfflineRCData()
        end
    end

    CMD->>CMD: update data_[CTRL_SOURCE_RC]

    alt RC offline and was online
        CMD->>Event: Active(CMD_EVENT_LOST_CTRL)
    else RC online and was offline
        CMD->>Event: Active(CMD_EVENT_START_CTRL)
    end

    alt mode_ == CMD_OP_CTRL
        CMD->>GimbalTopic: Publish(rc_selected.gimbal)
        CMD->>ChassisTopic: Publish(rc_selected.chassis)
        CMD->>FireTopic: Publish(rc_selected.launcher)
    else mode_ == CMD_AUTO_CTRL
        CMD->>CMD: choose ai or rc for chassis/gimbal/launcher
        CMD->>GimbalTopic: Publish(out_gimbal)
        CMD->>ChassisTopic: Publish(out_chassis)
        CMD->>FireTopic: Publish(out_launcher)
    end
    deactivate CMD
Loading

Updated class diagram for CMD RC multi-input handling

classDiagram
    class LibXR_Application

    class Data
      Data : bool chassis_online
      Data : bool gimbal_online
      Data : ControlSource ctrl_source
      Data : ChassisCMD chassis
      Data : GimbalCMD gimbal
      Data : LauncherCMD launcher

    class ChassisCMD
    class GimbalCMD
    class LauncherCMD

    class LibXR_Event
      LibXR_Event : Active(uint32_t event_id)
      LibXR_Event : Register(uint32_t event_id, Callback_uint32_t callback)

    class LibXR_Topic
      LibXR_Topic : Publish(ChassisCMD chassis)
      LibXR_Topic : Publish(GimbalCMD gimbal)
      LibXR_Topic : Publish(LauncherCMD launcher)

    class CMD
      CMD : Mode mode_
      CMD : bool online_
      CMD : LibXR_Event cmd_event_
      CMD : array~Data~ data_
      CMD : array~Data~ rc_input_data_
      CMD : array~uint32_t~ rc_input_seq_
      CMD : LibXR_Topic chassis_data_tp_
      CMD : LibXR_Topic gimbal_data_tp_
      CMD : LibXR_Topic fire_data_tp_
      CMD : LibXR_Topic host_euler_data_tp_
      CMD : RCInputSource active_rc_input_
      CMD : uint32_t rc_update_seq_
      CMD : FeedRC(Data rc_data)
      CMD : FeedRC(RCInputSource source, Data rc_data)
      CMD : FeedAI(Data ai_data)
      CMD : Init(void* hw, void* app)
      CMD : EventHandler(uint32_t event_id)
      CMD : ProcessAndPublish()
      CMD : Data SelectRCData()
      CMD : static bool IsRCInputOnline(Data rc_data)
      CMD : static bool IsRCInputActive(Data rc_data)
      CMD : static Data MakeOfflineRCData()

    class ControlSource {
      <<enum>>
      ControlSource : CTRL_SOURCE_RC
      ControlSource : CTRL_SOURCE_AI
      ControlSource : CTRL_SOURCE_NUM
    }

    class RCInputSource {
      <<enum>>
      RCInputSource : RC_INPUT_DR16
      RCInputSource : RC_INPUT_VT13
      RCInputSource : RC_INPUT_NUM
    }

    class Mode {
      <<enum>>
      Mode : CMD_OP_CTRL
      Mode : CMD_AUTO_CTRL
    }

    CMD --|> LibXR_Application
    CMD --> LibXR_Event : uses
    CMD --> LibXR_Topic : publishes
    CMD --> Data : processes
    Data --> ControlSource
    CMD --> RCInputSource
    CMD --> Mode
    Data --> ChassisCMD
    Data --> GimbalCMD
    Data --> LauncherCMD
Loading

File-Level Changes

Change Details Files
Support multiple RC input sources (DR16 and VT13) with active-source selection and fallback logic.
  • Introduce RCInputSource enum to represent DR16, VT13, and input count.
  • Add per-RC-input data and sequence arrays plus active_rc_input_ and rc_update_seq_ members.
  • Implement IsRCInputOnline, IsRCInputActive, MakeOfflineRCData, and SelectRCData helpers to manage online state and source switching.
  • Update ProcessAndPublish to obtain RC data via SelectRCData, mirror it into the RC control source slot, drive online/offline events based on selected RC, and keep AUTO vs OP control behavior unchanged.
CMD.hpp
Extend RC feeding API to handle different input sources while keeping backward compatibility.
  • Change existing FeedRC(Data) to delegate to a new FeedRC(RCInputSource, Data) overload defaulting to DR16.
  • In the new FeedRC overload, validate source index, store rc_data to the per-source buffer, update per-source sequence and global sequence, potentially update active_rc_input_ when the data is online and active, and then call ProcessAndPublish.
  • Adjust FeedAI to use explicit this-> qualifiers for consistency.
CMD.hpp
Minor refactors and includes to support new logic and code-style consistency.
  • Replace with and add for std::fabs usage, removing unused cycle_value.hpp include.
  • Use this-> qualification when accessing members inside CMD methods to improve clarity.
  • Tweak comments to shorter C-style comments for event callback registration and control mode handler.
CMD.hpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The rc_update_seq_ counter and rc_input_seq_ array are written but never read, which suggests incomplete or dead logic for choosing between multiple RC sources; either remove them or complete the selection logic to use the sequence information.
  • FeedRC(RCInputSource source, ...) silently returns on an invalid source_index; consider asserting or logging in this path so configuration or call-site errors are easier to detect.
  • In MakeOfflineRCData you always set ctrl_source to CTRL_SOURCE_RC even when the last active input might have been VT13; if ctrl_source is used downstream for telemetry or behavior decisions, you may want to reflect the specific RC input or explicitly mark it as offline/unknown instead.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `rc_update_seq_` counter and `rc_input_seq_` array are written but never read, which suggests incomplete or dead logic for choosing between multiple RC sources; either remove them or complete the selection logic to use the sequence information.
- `FeedRC(RCInputSource source, ...)` silently returns on an invalid `source_index`; consider asserting or logging in this path so configuration or call-site errors are easier to detect.
- In `MakeOfflineRCData` you always set `ctrl_source` to `CTRL_SOURCE_RC` even when the last active input might have been `VT13`; if `ctrl_source` is used downstream for telemetry or behavior decisions, you may want to reflect the specific RC input or explicitly mark it as offline/unknown instead.

## Individual Comments

### Comment 1
<location path="CMD.hpp" line_range="164" />
<code_context>
+    }
+
+    this->rc_input_data_[source_index] = rc_data;
+    this->rc_input_seq_[source_index] = ++this->rc_update_seq_;
+
+    if (rc_data.chassis_online && this->IsRCInputActive(rc_data)) {
</code_context>
<issue_to_address>
**suggestion (bug_risk):** rc_input_seq_/rc_update_seq_ are written here but not used in selection, which may indicate either dead state or a missed use in RC source arbitration.

In this header, rc_input_seq_ and rc_update_seq_ are only written in FeedRC and never read (including in SelectRCData). If recency is meant to influence RC source arbitration (e.g., for tie‑breaking), that logic is missing. If recency isn’t needed, consider removing this sequence tracking to avoid dead state and confusion about intent.

Suggested implementation:

```
  /**
   * @brief 按遥控输入源写入控制数据
   */
  void FeedRC(RCInputSource source, const Data& rc_data) {
    const auto source_index = static_cast<size_t>(source);
    if (source_index >= static_cast<size_t>(RCInputSource::RC_INPUT_NUM)) {
      return;
    }

    this->rc_input_data_[source_index] = rc_data;

    if (rc_data.chassis_online && this->IsRCInputActive(rc_data)) {
      this->active_rc_input_ = source;
    }

    this->ProcessAndPublish();
  }

  /**
   * @brief 直接写入 AI 控制数据
   */
  void FeedAI(const Data& ai_data) {

```

1. Remove the `rc_input_seq_` and `rc_update_seq_` member variables from the class definition in CMD.hpp (or its corresponding header), including any initialization in the constructor.
2. Remove any other writes to `rc_input_seq_` / `rc_update_seq_` if they exist elsewhere.
3. If there are comments or documentation referring to RC input sequencing/recency, update or remove them to reflect that recency is no longer tracked.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread CMD.hpp
}

this->rc_input_data_[source_index] = rc_data;
this->rc_input_seq_[source_index] = ++this->rc_update_seq_;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): rc_input_seq_/rc_update_seq_ are written here but not used in selection, which may indicate either dead state or a missed use in RC source arbitration.

In this header, rc_input_seq_ and rc_update_seq_ are only written in FeedRC and never read (including in SelectRCData). If recency is meant to influence RC source arbitration (e.g., for tie‑breaking), that logic is missing. If recency isn’t needed, consider removing this sequence tracking to avoid dead state and confusion about intent.

Suggested implementation:

  /**
   * @brief 按遥控输入源写入控制数据
   */
  void FeedRC(RCInputSource source, const Data& rc_data) {
    const auto source_index = static_cast<size_t>(source);
    if (source_index >= static_cast<size_t>(RCInputSource::RC_INPUT_NUM)) {
      return;
    }

    this->rc_input_data_[source_index] = rc_data;

    if (rc_data.chassis_online && this->IsRCInputActive(rc_data)) {
      this->active_rc_input_ = source;
    }

    this->ProcessAndPublish();
  }

  /**
   * @brief 直接写入 AI 控制数据
   */
  void FeedAI(const Data& ai_data) {

  1. Remove the rc_input_seq_ and rc_update_seq_ member variables from the class definition in CMD.hpp (or its corresponding header), including any initialization in the constructor.
  2. Remove any other writes to rc_input_seq_ / rc_update_seq_ if they exist elsewhere.
  3. If there are comments or documentation referring to RC input sequencing/recency, update or remove them to reflect that recency is no longer tracked.

@llLeo306 llLeo306 merged commit bfcfbc0 into QDU-Robomaster:dev Apr 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants