mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 09:16:07 +03:00
Fix failsafe timings and behaviour to match Failsafe.md
This commit is contained in:
parent
a6207a100e
commit
07f6bea174
18 changed files with 214 additions and 136 deletions
|
@ -183,7 +183,7 @@ TEST(FlightFailsafeTest, TestFailsafeDetectsRxLossAndStartsLanding)
|
|||
failsafeOnValidDataReceived(); // set last valid sample at current time
|
||||
|
||||
// when
|
||||
for (sysTickUptime = 0; sysTickUptime < (uint32_t)(PERIOD_RXDATA_FAILURE + failsafeConfig()->failsafe_delay * MILLIS_PER_TENTH_SECOND); sysTickUptime++) {
|
||||
for (sysTickUptime = 0; sysTickUptime < (uint32_t)(failsafeConfig()->failsafe_delay * MILLIS_PER_TENTH_SECOND); sysTickUptime++) {
|
||||
failsafeOnValidDataFailed();
|
||||
|
||||
failsafeUpdateState();
|
||||
|
@ -237,7 +237,7 @@ TEST(FlightFailsafeTest, TestFailsafeCausesLanding)
|
|||
EXPECT_TRUE(isArmingDisabled());
|
||||
|
||||
// given
|
||||
sysTickUptime += PERIOD_OF_30_SECONDS + 1; // adjust time to point just past the required additional recovery time
|
||||
sysTickUptime += PERIOD_OF_3_SECONDS + 1; // adjust time to point just past the required additional recovery time
|
||||
failsafeOnValidDataReceived();
|
||||
|
||||
// when
|
||||
|
@ -361,7 +361,7 @@ TEST(FlightFailsafeTest, TestFailsafeSwitchModeKill)
|
|||
EXPECT_EQ(FAILSAFE_RX_LOSS_MONITORING, failsafePhase());
|
||||
|
||||
// given
|
||||
sysTickUptime += PERIOD_OF_1_SECONDS + 1; // adjust time to point just past the required additional recovery time
|
||||
sysTickUptime += PERIOD_OF_3_SECONDS + 1; // adjust time to point just past the required additional recovery time
|
||||
failsafeOnValidDataReceived();
|
||||
|
||||
// when
|
||||
|
@ -435,8 +435,7 @@ TEST(FlightFailsafeTest, TestFailsafeSwitchModeStage2Land)
|
|||
failsafeUpdateState(); // should activate stage2 immediately
|
||||
|
||||
// then
|
||||
EXPECT_TRUE(failsafeIsActive());
|
||||
EXPECT_TRUE(isArmingDisabled());
|
||||
EXPECT_TRUE(failsafeIsActive()); // stick induced failsafe allows re-arming
|
||||
EXPECT_EQ(0, CALL_COUNTER(COUNTER_MW_DISARM));
|
||||
EXPECT_EQ(FAILSAFE_LANDING, failsafePhase());
|
||||
|
||||
|
@ -456,7 +455,7 @@ TEST(FlightFailsafeTest, TestFailsafeSwitchModeStage2Land)
|
|||
EXPECT_EQ(FAILSAFE_RX_LOSS_MONITORING, failsafePhase());
|
||||
|
||||
// given
|
||||
sysTickUptime += PERIOD_OF_30_SECONDS + 1; // adjust time to point just past the required additional recovery time
|
||||
sysTickUptime += PERIOD_OF_3_SECONDS + 1; // adjust time to point just past the required additional recovery time
|
||||
|
||||
// and
|
||||
deactivateBoxFailsafe();
|
||||
|
@ -497,7 +496,7 @@ TEST(FlightFailsafeTest, TestFailsafeNotActivatedWhenDisarmedAndRXLossIsDetected
|
|||
sysTickUptime = 0; // restart time from 0
|
||||
failsafeOnValidDataReceived(); // set last valid sample at current time
|
||||
|
||||
// when
|
||||
// enter stage 1 failsafe
|
||||
for (sysTickUptime = 0; sysTickUptime < PERIOD_RXDATA_FAILURE; sysTickUptime++) {
|
||||
failsafeOnValidDataFailed();
|
||||
|
||||
|
@ -520,10 +519,20 @@ TEST(FlightFailsafeTest, TestFailsafeNotActivatedWhenDisarmedAndRXLossIsDetected
|
|||
EXPECT_FALSE(failsafeIsActive());
|
||||
EXPECT_EQ(FAILSAFE_IDLE, failsafePhase());
|
||||
EXPECT_EQ(0, CALL_COUNTER(COUNTER_MW_DISARM));
|
||||
EXPECT_TRUE(isArmingDisabled());
|
||||
EXPECT_FALSE(isArmingDisabled()); // arming not blocked in stage 1
|
||||
|
||||
// given
|
||||
// enough valid data is received
|
||||
// add enough time to enter stage 2
|
||||
sysTickUptime += failsafeConfig()->failsafe_off_delay * MILLIS_PER_TENTH_SECOND + 1;
|
||||
failsafeOnValidDataFailed();
|
||||
|
||||
// when
|
||||
failsafeUpdateState();
|
||||
|
||||
// then
|
||||
EXPECT_TRUE(isArmingDisabled()); // arming blocked until recovery time
|
||||
EXPECT_FALSE(failsafeIsActive()); // failsafe is still not active
|
||||
|
||||
// given valid data is received for the recovery time, allow re-arming
|
||||
uint32_t sysTickTarget = sysTickUptime + PERIOD_RXDATA_RECOVERY;
|
||||
for (; sysTickUptime < sysTickTarget; sysTickUptime++) {
|
||||
failsafeOnValidDataReceived();
|
||||
|
@ -546,6 +555,7 @@ extern "C" {
|
|||
float rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
|
||||
float rcCommand[4];
|
||||
int16_t debug[DEBUG16_VALUE_COUNT];
|
||||
uint8_t debugMode = 0;
|
||||
bool isUsingSticksToArm = true;
|
||||
|
||||
PG_REGISTER(rxConfig_t, rxConfig, PG_RX_CONFIG, 0);
|
||||
|
|
|
@ -45,6 +45,7 @@ extern "C" {
|
|||
#include "fc/rc_modes.h"
|
||||
#include "fc/runtime_config.h"
|
||||
|
||||
#include "flight/failsafe.h"
|
||||
#include "flight/imu.h"
|
||||
#include "flight/mixer.h"
|
||||
#include "flight/pid.h"
|
||||
|
@ -86,6 +87,7 @@ extern "C" {
|
|||
PG_REGISTER(pilotConfig_t, pilotConfig, PG_PILOT_CONFIG, 0);
|
||||
PG_REGISTER(imuConfig_t, imuConfig, PG_IMU_CONFIG, 0);
|
||||
PG_REGISTER(gpsConfig_t, gpsConfig, PG_GPS_CONFIG, 0);
|
||||
PG_REGISTER(failsafeConfig_t, failsafeConfig, PG_FAILSAFE_CONFIG, 0);
|
||||
|
||||
timeUs_t simulationTime = 0;
|
||||
|
||||
|
@ -502,6 +504,7 @@ extern "C" {
|
|||
void persistentObjectWrite(persistentObjectId_e, uint32_t) {}
|
||||
void failsafeOnRxSuspend(uint32_t ) {}
|
||||
void failsafeOnRxResume(void) {}
|
||||
uint32_t failsafeFailurePeriodMs(void) { return 400; }
|
||||
void featureDisableImmediate(uint32_t) { }
|
||||
bool rxMspFrameComplete(void) { return false; }
|
||||
bool isPPMDataBeingReceived(void) { return false; }
|
||||
|
|
|
@ -25,11 +25,13 @@ extern "C" {
|
|||
#include "build/debug.h"
|
||||
#include "drivers/io.h"
|
||||
#include "common/maths.h"
|
||||
#include "flight/failsafe.h"
|
||||
#include "pg/pg.h"
|
||||
#include "pg/pg_ids.h"
|
||||
#include "pg/rx.h"
|
||||
#include "fc/rc_controls.h"
|
||||
#include "fc/rc_modes.h"
|
||||
#include "fc/runtime_config.h"
|
||||
#include "rx/rx.h"
|
||||
}
|
||||
|
||||
|
@ -39,10 +41,12 @@ extern "C" {
|
|||
extern "C" {
|
||||
|
||||
PG_REGISTER(flight3DConfig_t, flight3DConfig, PG_MOTOR_3D_CONFIG, 0);
|
||||
PG_REGISTER(failsafeConfig_t, failsafeConfig, PG_FAILSAFE_CONFIG, 0);
|
||||
|
||||
boxBitmask_t rcModeActivationMask;
|
||||
int16_t debug[DEBUG16_VALUE_COUNT];
|
||||
uint8_t debugMode = 0;
|
||||
uint8_t armingFlags = 0;
|
||||
|
||||
extern float applyRxChannelRangeConfiguraton(float sample, const rxChannelRangeConfig_t *range);
|
||||
}
|
||||
|
@ -107,8 +111,11 @@ extern "C" {
|
|||
|
||||
void failsafeOnRxSuspend(uint32_t ) {}
|
||||
void failsafeOnRxResume(void) {}
|
||||
bool failsafeIsActive(void) { return false; }
|
||||
bool failsafeIsReceivingRxData(void) { return true; }
|
||||
bool taskUpdateRxMainInProgress() { return true; }
|
||||
void setArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
|
||||
void unsetArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
|
||||
|
||||
uint32_t micros(void) { return 0; }
|
||||
uint32_t millis(void) { return 0; }
|
||||
|
@ -225,6 +232,11 @@ void failsafeOnValidDataFailed(void)
|
|||
{
|
||||
}
|
||||
|
||||
uint32_t failsafeFailurePeriodMs(void)
|
||||
{
|
||||
return 400;
|
||||
}
|
||||
|
||||
float pt1FilterGain(float f_cut, float dT)
|
||||
{
|
||||
UNUSED(f_cut);
|
||||
|
|
|
@ -27,6 +27,8 @@ extern "C" {
|
|||
#include "build/debug.h"
|
||||
#include "drivers/io.h"
|
||||
#include "fc/rc_controls.h"
|
||||
#include "fc/runtime_config.h"
|
||||
#include "flight/failsafe.h"
|
||||
#include "rx/rx.h"
|
||||
#include "fc/rc_modes.h"
|
||||
#include "common/maths.h"
|
||||
|
@ -39,6 +41,7 @@ extern "C" {
|
|||
boxBitmask_t rcModeActivationMask;
|
||||
int16_t debug[DEBUG16_VALUE_COUNT];
|
||||
uint8_t debugMode = 0;
|
||||
uint8_t armingFlags = 0;
|
||||
|
||||
bool isPulseValid(uint16_t pulseDuration);
|
||||
|
||||
|
@ -47,6 +50,7 @@ extern "C" {
|
|||
);
|
||||
|
||||
PG_REGISTER(flight3DConfig_t, flight3DConfig, PG_MOTOR_3D_CONFIG, 0);
|
||||
PG_REGISTER(failsafeConfig_t, failsafeConfig, PG_FAILSAFE_CONFIG, 0);
|
||||
}
|
||||
|
||||
#include "unittest_macros.h"
|
||||
|
@ -210,7 +214,9 @@ extern "C" {
|
|||
|
||||
void failsafeOnRxSuspend(uint32_t ) {}
|
||||
void failsafeOnRxResume(void) {}
|
||||
bool failsafeIsActive(void) { return false; }
|
||||
bool failsafeIsReceivingRxData(void) { return true; }
|
||||
uint32_t failsafeFailurePeriodMs(void) { return 400; }
|
||||
|
||||
uint32_t micros(void) { return 0; }
|
||||
uint32_t millis(void) { return 0; }
|
||||
|
@ -236,6 +242,8 @@ extern "C" {
|
|||
void xBusInit(const rxConfig_t *, rxRuntimeState_t *) {}
|
||||
void rxMspInit(const rxConfig_t *, rxRuntimeState_t *) {}
|
||||
void rxPwmInit(const rxConfig_t *, rxRuntimeState_t *) {}
|
||||
void setArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
|
||||
void unsetArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
|
||||
bool taskUpdateRxMainInProgress() { return true; }
|
||||
float pt1FilterGain(float f_cut, float dT)
|
||||
{
|
||||
|
|
|
@ -74,7 +74,7 @@ extern "C" {
|
|||
uint32_t simulatedTime = 0;
|
||||
uint32_t micros(void) { return simulatedTime; }
|
||||
uint32_t millis(void) { return simulatedTime/1000; } // Note simplistic mapping suitable only for short unit tests
|
||||
uint32_t clockCyclesToMicros(uint32_t x) { return x/10;}
|
||||
int32_t clockCyclesToMicros(int32_t x) { return x/10;}
|
||||
int32_t clockCyclesTo10thMicros(int32_t x) { return x;}
|
||||
uint32_t clockMicrosToCycles(uint32_t x) { return x*10;}
|
||||
uint32_t getCycleCounter(void) {return simulatedTime * 10;}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue