Skip to content

Gimbal: Use delta_yaw in heading calc when provided rather than vehicle - #14865

Open
jnomikos wants to merge 6 commits into
mavlink:masterfrom
jnomikos:john-delta-yaw
Open

Gimbal: Use delta_yaw in heading calc when provided rather than vehicle#14865
jnomikos wants to merge 6 commits into
mavlink:masterfrom
jnomikos:john-delta-yaw

Conversation

@jnomikos

@jnomikos jnomikos commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Description

Some gimbals have a seperate mag/compass to the vehicle and may provide delta_yaw. For these specific gimbals, utilizing delta_yaw is better than basing gimbal yaw on vehicle heading, because it removes the risk of inaccuracy if the gimbal's sensor readings differ from vehicle. A gimbal device maintains its own yaw estimate, which can differ from the vehicle's heading.

Motivation: The Pixy LR gimbal when sending the GIMBAL_DEVICE_ATTITUDE_STATUS message always gives YAW_IN_VEHICLE_FRAME, regardless of if follow/lock. When tested indoors and utilizing vehicle heading in the yaw calculation, switching between follow to lock causes the gimbal to move. Utilizing delta_yaw fixes this.

Related PR: ArduPilot/ardupilot#33870

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/Build changes
  • Other

Testing

  • Tested locally
  • Added/updated unit tests
  • Tested with simulator (SITL)
  • Tested with hardware

Platforms Tested

  • Linux
  • Windows
  • macOS
  • Android
  • iOS

Flight Stacks Tested

Tested with Gremsy Pixy LR gimbal on v7.8.7 with my ArduPilot PR. Without my change, switching from follow to lock causes the gimbal to shift and not maintain yaw. With my change, this issue disappears.

PX4 still needs testing, but should work already because it forwards delta_yaw from the gimbal in GIMBAL_DEVICE_ATTITUDE_STATUS already.

Screenshots

Checklist

  • I have read the Contribution Guidelines
  • I have read the Code of Conduct
  • My code follows the project's coding standards
  • I have added tests that prove my fix/feature works
  • New and existing unit tests pass locally

Related Issues


By submitting this pull request, I confirm that my contribution is made under the terms of the project's dual license (Apache 2.0 and GPL v3).

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.25000% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.77%. Comparing base (f29efd3) to head (9cebea8).
⚠️ Report is 290 commits behind head on master.

Files with missing lines Patch % Lines
src/Gimbal/GimbalController.cc 20.00% 3 Missing and 5 partials ⚠️
src/Gimbal/Gimbal.cc 33.33% 1 Missing and 1 partial ⚠️
src/Gimbal/Gimbal.h 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14865      +/-   ##
==========================================
+ Coverage   25.47%   33.77%   +8.30%     
==========================================
  Files         769      933     +164     
  Lines       65912    84623   +18711     
  Branches    30495    39123    +8628     
==========================================
+ Hits        16788    28580   +11792     
+ Misses      37285    36841     -444     
- Partials    11839    19202    +7363     
Flag Coverage Δ
unittests 33.77% <31.25%> (+8.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/Comms/MockLink/MockLinkGimbal.cc 50.52% <ø> (+4.21%) ⬆️
src/Gimbal/Gimbal.h 48.27% <66.66%> (+17.50%) ⬆️
src/Gimbal/Gimbal.cc 30.35% <33.33%> (-1.72%) ⬇️
src/Gimbal/GimbalController.cc 22.34% <20.00%> (-0.13%) ⬇️

... and 635 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1f0d6a...9cebea8. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Build Results

Platform Status

Platform Status Details
Linux Passed View
Windows Passed View
MacOS Passed View
Android Passed View

All builds passed.

Pre-commit

Check Status Details
pre-commit Failed (non-blocking) View

Pre-commit hooks: 2 passed, 75 failed, 7 skipped.

Test Results

linux-coverage-integration: 43 passed, 0 skipped
linux-coverage-unit: 132 passed, 0 skipped
linux-sanitizers-integration: 25 passed, 0 skipped
linux-sanitizers-unit: 132 passed, 0 skipped
Total: 332 passed, 0 skipped

Code Coverage

Coverage: 69.5%

No baseline available for comparison

Artifact Sizes

Artifact Size
QGroundControl 252.62 MB
QGroundControl-aarch64 176.50 MB
QGroundControl-installer-AMD64 137.92 MB
QGroundControl-installer-AMD64-ARM64 80.43 MB
QGroundControl-installer-ARM64 109.17 MB
QGroundControl-linux 84.51 MB
QGroundControl-mac 84.50 MB
QGroundControl-x86_64 188.75 MB
No baseline available for comparison

Updated: 2026-08-14 21:37:46 UTC • Commit: 9cebea8 • Triggered by: Windows

@jnomikos
jnomikos marked this pull request as ready for review August 14, 2026 17:11
Copilot AI balanced review requested due to automatic review settings August 14, 2026 17:11

Copilot AI left a comment

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.

Pull request overview

Uses gimbal-provided delta_yaw when available to improve body/earth yaw-frame conversions.

Changes:

  • Adds delta-yaw telemetry as a Fact.
  • Detects and stores supported delta_yaw values.
  • Uses delta yaw instead of vehicle heading for yaw calculations.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/Gimbal/GimbalFact.json Defines delta-yaw metadata.
src/Gimbal/GimbalController.cc Consumes delta yaw and converts yaw frames.
src/Gimbal/Gimbal.h Exposes and stores the delta-yaw Fact.
src/Gimbal/Gimbal.cc Initializes and copies delta-yaw state.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

gimbal->setAbsoluteRoll(qRadiansToDegrees(roll));
gimbal->setAbsolutePitch(qRadiansToDegrees(pitch));

const float deltaYawDeg = qRadiansToDegrees(attitude_status.delta_yaw);
Comment thread src/Gimbal/GimbalController.cc Outdated
Comment thread src/Gimbal/GimbalController.cc Outdated
Comment thread src/Gimbal/GimbalController.cc Outdated
Comment thread src/Gimbal/GimbalController.cc Outdated
- Some gimbals have a seperate mag/compass to the vehicle and may provide delta_yaw.
- For these specific gimbals, utilizing delta_yaw is better than basing gimbal setpoint on vehicle heading, because it removes the risk of drift if the gimbal's sensor readings differ from vehicle.
- A gimbal device maintains its own yaw estimate, which can differ from the vehicle's heading.
@jnomikos
jnomikos marked this pull request as draft August 14, 2026 17:29
- Fixes edge case where if deltaYaw WAS valid, went NAN and then became
  valid again (by sending exactly 0.0), we would not consider it valid.
@jnomikos
jnomikos marked this pull request as ready for review August 14, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants