Skip to content

feat(px4): add failure injection setup page - #14578

Open
Claudio-Chies wants to merge 8 commits into
mavlink:masterfrom
Claudio-Chies:cch/qgc-failure-injection
Open

feat(px4): add failure injection setup page#14578
Claudio-Chies wants to merge 8 commits into
mavlink:masterfrom
Claudio-Chies:cch/qgc-failure-injection

Conversation

@Claudio-Chies

Copy link
Copy Markdown
Contributor

Description

Failure injection support in PX4 is being refactored and expanded, with the eventual goal of using it for hardware flight testing — for example, validating system response to a motor-out scenario.
As part of that, this PR adds a PX4 Vehicle Setup page for injecting simulated failures via MAV_CMD_INJECT_FAILURE, so failsafe and EKF response can be validated from the UI instead of hand-crafting MAVLink commands.
Operators pick a failure unit, type, and instance(s) and inject them directly through the page. The page only appears when SYS_FAILURE_EN is present on the vehicle, which depends on the firmware being built with the failure-injection-manager module included — if the module isn't built in, the parameter is absent and the page stays hidden. The unit/type dropdowns are populated directly from MAVLink's FAILURE_UNIT/FAILURE_TYPE enums, so new entries appear automatically as they're added to MAVLink.

Display

Screencast.From.2026-07-01.19-28-43.mp4

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

  • PX4
  • ArduPilot

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 PR's


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 Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.42857% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.42%. Comparing base (f29efd3) to head (b1ef562).
⚠️ Report is 188 commits behind head on master.

Files with missing lines Patch % Lines
src/AutoPilotPlugins/PX4/FailureInjection.cc 56.63% 15 Missing and 34 partials ⚠️
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc 40.00% 0 Missing and 3 partials ⚠️
.../AutoPilotPlugins/PX4/FailureInjectionComponent.cc 81.81% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14578      +/-   ##
==========================================
+ Coverage   25.47%   32.42%   +6.95%     
==========================================
  Files         769      785      +16     
  Lines       65912    67362    +1450     
  Branches    30495    31198     +703     
==========================================
+ Hits        16788    21839    +5051     
+ Misses      37285    30820    -6465     
- Partials    11839    14703    +2864     
Flag Coverage Δ
unittests 32.42% <61.42%> (+6.95%) ⬆️

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

Files with missing lines Coverage Δ
src/AutoPilotPlugins/PX4/FailureInjection.h 100.00% <100.00%> (ø)
...c/AutoPilotPlugins/PX4/FailureInjectionComponent.h 100.00% <100.00%> (ø)
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.h 0.00% <ø> (ø)
.../AutoPilotPlugins/PX4/FailureInjectionComponent.cc 81.81% <81.81%> (ø)
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc 40.31% <40.00%> (+14.50%) ⬆️
src/AutoPilotPlugins/PX4/FailureInjection.cc 56.63% <56.63%> (ø)

... and 471 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 6d90e4b...b1ef562. 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 added size/L and removed size/M labels Jul 2, 2026
@Claudio-Chies

Copy link
Copy Markdown
Contributor Author

@bkueng @hamishwillee FYI This would be the PR for the UI side of the Failure injection refactor.

@Claudio-Chies
Claudio-Chies marked this pull request as ready for review July 2, 2026 10:42
@Claudio-Chies
Claudio-Chies requested a review from HTRamsey as a code owner July 2, 2026 10:42
Copilot AI review requested due to automatic review settings July 2, 2026 10:42

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

This PR adds a new PX4 Vehicle Setup page for injecting simulated failures using MAV_CMD_INJECT_FAILURE, gated by the presence of SYS_FAILURE_EN on the connected vehicle. It also updates MAVLink to a newer commit and extends the MAVLink-enum generator so QML can reflect the FAILURE_UNIT/FAILURE_TYPE catalogs directly from the MAVLink dialect.

Changes:

  • Add a PX4 “Failure Injection” setup component + QML page (instance selection, activity log, reset-all).
  • Add a QML singleton (FailureInjection) which builds unit/type catalogs from MAVLink enum reflection and tracks session activity.
  • Update MAVLink git tag and adjust enum-generation to provide QML-reflectable FAILURE_UNIT/FAILURE_TYPE enums, plus add unit/integration/UI tests.

Reviewed changes

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

Show a summary per file
File Description
tools/generators/mavlink_enums.py Extends QML enum header generation to locally redeclare specific enums for QML reflection.
cmake/CustomOptions.cmake Bumps the MAVLink repository commit/tag used by the build.
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.h Adds the Failure Injection component member/include.
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc Conditionally adds the Failure Injection setup page when SYS_FAILURE_EN exists.
src/AutoPilotPlugins/PX4/FailureInjectionComponent.qml Implements the full PX4 setup UI for injecting and resetting failures via MAVLink command.
src/AutoPilotPlugins/PX4/FailureInjectionInstances.js Shared instance-selection logic for mapping selected instances to MAVLink params.
src/AutoPilotPlugins/PX4/FailureInjectionComponent.h Declares the new Vehicle Setup component wrapper.
src/AutoPilotPlugins/PX4/FailureInjectionComponent.cc Implements component metadata and QML source wiring.
src/AutoPilotPlugins/PX4/FailureInjection.h Declares the QML singleton API and activity/catalog properties.
src/AutoPilotPlugins/PX4/FailureInjection.cc Builds catalogs from Q_ENUM_NS metadata and manages activity + injected-unit tracking.
src/AutoPilotPlugins/PX4/CMakeLists.txt Adds new C++ sources and QML/JS resources to the PX4 plugin build.
test/UnitTestFramework/QmlTesting/tests/tst_FailureInjectionInstances.qml Unit tests for the shared JS instance-selection logic.
test/AutoPilotPlugins/PX4/FailureInjectionTest.h Declares unit tests for the FailureInjection singleton model/logic.
test/AutoPilotPlugins/PX4/FailureInjectionTest.cc Implements unit tests for catalog building and activity/injected tracking behavior.
test/AutoPilotPlugins/CMakeLists.txt Registers the new FailureInjection unit test target.
test/QmlUITests/FailureInjectionUITest.h Declares an integration UI test that drives injection/reset through the real UI.
test/QmlUITests/FailureInjectionUITest.cc Implements the UI test using PX4 MockLink and QML objectName lookups.
test/QmlUITests/CMakeLists.txt Adds the new FailureInjection UI test to the test build/ctest list.

property Fact _sysFailureEn: controller.getParameterFact(-1, "SYS_FAILURE_EN", true /* reportMissing */)
property bool _paramSet: _sysFailureEn && _sysFailureEn.value === 1
property bool _pendingReboot: false // SYS_FAILURE_EN just toggled, reboot not yet triggered
property bool _armed: _paramSet // PX4 honors SYS_FAILURE_EN at boot; arm once the param reads 1
Comment on lines +38 to +41
property int _unitIndex: 4 // GPS
property int _typeIndex: 1 // Off
property var _selectedInstances: [1] // 1-based instance numbers
readonly property int _instanceCount: 8 // fixed number of selectable instances (not tied to the unit)
Comment on lines +25 to +26
Q_PROPERTY(QVariantList units READ units CONSTANT) ///< [{ name, unit, max }]
Q_PROPERTY(QVariantList types READ types CONSTANT) ///< [{ name, type }]

// One ack arrived: resolve the matching log row (only one is pending at a time), then send the next.
function _onAck(ackResult) {
FailureInjection.resolveResult(ackResult) // no-op when the head was a reset (no pending row)
@Claudio-Chies
Claudio-Chies force-pushed the cch/qgc-failure-injection branch from e7f5ab2 to b6b67e7 Compare July 2, 2026 14:13
@github-actions

github-actions Bot commented Jul 2, 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: 0 passed, 0 failed, 0 skipped.

Test Results

linux-coverage-integration: 36 passed, 0 skipped
linux-coverage-unit: 112 passed, 0 skipped
Total: 148 passed, 0 skipped

Code Coverage

Coverage: 68.9%

No baseline available for comparison

Artifact Sizes

Artifact Size
QGroundControl 221.90 MB
QGroundControl-aarch64 179.43 MB
QGroundControl-installer-AMD64 137.95 MB
QGroundControl-installer-AMD64-ARM64 80.46 MB
QGroundControl-installer-ARM64 109.24 MB
QGroundControl-linux 87.12 MB
QGroundControl-mac 87.11 MB
QGroundControl-windows 86.17 MB
QGroundControl-x86_64 191.66 MB
No baseline available for comparison

Updated: 2026-07-24 21:54:27 UTC • Commit: b1ef562 • Triggered by: Android

@HTRamsey
HTRamsey requested a review from DonLakeFlyer July 3, 2026 04:56
@DonLakeFlyer DonLakeFlyer added this to the Release V5.2 milestone Jul 3, 2026
@Claudio-Chies
Claudio-Chies force-pushed the cch/qgc-failure-injection branch from cb576ac to 01412ce Compare July 3, 2026 11:45
@DonLakeFlyer

Copy link
Copy Markdown
Contributor

FYI: Since we are currently in Stable 5.1 lockdown this won't get merged until we create the 5.1 branch.

Claudio Chies added 7 commits July 23, 2026 11:55
- Introduced FailureInjection and FailureInjectionComponent classes to manage simulated sensor and system failures.
- Updated CMakeLists.txt to include new source files and tests for Failure Injection.
- Implemented QML interface for Failure Injection, allowing users to inject failures and view activity logs.
- Enhanced MAVLink enums to support new FAILURE_UNIT and FAILURE_TYPE enums for failure injection.
- Added unit tests for FailureInjection functionality to ensure proper behavior and integration.
Copilot AI review requested due to automatic review settings July 23, 2026 21:56
@Claudio-Chies
Claudio-Chies force-pushed the cch/qgc-failure-injection branch from 25bf70e to 10aaec0 Compare July 23, 2026 21:56

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

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

Comment thread tools/generators/mavlink_enums.py
Comment thread src/AutoPilotPlugins/PX4/FailureInjectionComponent.qml Outdated
Comment thread src/AutoPilotPlugins/PX4/FailureInjectionComponent.qml
Comment thread src/AutoPilotPlugins/PX4/FailureInjectionComponent.qml
Comment thread src/AutoPilotPlugins/PX4/FailureInjectionComponent.cc Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 21:00

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

Copilot reviewed 18 out of 19 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/AutoPilotPlugins/PX4/FailureInjectionComponent.qml:393

  • The command preview string is user-visible but not translatable. Please wrap it in qsTr (with %n placeholders) so it can be localized like the rest of the page.
                            return "MAV_CMD_INJECT_FAILURE  param1=" + u.unit +
                                   "  param2=" + t.type + "  param3=" + p3 +
                                   "  param4=" + s.param4 + "  (i=" + s.label + ")"

// Holds MAV_CMD_INJECT_FAILURE sends not yet dispatched. Each entry is sent only once the
// previous one's ack has come back through onMavCommandResult/_onAck, so at most one is ever
// in flight at a time.
property var _sendQueue: [] // outstanding sends: [{ unit, type, instance, logArgs|null }]
Comment on lines +384 to +385
return "MAV_CMD_INJECT_FAILURE param1=" + _units[_unitIndex].unit +
" param2=" + _types[_typeIndex].type + " (no instance selected)"
Comment on lines +69 to +72
function onMavCommandResult(vehicleId, targetComponent, command, ackResult, failureCode) {
if (command === _cmdInjectFailure) {
_onAck(ackResult)
}
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.

3 participants