Fix random RX loss beep when using Serial RX receivers.

This commit is contained in:
Dominic Clifton 2015-04-23 16:33:41 +02:00
parent 7266d42466
commit bad0b1b04d
3 changed files with 30 additions and 18 deletions

View File

@ -18,6 +18,8 @@
#include <stdbool.h>
#include <stdint.h>
#include "debug.h"
#include "common/axis.h"
#include "rx/rx.h"
@ -75,11 +77,11 @@ failsafePhase_e failsafePhase()
return failsafeState.phase;
}
#define MAX_COUNTER_VALUE_WHEN_RX_IS_RECEIVED_AFTER_RX_CYCLE 1
#define FAILSAFE_COUNTER_THRESHOLD 20
bool failsafeIsReceivingRxData(void)
{
return failsafeState.counter <= MAX_COUNTER_VALUE_WHEN_RX_IS_RECEIVED_AFTER_RX_CYCLE;
return failsafeState.counter <= FAILSAFE_COUNTER_THRESHOLD;
}
bool failsafeIsMonitoring(void)
@ -130,8 +132,8 @@ static void failsafeApplyControlInput(void)
void failsafeOnValidDataReceived(void)
{
if (failsafeState.counter > 20)
failsafeState.counter -= 20;
if (failsafeState.counter > FAILSAFE_COUNTER_THRESHOLD)
failsafeState.counter -= FAILSAFE_COUNTER_THRESHOLD;
else
failsafeState.counter = 0;
}

View File

@ -225,6 +225,9 @@ void updateRx(uint32_t currentTime)
if (rxSignalReceived) {
if (((int32_t)(currentTime - needRxSignalBefore) >= 0)) {
rxSignalReceived = false;
#ifdef DEBUG_RX_SIGNAL_LOSS
debug[0]++;
#endif
}
}

View File

@ -176,22 +176,27 @@ TEST(FlightFailsafeTest, TestFailsafeDetectsRxLossAndStartsLanding)
// given
ENABLE_ARMING_FLAG(ARMED);
// 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.
// currently 20 cycles must occur before the lack of an update triggers RX loss detection.
//
// FIXME see comments about RX_SERIAL/RX_MSP above, the test should likely deal with time rather than counters.
int failsafeCounterThreshold = 20;
// when
for (int i = 0; i < FAILSAFE_UPDATE_HZ - 1; i++) {
for (int i = 0; i < failsafeCounterThreshold; i++) {
failsafeOnRxCycleStarted();
// no call to failsafeOnValidDataReceived();
failsafeUpdateState();
// then
EXPECT_EQ(FAILSAFE_IDLE, failsafePhase());
EXPECT_EQ(false, failsafeIsActive());
}
// when
for (int i = 0; i < FAILSAFE_UPDATE_HZ - failsafeCounterThreshold; i++) {
failsafeOnRxCycleStarted();
// no call to failsafeOnValidDataReceived();
@ -201,7 +206,6 @@ TEST(FlightFailsafeTest, TestFailsafeDetectsRxLossAndStartsLanding)
// then
EXPECT_EQ(FAILSAFE_RX_LOSS_DETECTED, failsafePhase());
EXPECT_EQ(false, failsafeIsActive());
}
//
@ -305,6 +309,7 @@ TEST(FlightFailsafeTest, TestFailsafeNotActivatedWhenDisarmedAndRXLossIsDetected
extern "C" {
int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
uint8_t armingFlags;
int16_t debug[DEBUG16_VALUE_COUNT];
void delay(uint32_t) {}
@ -316,6 +321,8 @@ void mwDisarm(void) {
callCounts[COUNTER_MW_DISARM]++;
}
void beeper(beeperMode_e mode) { }
void beeper(beeperMode_e mode) {
UNUSED(mode);
}
}