mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 05:45:31 +03:00
Update the failsafe so that an extra cycle is not required between some
phase changes.
This commit is contained in:
parent
eb74735ee8
commit
a34e8f0bdb
2 changed files with 54 additions and 40 deletions
|
@ -145,42 +145,59 @@ void failsafeUpdateState(void)
|
|||
failsafeState.active = false;
|
||||
}
|
||||
|
||||
switch (failsafeState.phase) {
|
||||
case FAILSAFE_IDLE:
|
||||
if (!receivingRxData && armed) {
|
||||
failsafeState.phase = FAILSAFE_RX_LOSS_DETECTED;
|
||||
}
|
||||
break;
|
||||
|
||||
case FAILSAFE_RX_LOSS_DETECTED:
|
||||
if (failsafeShouldForceLanding(armed)) {
|
||||
// Stabilize, and set Throttle to specified level
|
||||
failsafeActivate();
|
||||
}
|
||||
break;
|
||||
bool reprocessState;
|
||||
|
||||
case FAILSAFE_LANDING:
|
||||
if (armed) {
|
||||
failsafeApplyControlInput();
|
||||
}
|
||||
do {
|
||||
reprocessState = false;
|
||||
|
||||
if (failsafeShouldHaveCausedLandingByNow() || !armed) {
|
||||
switch (failsafeState.phase) {
|
||||
case FAILSAFE_IDLE:
|
||||
if (!receivingRxData && armed) {
|
||||
failsafeState.phase = FAILSAFE_RX_LOSS_DETECTED;
|
||||
|
||||
reprocessState = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FAILSAFE_RX_LOSS_DETECTED:
|
||||
if (failsafeShouldForceLanding(armed)) {
|
||||
// Stabilize, and set Throttle to specified level
|
||||
failsafeActivate();
|
||||
|
||||
reprocessState = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FAILSAFE_LANDING:
|
||||
if (armed) {
|
||||
failsafeApplyControlInput();
|
||||
}
|
||||
|
||||
if (failsafeShouldHaveCausedLandingByNow() || !armed) {
|
||||
|
||||
failsafeState.phase = FAILSAFE_LANDED;
|
||||
|
||||
reprocessState = true;
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case FAILSAFE_LANDED:
|
||||
|
||||
// This will prevent the automatic rearm if failsafe shuts it down and prevents
|
||||
// to restart accidently by just reconnect to the tx - you will have to switch off first to rearm
|
||||
ENABLE_ARMING_FLAG(PREVENT_ARMING);
|
||||
|
||||
failsafeState.phase = FAILSAFE_LANDED;
|
||||
failsafeState.active = false;
|
||||
mwDisarm();
|
||||
}
|
||||
break;
|
||||
|
||||
case FAILSAFE_LANDED:
|
||||
// This will prevent the automatic rearm if failsafe shuts it down and prevents
|
||||
// to restart accidently by just reconnect to the tx - you will have to switch off first to rearm
|
||||
ENABLE_ARMING_FLAG(PREVENT_ARMING);
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (reprocessState);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -162,19 +162,23 @@ TEST(FlightFailsafeTest, TestFailsafeNotActivatedWhenReceivingData)
|
|||
|
||||
TEST(FlightFailsafeTest, TestFailsafeDetectsRxLossAndStartsLanding)
|
||||
{
|
||||
|
||||
// given
|
||||
ENABLE_ARMING_FLAG(ARMED);
|
||||
|
||||
// FIXME one more cycle currently needed
|
||||
// when
|
||||
failsafeOnRxCycleStarted();
|
||||
// no call to failsafeOnValidDataReceived();
|
||||
|
||||
failsafeUpdateState();
|
||||
|
||||
// then
|
||||
EXPECT_EQ(false, failsafeIsActive());
|
||||
EXPECT_EQ(FAILSAFE_IDLE, failsafePhase());
|
||||
|
||||
//
|
||||
// currently one cycle must occur (above) so that the next cycle (below) can detect the lack of an update.
|
||||
//
|
||||
|
||||
// when
|
||||
for (int i = 0; i < FAILSAFE_UPDATE_HZ - 1; i++) {
|
||||
|
@ -190,7 +194,10 @@ TEST(FlightFailsafeTest, TestFailsafeDetectsRxLossAndStartsLanding)
|
|||
|
||||
}
|
||||
|
||||
// FIXME one more cycle currently needed
|
||||
//
|
||||
// one more cycle currently needed before the counter is re-checked.
|
||||
//
|
||||
|
||||
// when
|
||||
failsafeOnRxCycleStarted();
|
||||
// no call to failsafeOnValidDataReceived();
|
||||
|
@ -220,7 +227,6 @@ TEST(FlightFailsafeTest, TestFailsafeCausesLanding)
|
|||
|
||||
}
|
||||
|
||||
// FIXME one more cycle currently needed
|
||||
// when
|
||||
failsafeOnRxCycleStarted();
|
||||
// no call to failsafeOnValidDataReceived();
|
||||
|
@ -230,15 +236,6 @@ TEST(FlightFailsafeTest, TestFailsafeCausesLanding)
|
|||
EXPECT_EQ(false, failsafeIsActive());
|
||||
EXPECT_EQ(FAILSAFE_LANDED, failsafePhase());
|
||||
EXPECT_EQ(1, CALL_COUNTER(COUNTER_MW_DISARM));
|
||||
// FIXME one more cycle currently needed
|
||||
EXPECT_FALSE(ARMING_FLAG(PREVENT_ARMING));
|
||||
|
||||
// when
|
||||
failsafeOnRxCycleStarted();
|
||||
// no call to failsafeOnValidDataReceived();
|
||||
failsafeUpdateState();
|
||||
|
||||
// then
|
||||
EXPECT_TRUE(ARMING_FLAG(PREVENT_ARMING));
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue