Skip to content

格式化代码#2

Merged
llLeo306 merged 3 commits intomasterfrom
dev
Apr 10, 2026
Merged

格式化代码#2
llLeo306 merged 3 commits intomasterfrom
dev

Conversation

@llLeo306
Copy link
Copy Markdown
Contributor

@llLeo306 llLeo306 commented Apr 10, 2026

Summary by Sourcery

Update host data handling to consume full gimbal state (angles, angular rates, and accelerations) and propagate this richer information into host commands.

New Features:

  • Introduce a HostGimbalTarget structure encapsulating gimbal angles, angular velocities, and accelerations.
  • Extend host gimbal command data to include pitch/yaw rates and accelerations derived from incoming gimbal state.

Enhancements:

  • Switch gimbal topic from raw Euler angles to the new HostGimbalTarget payload and map it to Euler, gyro, and acceleration state inside HostData.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 10, 2026

Reviewer's Guide

Refactors HostData to subscribe to a richer gimbal target topic (position, velocity, acceleration) instead of a simple Euler-angle topic, wiring the additional data into HostCMD and updating member types and callbacks accordingly.

Sequence diagram for updated gimbal topic handling in HostData

sequenceDiagram
  participant Topic as host_gimbal_data_tp_
  participant ISR as LibXR_ISR
  participant Host as HostData
  participant CMD as CMD

  Topic->>ISR: OnDataReceived(raw_data)
  ISR->>Host: euler_callback(in_isr, Host, raw_data)
  activate Host
  Host->>Host: LibXR::Memory::FastCopy(t, raw_data.addr_, sizeof(t))
  Host->>Host: host_euler_ = LibXR::EulerAngle(t.rol, t.pit, t.yaw)
  Host->>Host: host_gyro_ = Eigen::Matrix( t.rol_dot, t.pit_dot, t.yaw_dot )
  Host->>Host: host_accl_ = Eigen::Matrix( t.rol_ddot, t.pit_ddot, t.yaw_ddot )
  Host->>Host: last_gimbal_time_ = LibXR::Timebase::GetMilliseconds()
  Host->>Host: HostCMD(in_isr)
  Host->>CMD: update host_cmd.gimbal (pos, vel, accel)
  deactivate Host
Loading

Updated class diagram for HostData gimbal subscription refactor

classDiagram
  class HostData {
    +HostData(LibXR::HardwareContainer& hw, LibXR::ApplicationManager& app, CMD& cmd, const char* host_gimbal_topic_name, const char* host_chassis_data_topic_name, const char* host_fire_topic_name)
    +void HostCMD(bool in_isr)
    -CMD* cmd_
    -ChassisCMD host_chassis_target_
    -LauncherCMD host_fire_notify_
    -LibXR::EulerAngle~float~ host_euler_
    -Eigen::Matrix~float,3,1~ host_gyro_
    -Eigen::Matrix~float,3,1~ host_accl_
    -uint32_t last_gimbal_time_
    -LibXR::Topic host_gimbal_data_tp_
    -LibXR::Topic host_chassis_data_tp_
    -LibXR::Topic host_fire_notify_tp_
  }

  class HostChassisTarget {
    +float vx
    +float vy
    +float wz
    +bool isfire
  }

  class HostGimbalTarget {
    +float rol
    +float pit
    +float yaw
    +float rol_dot
    +float pit_dot
    +float yaw_dot
    +float rol_ddot
    +float pit_ddot
    +float yaw_ddot
  }

  class CMD {
    +HostCMDData host_cmd
  }

  class HostCMDData {
    +GimbalTarget gimbal
    +bool gimbal_online
  }

  class GimbalTarget {
    +float rol
    +float pit
    +float yaw
    +float rol_dot
    +float pit_dot
    +float yaw_dot
    +float rol_ddot
    +float pit_ddot
    +float yaw_ddot
  }

  HostData --> HostChassisTarget : publishes
  HostData --> HostGimbalTarget : subscribes
  HostData --> CMD : updates
  CMD --> HostCMDData : owns
  HostCMDData --> GimbalTarget : has
Loading

File-Level Changes

Change Details Files
Switch gimbal input from a raw EulerAngle topic to a structured HostGimbalTarget carrying angles, angular rates, and angular accelerations, and propagate these into HostCMD.
  • Introduce HostGimbalTarget struct containing roll/pitch/yaw plus their first and second derivatives.
  • Update HostData constructor to take a gimbal-topic name, create a HostGimbalTarget topic, and register the existing gimbal callback on it.
  • Change the gimbal callback to copy from raw data into a HostGimbalTarget instance, then derive host_euler_, host_gyro_, and host_accl_ from it and update last_gimbal_time_.
  • Extend HostCMD filling logic to populate additional gimbal derivative fields (pit_dot, pit_ddot, yaw_dot, yaw_ddot) from host_gyro_ and host_accl_, and expand the zero-initialization for the offline case to cover all fields.
  • Add host_gyro_ and host_accl_ Eigen vectors as HostData members initialized to zero, and rename the topic member from host_euler_data_tp_ to host_gimbal_data_tp_.
  • Remove unused DATA_TIMEOUT_MS constant from HostData.
HostData.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 left some high level feedback:

  • Now that the topic and payload have been generalized to a full gimbal state (HostGimbalTarget), consider renaming variables like host_euler_ and euler_callback to reflect that they carry position, velocity, and acceleration, to keep the intent of the data clear.
  • Because HostGimbalTarget is being memcpy’d from raw bytes, it would be safer to explicitly control or assert its layout (e.g., static_assert(sizeof(HostGimbalTarget) == expected_size) or using a packed/standard-layout type) to avoid issues from padding or alignment changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that the topic and payload have been generalized to a full gimbal state (`HostGimbalTarget`), consider renaming variables like `host_euler_` and `euler_callback` to reflect that they carry position, velocity, and acceleration, to keep the intent of the data clear.
- Because `HostGimbalTarget` is being memcpy’d from raw bytes, it would be safer to explicitly control or assert its layout (e.g., `static_assert(sizeof(HostGimbalTarget) == expected_size)` or using a packed/standard-layout type) to avoid issues from padding or alignment changes.

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.

@llLeo306 llLeo306 merged commit b621199 into master Apr 10, 2026
2 of 3 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