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

Merge remote-tracking branch 'prodrone/improved_rx_failsafe_detection' into betaflight

This commit is contained in:
borisbstyle 2015-10-08 14:53:07 +02:00
commit fa2ac7fe86

View file

@ -69,7 +69,10 @@ uint16_t rssi = 0; // range: [0;1023]
static bool rxDataReceived = false; static bool rxDataReceived = false;
static bool rxSignalReceived = false; static bool rxSignalReceived = false;
static bool rxSignalReceivedNotDataDriven = false;
static bool rxFlightChannelsValid = false; static bool rxFlightChannelsValid = false;
static bool rxIsInFailsafeMode = true;
static bool rxIsInFailsafeModeNotDataDriven = true;
static uint32_t rxUpdateAt = 0; static uint32_t rxUpdateAt = 0;
static uint32_t needRxSignalBefore = 0; static uint32_t needRxSignalBefore = 0;
@ -272,9 +275,7 @@ static void resetRxSignalReceivedFlagIfNeeded(uint32_t currentTime)
if (((int32_t)(currentTime - needRxSignalBefore) >= 0)) { if (((int32_t)(currentTime - needRxSignalBefore) >= 0)) {
rxSignalReceived = false; rxSignalReceived = false;
#ifdef DEBUG_RX_SIGNAL_LOSS rxSignalReceivedNotDataDriven = false;
debug[0]++;
#endif
} }
} }
@ -307,7 +308,8 @@ void updateRx(uint32_t currentTime)
if (frameStatus & SERIAL_RX_FRAME_COMPLETE) { if (frameStatus & SERIAL_RX_FRAME_COMPLETE) {
rxDataReceived = true; rxDataReceived = true;
rxSignalReceived = (frameStatus & SERIAL_RX_FRAME_FAILSAFE) == 0; rxIsInFailsafeMode = (frameStatus & SERIAL_RX_FRAME_FAILSAFE) != 0;
rxSignalReceived = !rxIsInFailsafeMode;
needRxSignalBefore = currentTime + DELAY_10_HZ; needRxSignalBefore = currentTime + DELAY_10_HZ;
} }
} }
@ -318,13 +320,15 @@ void updateRx(uint32_t currentTime)
if (rxDataReceived) { if (rxDataReceived) {
rxSignalReceived = true; rxSignalReceived = true;
rxIsInFailsafeMode = false;
needRxSignalBefore = currentTime + DELAY_5_HZ; needRxSignalBefore = currentTime + DELAY_5_HZ;
} }
} }
if (feature(FEATURE_RX_PPM)) { if (feature(FEATURE_RX_PPM)) {
if (isPPMDataBeingReceived()) { if (isPPMDataBeingReceived()) {
rxSignalReceived = true; rxSignalReceivedNotDataDriven = true;
rxIsInFailsafeModeNotDataDriven = false;
needRxSignalBefore = currentTime + DELAY_10_HZ; needRxSignalBefore = currentTime + DELAY_10_HZ;
resetPPMDataReceivedState(); resetPPMDataReceivedState();
} }
@ -332,7 +336,8 @@ void updateRx(uint32_t currentTime)
if (feature(FEATURE_RX_PARALLEL_PWM)) { if (feature(FEATURE_RX_PARALLEL_PWM)) {
if (isPWMDataBeingReceived()) { if (isPWMDataBeingReceived()) {
rxSignalReceived = true; rxSignalReceivedNotDataDriven = true;
rxIsInFailsafeModeNotDataDriven = false;
needRxSignalBefore = currentTime + DELAY_10_HZ; needRxSignalBefore = currentTime + DELAY_10_HZ;
} }
} }
@ -439,13 +444,20 @@ static void detectAndApplySignalLossBehaviour(void)
bool useValueFromRx = true; bool useValueFromRx = true;
bool rxIsDataDriven = isRxDataDriven(); bool rxIsDataDriven = isRxDataDriven();
if (!rxSignalReceived) { if (!rxIsDataDriven) {
if (rxIsDataDriven && rxDataReceived) { rxSignalReceived = rxSignalReceivedNotDataDriven;
// use the values from the RX rxIsInFailsafeMode = rxIsInFailsafeModeNotDataDriven;
} else { }
if (!rxSignalReceived || rxIsInFailsafeMode) {
useValueFromRx = false; useValueFromRx = false;
} }
}
#ifdef DEBUG_RX_SIGNAL_LOSS
debug[0] = rxSignalReceived;
debug[1] = rxIsInFailsafeMode;
debug[2] = rcReadRawFunc(&rxRuntimeConfig, 0);
#endif
rxResetFlightChannelStatus(); rxResetFlightChannelStatus();
@ -473,7 +485,7 @@ static void detectAndApplySignalLossBehaviour(void)
if ((rxFlightChannelsValid) && !IS_RC_MODE_ACTIVE(BOXFAILSAFE)) { if ((rxFlightChannelsValid) && !IS_RC_MODE_ACTIVE(BOXFAILSAFE)) {
failsafeOnValidDataReceived(); failsafeOnValidDataReceived();
} else { } else {
rxSignalReceived = false; rxIsInFailsafeMode = rxIsInFailsafeModeNotDataDriven = true;
failsafeOnValidDataFailed(); failsafeOnValidDataFailed();
for (channel = 0; channel < rxRuntimeConfig.channelCount; channel++) { for (channel = 0; channel < rxRuntimeConfig.channelCount; channel++) {
@ -481,6 +493,10 @@ static void detectAndApplySignalLossBehaviour(void)
} }
} }
#ifdef DEBUG_RX_SIGNAL_LOSS
debug[3] = rcData[THROTTLE];
#endif
} }
void calculateRxChannelsAndUpdateFailsafe(uint32_t currentTime) void calculateRxChannelsAndUpdateFailsafe(uint32_t currentTime)