Skip to content

Bugfix: Let user take over from a degraded failsafe#26237

Merged
MaEtUgR merged 2 commits intomainfrom
maetugr/fix-failsafe-takeover
Jan 9, 2026
Merged

Bugfix: Let user take over from a degraded failsafe#26237
MaEtUgR merged 2 commits intomainfrom
maetugr/fix-failsafe-takeover

Conversation

@MaEtUgR
Copy link
Copy Markdown
Member

@MaEtUgR MaEtUgR commented Jan 8, 2026

Solved Problem

User can not take over from a degraded failsafe e.g.

  1. Configure an RTL failsafe e.g. ground station loss action: Return (NAV_DLL_ACT = 2)
  2. Fly in manual mode (without position requirement)
  3. No position estimates available
  4. Lose ground station connection (but not RC connection)
  5. RTL is desired but not possible -> failsafe is Land
  6. Try to take over by changing the mode switch -> Nothing happens
Untitled

Solution

  1. Add unit test cases for
    • the case above: Remaining battery time low -> RTL, no position -> Land, need to be able to take over
    • the case for which the condition _selected_action == selected_action was originally added: When a failsafe happens immediately on mode switch because a mode requirement is not met. Then the mode switch that caused it should not be interpreted as the user taking over immediately. Note that the context should avoid switching to modes that cannot run but the framework should still handle the case correctly.
  2. Fix the condition _selected_action == selected_action to (_selected_action > Action::Warn).
    • Remove _selected_action == selected_action because in the problem case selected_action is what we want to do: Return and _selected_action is what we end up doing after the fallbacks in the same function below: Land and the condition is never fulfilled while degraded.
    • Still have (_selected_action > Action::Warn) to avoid immediately flaging a user takeover if there was no failsafe before and it's triggered at the same time as/caused by a mode switch.

Big thanks to @bkueng who got me to understand the immediate takeover case and also was the one suggesting the fix 🙏

Changelog Entry

Bugfix: Let user take over from a degraded failsafe

Test coverage

The failsafe simulation shows the problem and it being resolved and we have automated unit tests for the cases we could think of such that we hopefully can't break it again.

@MaEtUgR MaEtUgR requested review from bkueng and sfuhrer January 8, 2026 18:10
@MaEtUgR MaEtUgR self-assigned this Jan 8, 2026
@MaEtUgR MaEtUgR force-pushed the maetugr/fix-failsafe-takeover branch 2 times, most recently from 8e28636 to c081d2c Compare January 8, 2026 19:10
bkueng
bkueng previously approved these changes Jan 9, 2026
Copy link
Copy Markdown
Member

@bkueng bkueng left a comment

Choose a reason for hiding this comment

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

Nice work, this is an important fix

ASSERT_EQ(updated_user_intented_mode, state.user_intended_mode);
ASSERT_EQ(failsafe.selectedAction(), FailsafeBase::Action::Land);

// User wants takeover -> Land
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// User wants takeover -> Land
// User wants takeover -> Altitude Control

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for reviewing and spotting, copy pasta comment and forgot adapting the second part 🤦‍♂️
Fixed in place: https://github.com/PX4/PX4-Autopilot/compare/c081d2cb807f6f5fa783fcc5ff9ce25f6d5c09c6..1a85c71245ee27b972e7971d2a3f727b1c70b88d

…ailsafes 2 not cause immediate takeover when failsafe happens because of mode switch

The first test makes sure the user can take over when an RTL failsafe was triggered but degraded to a Land.

The second test rules out the easiest fix of removing the condition `_selected_action == selected_action` which causes the problem for test one but is there for a reason.
@MaEtUgR MaEtUgR force-pushed the maetugr/fix-failsafe-takeover branch from c081d2c to 1a85c71 Compare January 9, 2026 09:08
@MaEtUgR MaEtUgR merged commit 0e61581 into main Jan 9, 2026
70 checks passed
@MaEtUgR MaEtUgR deleted the maetugr/fix-failsafe-takeover branch January 9, 2026 09:10
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