1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-18 13:55:18 +03:00

Update the failsafe so that an extra cycle is not required between some

phase changes.
This commit is contained in:
Dominic Clifton 2015-04-17 00:10:35 +01:00
parent eb74735ee8
commit a34e8f0bdb
2 changed files with 54 additions and 40 deletions

View file

@ -145,42 +145,59 @@ void failsafeUpdateState(void)
failsafeState.active = false; failsafeState.active = false;
} }
switch (failsafeState.phase) {
case FAILSAFE_IDLE:
if (!receivingRxData && armed) {
failsafeState.phase = FAILSAFE_RX_LOSS_DETECTED;
}
break;
case FAILSAFE_RX_LOSS_DETECTED: bool reprocessState;
if (failsafeShouldForceLanding(armed)) {
// Stabilize, and set Throttle to specified level
failsafeActivate();
}
break;
case FAILSAFE_LANDING: do {
if (armed) { reprocessState = false;
failsafeApplyControlInput();
}
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; failsafeState.active = false;
mwDisarm(); mwDisarm();
}
break;
case FAILSAFE_LANDED: break;
// 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;
default: default:
break; break;
} }
} while (reprocessState);
} }

View file

@ -162,19 +162,23 @@ TEST(FlightFailsafeTest, TestFailsafeNotActivatedWhenReceivingData)
TEST(FlightFailsafeTest, TestFailsafeDetectsRxLossAndStartsLanding) TEST(FlightFailsafeTest, TestFailsafeDetectsRxLossAndStartsLanding)
{ {
// given // given
ENABLE_ARMING_FLAG(ARMED); ENABLE_ARMING_FLAG(ARMED);
// FIXME one more cycle currently needed
// when // when
failsafeOnRxCycleStarted(); failsafeOnRxCycleStarted();
// no call to failsafeOnValidDataReceived(); // no call to failsafeOnValidDataReceived();
failsafeUpdateState(); failsafeUpdateState();
// then // then
EXPECT_EQ(false, failsafeIsActive()); EXPECT_EQ(false, failsafeIsActive());
EXPECT_EQ(FAILSAFE_IDLE, failsafePhase()); 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 // when
for (int i = 0; i < FAILSAFE_UPDATE_HZ - 1; i++) { 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 // when
failsafeOnRxCycleStarted(); failsafeOnRxCycleStarted();
// no call to failsafeOnValidDataReceived(); // no call to failsafeOnValidDataReceived();
@ -220,7 +227,6 @@ TEST(FlightFailsafeTest, TestFailsafeCausesLanding)
} }
// FIXME one more cycle currently needed
// when // when
failsafeOnRxCycleStarted(); failsafeOnRxCycleStarted();
// no call to failsafeOnValidDataReceived(); // no call to failsafeOnValidDataReceived();
@ -230,15 +236,6 @@ TEST(FlightFailsafeTest, TestFailsafeCausesLanding)
EXPECT_EQ(false, failsafeIsActive()); EXPECT_EQ(false, failsafeIsActive());
EXPECT_EQ(FAILSAFE_LANDED, failsafePhase()); EXPECT_EQ(FAILSAFE_LANDED, failsafePhase());
EXPECT_EQ(1, CALL_COUNTER(COUNTER_MW_DISARM)); 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)); EXPECT_TRUE(ARMING_FLAG(PREVENT_ARMING));
} }