-
Notifications
You must be signed in to change notification settings - Fork 15.5k
fix(commander): failsafe prevent manual fallback without RC #27408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include "failsafe.h" | ||
| #include "framework.h" | ||
| #include <uORB/topics/vehicle_status.h> | ||
| #include "../ModeUtil/mode_requirements.hpp" | ||
|
|
@@ -562,3 +563,98 @@ TEST_F(FailsafeTest, user_termination) | |
| EXPECT_EQ(updated_user_intented_mode, state.user_intended_mode); | ||
| EXPECT_EQ(failsafe.selectedAction(), FailsafeBase::Action::Terminate); | ||
| } | ||
|
|
||
| TEST_F(FailsafeTest, fallback_altitude_requires_manual_control) | ||
|
AkaiEurus marked this conversation as resolved.
|
||
| { | ||
| int nav_rcl_act = 2; | ||
| param_set(param_handle(px4::params::NAV_RCL_ACT), &nav_rcl_act); | ||
|
|
||
| Failsafe failsafe(nullptr); | ||
|
|
||
| failsafe_flags_s failsafe_flags{}; | ||
| mode_util::getModeRequirements(vehicle_status_s::VEHICLE_TYPE_ROTARY_WING, failsafe_flags); | ||
| failsafe_flags.manual_control_signal_lost = true; | ||
|
|
||
| FailsafeBase::State state{}; | ||
| state.user_intended_mode = vehicle_status_s::NAVIGATION_STATE_POSCTL; | ||
| state.vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING; | ||
| hrt_abstime time = 5_s; | ||
|
|
||
| // If arming was allowed without manual control, RC loss is ignored until manual control returns. | ||
| failsafe.update(time, state, false, false, failsafe_flags); | ||
|
|
||
| state.armed = true; | ||
| time += 10_ms; | ||
| failsafe.update(time, state, false, false, failsafe_flags); | ||
| ASSERT_EQ(failsafe.selectedAction(), FailsafeBase::Action::None); | ||
|
|
||
| // Losing position in PosCtl would normally fall back to AltCtl, but AltCtl needs manual control. | ||
| failsafe_flags.local_position_invalid_relaxed = true; | ||
| time += 10_ms; | ||
| failsafe.update(time, state, false, false, failsafe_flags); | ||
| EXPECT_EQ(failsafe.selectedAction(), FailsafeBase::Action::RTL); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With default |
||
| } | ||
|
|
||
| TEST_F(FailsafeTest, fallback_altitude_uses_nav_rcl_act_param) | ||
|
AkaiEurus marked this conversation as resolved.
|
||
| { | ||
| int nav_rcl_act = 5; | ||
| param_set(param_handle(px4::params::NAV_RCL_ACT), &nav_rcl_act); | ||
|
|
||
| Failsafe failsafe(nullptr); | ||
|
|
||
| failsafe_flags_s failsafe_flags{}; | ||
| mode_util::getModeRequirements(vehicle_status_s::VEHICLE_TYPE_ROTARY_WING, failsafe_flags); | ||
| failsafe_flags.manual_control_signal_lost = true; | ||
|
|
||
| FailsafeBase::State state{}; | ||
| state.user_intended_mode = vehicle_status_s::NAVIGATION_STATE_POSCTL; | ||
| state.vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING; | ||
| hrt_abstime time = 5_s; | ||
|
|
||
| // If arming was allowed without manual control, RC loss is ignored until manual control returns. | ||
| failsafe.update(time, state, false, false, failsafe_flags); | ||
|
|
||
| state.armed = true; | ||
| time += 10_ms; | ||
| failsafe.update(time, state, false, false, failsafe_flags); | ||
| ASSERT_EQ(failsafe.selectedAction(), FailsafeBase::Action::None); | ||
|
|
||
| // Losing position in PosCtl triggers the manual-control fallback, which should use NAV_RCL_ACT. | ||
| failsafe_flags.local_position_invalid_relaxed = true; | ||
| time += 10_ms; | ||
| failsafe.update(time, state, false, false, failsafe_flags); | ||
| EXPECT_EQ(failsafe.selectedAction(), FailsafeBase::Action::Terminate); | ||
| } | ||
|
|
||
| TEST_F(FailsafeTest, fallback_stabilized_requires_manual_control) | ||
|
AkaiEurus marked this conversation as resolved.
AkaiEurus marked this conversation as resolved.
|
||
| { | ||
| int nav_rcl_act = 2; | ||
| param_set(param_handle(px4::params::NAV_RCL_ACT), &nav_rcl_act); | ||
|
|
||
| Failsafe failsafe(nullptr); | ||
|
|
||
| failsafe_flags_s failsafe_flags{}; | ||
| mode_util::getModeRequirements(vehicle_status_s::VEHICLE_TYPE_ROTARY_WING, failsafe_flags); | ||
| failsafe_flags.manual_control_signal_lost = true; | ||
|
|
||
| FailsafeBase::State state{}; | ||
| state.user_intended_mode = vehicle_status_s::NAVIGATION_STATE_ALTCTL; | ||
| state.vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING; | ||
| hrt_abstime time = 5_s; | ||
|
|
||
| // If arming was allowed without manual control, RC loss is ignored until manual control returns. | ||
| failsafe.update(time, state, false, false, failsafe_flags); | ||
|
|
||
| state.armed = true; | ||
| time += 10_ms; | ||
| failsafe.update(time, state, false, false, failsafe_flags); | ||
| ASSERT_EQ(failsafe.selectedAction(), FailsafeBase::Action::None); | ||
|
|
||
| // Losing altitude in AltCtl would normally fall back to Stabilized, but Stabilized needs manual control. | ||
| failsafe_flags.local_altitude_invalid = true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth a comment that |
||
| time += 10_ms; | ||
| failsafe.update(time, state, false, false, failsafe_flags); | ||
| // checkModeFallback returns RTL from NAV_RCL_ACT. The framework then cascades RTL -> Land -> Descend | ||
| // because local altitude loss blocks both AUTO_RTL and AUTO_LAND. | ||
| EXPECT_EQ(failsafe.selectedAction(), FailsafeBase::Action::Descend); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.