2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
20 #define FAILSAFE_POWER_ON_DELAY_US (1000 * 1000 * 5)
21 #define MILLIS_PER_TENTH_SECOND 100
22 #define MILLIS_PER_SECOND 1000
23 #define PERIOD_OF_1_SECONDS 1 * MILLIS_PER_SECOND
24 #define PERIOD_OF_3_SECONDS 3 * MILLIS_PER_SECOND
25 #define PERIOD_OF_30_SECONDS 30 * MILLIS_PER_SECOND
26 #define PERIOD_RXDATA_FAILURE 200 // millis
27 #define PERIOD_RXDATA_RECOVERY 200 // millis
30 typedef struct failsafeConfig_s
{
31 uint8_t failsafe_delay
; // Guard time for failsafe activation after signal lost. 1 step = 0.1sec - 1sec in example (10)
32 uint8_t failsafe_off_delay
; // Time for Landing before motors stop in 0.1sec. 1 step = 0.1sec - 20sec in example (200)
33 uint16_t failsafe_throttle
; // Throttle level used for landing - specify value between 1000..2000 (pwm pulse width for slightly below hover). center throttle = 1500.
34 uint8_t failsafe_kill_switch
; // failsafe switch action is 0: identical to rc link loss, 1: disarms instantly
35 uint16_t failsafe_throttle_low_delay
; // Time throttle stick must have been below 'min_check' to "JustDisarm" instead of "full failsafe procedure".
40 FAILSAFE_RX_LOSS_DETECTED
,
43 FAILSAFE_RX_LOSS_MONITORING
,
44 FAILSAFE_RX_LOSS_RECOVERED
48 FAILSAFE_RXLINK_DOWN
= 0,
50 } failsafeRxLinkState_e
;
52 typedef struct failsafeState_s
{
56 uint32_t rxDataFailurePeriod
;
57 uint32_t validRxDataReceivedAt
;
58 uint32_t validRxDataFailedAt
;
59 uint32_t throttleLowPeriod
; // throttle stick must have been below 'min_check' for this period
60 uint32_t landingShouldBeFinishedAt
;
61 uint32_t receivingRxDataPeriod
; // period for the required period of valid rxData
62 uint32_t receivingRxDataPeriodPreset
; // preset for the required period of valid rxData
63 failsafePhase_e phase
;
64 failsafeRxLinkState_e rxLinkState
;
67 void useFailsafeConfig(failsafeConfig_t
*failsafeConfigToUse
);
69 void failsafeStartMonitoring(void);
70 void failsafeUpdateState(void);
72 failsafePhase_e
failsafePhase();
73 bool failsafeIsMonitoring(void);
74 bool failsafeIsActive(void);
75 bool failsafeIsReceivingRxData(void);
76 void failsafeOnRxSuspend(uint32_t suspendPeriod
);
77 void failsafeOnRxResume(void);
79 void failsafeOnValidDataReceived(void);
80 void failsafeOnValidDataFailed(void);