Skip to content

Commit 95deb01

Browse files
author
Ivan Efimov
committed
Team failsafe Ctz fix
1 parent d8c1fbe commit 95deb01

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/main/flight/failsafe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ bool failsafeIsMonitoring(void)
124124
return failsafeState.monitoring;
125125
}
126126

127-
bool failsafeIsActive(void)
127+
bool failsafeIsActive(void) // real or switch-induced stage 2 failsafe
128128
{
129129
return failsafeState.active;
130130
}

src/main/rx/rx.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ static uint16_t calculateChannelMovingAverage(uint8_t chan, uint16_t sample)
568568
static uint16_t getRxfailValue(uint8_t channel)
569569
{
570570
const rxFailsafeChannelConfig_t *channelFailsafeConfig = rxFailsafeChannelConfigs(channel);
571+
const bool failsafeAuxSwitch = IS_RC_MODE_ACTIVE(BOXFAILSAFE);
571572

572573
switch (channelFailsafeConfig->mode) {
573574
case RX_FAILSAFE_MODE_AUTO:
@@ -588,8 +589,11 @@ static uint16_t getRxfailValue(uint8_t channel)
588589
default:
589590
case RX_FAILSAFE_MODE_INVALID:
590591
case RX_FAILSAFE_MODE_HOLD:
591-
return rcData[channel];
592-
592+
if (failsafeAuxSwitch) {
593+
return rcRaw[channel]; // current values are allowed through on held channels with switch induced failsafe
594+
} else {
595+
return rcData[channel]; // last good value
596+
}
593597
case RX_FAILSAFE_MODE_SET:
594598
return RXFAIL_STEP_TO_CHANNEL_VALUE(channelFailsafeConfig->step);
595599
}
@@ -637,13 +641,11 @@ void detectAndApplySignalLossBehaviour(void)
637641
{
638642
const uint32_t currentTimeMs = millis();
639643
const bool failsafeAuxSwitch = IS_RC_MODE_ACTIVE(BOXFAILSAFE);
640-
bool allAuxChannelsAreGood = true;
641-
// used to record if any non-aux channel is out of range for the timeout period, assume they are good
642644
rxFlightChannelsValid = rxSignalReceived && !failsafeAuxSwitch;
643645
// set rxFlightChannelsValid false when a packet is bad or we use a failsafe switch
644646

645647
for (int channel = 0; channel < rxChannelCount; channel++) {
646-
float sample = rcRaw[channel];
648+
float sample = rcRaw[channel]; // sample has latest RC value, rcData has last 'accepted valid' value
647649
const bool thisChannelValid = rxFlightChannelsValid && isPulseValid(sample);
648650
// if the whole packet is bad, consider all channels bad
649651

@@ -653,38 +655,37 @@ void detectAndApplySignalLossBehaviour(void)
653655
}
654656

655657
if (ARMING_FLAG(ARMED) && failsafeIsActive()) {
656-
// while in failsafe Stage 2, pass incoming flight channel values unless they are bad
657-
// this allows GPS Return to detect the 30% requirement for termination
658+
// while in failsafe Stage 2, whether Rx loss or switch induced, pass valid incoming flight channel values
659+
// this allows GPS Rescue to detect the 30% requirement for termination
658660
if (channel < NON_AUX_CHANNEL_COUNT) {
659661
if (!thisChannelValid) {
660662
if (channel == THROTTLE ) {
661-
sample = failsafeConfig()->failsafe_throttle;
663+
sample = failsafeConfig()->failsafe_throttle; // stage 2 failsafe throttle value
662664
} else {
663665
sample = rxConfig()->midrc;
664666
}
665667
}
666-
} else if (!failsafeAuxSwitch) {
667-
// set aux channels as per Stage 1 Configurator values, unless failsafe was initiated by switch
668+
} else {
669+
// During Stage 2, set aux channels as per Stage 1 configuration
668670
sample = getRxfailValue(channel);
669671
}
670672
} else {
671673
if (failsafeAuxSwitch) {
672-
if (channel < NON_AUX_CHANNEL_COUNT) {
673-
sample = getRxfailValue(channel);
674-
// set RPYT values to Stage 1 values immediately if initiated by switch
675-
}
674+
sample = getRxfailValue(channel);
675+
// set channels to Stage 1 values immediately failsafe switch is activated
676676
} else if (!thisChannelValid) {
677677
if (cmp32(currentTimeMs, validRxSignalTimeout[channel]) < 0) {
678+
// first 300ms of Stage 1 failsafe
678679
sample = rcData[channel];
679680
// HOLD last valid value on bad channel/s for MAX_INVALID_PULSE_TIME_MS (300ms)
680681
} else {
681-
// then use STAGE 1 failsafe values
682+
// remaining Stage 1 failsafe period after 300ms
682683
if (channel < NON_AUX_CHANNEL_COUNT) {
683-
allAuxChannelsAreGood = false;
684-
// declare signal lost after 300ms of at least one bad flight channel
684+
rxFlightChannelsValid = false;
685+
// declare signal lost after 300ms of any one bad flight channel
685686
}
686687
sample = getRxfailValue(channel);
687-
// set all channels to Stage 1 values
688+
// set channels that are invalid for more than 300ms to Stage 1 values
688689
}
689690
}
690691
}
@@ -701,11 +702,10 @@ void detectAndApplySignalLossBehaviour(void)
701702
{
702703
// set rcData to either validated incoming values, or failsafe-modified values
703704
rcData[channel] = sample;
704-
705705
}
706706
}
707707

708-
if (rxFlightChannelsValid && allAuxChannelsAreGood) {
708+
if (rxFlightChannelsValid) {
709709
failsafeOnValidDataReceived();
710710
// --> start the timer to exit stage 2 failsafe
711711
} else {

0 commit comments

Comments
 (0)