mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 21:35:44 +03:00
Fix random RX loss beep when using Serial RX receivers.
This commit is contained in:
parent
7266d42466
commit
bad0b1b04d
3 changed files with 30 additions and 18 deletions
|
@ -18,6 +18,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
#include "common/axis.h"
|
#include "common/axis.h"
|
||||||
|
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
|
@ -75,11 +77,11 @@ failsafePhase_e failsafePhase()
|
||||||
return failsafeState.phase;
|
return failsafeState.phase;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_COUNTER_VALUE_WHEN_RX_IS_RECEIVED_AFTER_RX_CYCLE 1
|
#define FAILSAFE_COUNTER_THRESHOLD 20
|
||||||
|
|
||||||
bool failsafeIsReceivingRxData(void)
|
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)
|
bool failsafeIsMonitoring(void)
|
||||||
|
@ -130,8 +132,8 @@ static void failsafeApplyControlInput(void)
|
||||||
|
|
||||||
void failsafeOnValidDataReceived(void)
|
void failsafeOnValidDataReceived(void)
|
||||||
{
|
{
|
||||||
if (failsafeState.counter > 20)
|
if (failsafeState.counter > FAILSAFE_COUNTER_THRESHOLD)
|
||||||
failsafeState.counter -= 20;
|
failsafeState.counter -= FAILSAFE_COUNTER_THRESHOLD;
|
||||||
else
|
else
|
||||||
failsafeState.counter = 0;
|
failsafeState.counter = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,6 +225,9 @@ void updateRx(uint32_t currentTime)
|
||||||
if (rxSignalReceived) {
|
if (rxSignalReceived) {
|
||||||
if (((int32_t)(currentTime - needRxSignalBefore) >= 0)) {
|
if (((int32_t)(currentTime - needRxSignalBefore) >= 0)) {
|
||||||
rxSignalReceived = false;
|
rxSignalReceived = false;
|
||||||
|
#ifdef DEBUG_RX_SIGNAL_LOSS
|
||||||
|
debug[0]++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,22 +176,27 @@ TEST(FlightFailsafeTest, TestFailsafeDetectsRxLossAndStartsLanding)
|
||||||
// given
|
// given
|
||||||
ENABLE_ARMING_FLAG(ARMED);
|
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
|
// 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();
|
failsafeOnRxCycleStarted();
|
||||||
// no call to failsafeOnValidDataReceived();
|
// no call to failsafeOnValidDataReceived();
|
||||||
|
@ -201,7 +206,6 @@ TEST(FlightFailsafeTest, TestFailsafeDetectsRxLossAndStartsLanding)
|
||||||
// then
|
// then
|
||||||
EXPECT_EQ(FAILSAFE_RX_LOSS_DETECTED, failsafePhase());
|
EXPECT_EQ(FAILSAFE_RX_LOSS_DETECTED, failsafePhase());
|
||||||
EXPECT_EQ(false, failsafeIsActive());
|
EXPECT_EQ(false, failsafeIsActive());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -305,6 +309,7 @@ TEST(FlightFailsafeTest, TestFailsafeNotActivatedWhenDisarmedAndRXLossIsDetected
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
|
int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
|
||||||
uint8_t armingFlags;
|
uint8_t armingFlags;
|
||||||
|
int16_t debug[DEBUG16_VALUE_COUNT];
|
||||||
|
|
||||||
void delay(uint32_t) {}
|
void delay(uint32_t) {}
|
||||||
|
|
||||||
|
@ -316,6 +321,8 @@ void mwDisarm(void) {
|
||||||
callCounts[COUNTER_MW_DISARM]++;
|
callCounts[COUNTER_MW_DISARM]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void beeper(beeperMode_e mode) { }
|
void beeper(beeperMode_e mode) {
|
||||||
|
UNUSED(mode);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue