1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-20 23:05:19 +03:00

Merge pull request #11628 from ctzsnooze/During-switch-failsafe,-aux-channel-hold-passes-data

failsafe by switch aux channel hold change
This commit is contained in:
J Blackman 2022-06-04 16:55:33 +10:00 committed by GitHub
commit b125cc146d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 21 deletions

View file

@ -124,7 +124,7 @@ bool failsafeIsMonitoring(void)
return failsafeState.monitoring; return failsafeState.monitoring;
} }
bool failsafeIsActive(void) bool failsafeIsActive(void) // real or switch-induced stage 2 failsafe
{ {
return failsafeState.active; return failsafeState.active;
} }

View file

@ -568,6 +568,7 @@ static uint16_t calculateChannelMovingAverage(uint8_t chan, uint16_t sample)
static uint16_t getRxfailValue(uint8_t channel) static uint16_t getRxfailValue(uint8_t channel)
{ {
const rxFailsafeChannelConfig_t *channelFailsafeConfig = rxFailsafeChannelConfigs(channel); const rxFailsafeChannelConfig_t *channelFailsafeConfig = rxFailsafeChannelConfigs(channel);
const bool failsafeAuxSwitch = IS_RC_MODE_ACTIVE(BOXFAILSAFE);
switch (channelFailsafeConfig->mode) { switch (channelFailsafeConfig->mode) {
case RX_FAILSAFE_MODE_AUTO: case RX_FAILSAFE_MODE_AUTO:
@ -588,8 +589,11 @@ static uint16_t getRxfailValue(uint8_t channel)
default: default:
case RX_FAILSAFE_MODE_INVALID: case RX_FAILSAFE_MODE_INVALID:
case RX_FAILSAFE_MODE_HOLD: case RX_FAILSAFE_MODE_HOLD:
return rcData[channel]; if (failsafeAuxSwitch) {
return rcRaw[channel]; // current values are allowed through on held channels with switch induced failsafe
} else {
return rcData[channel]; // last good value
}
case RX_FAILSAFE_MODE_SET: case RX_FAILSAFE_MODE_SET:
return RXFAIL_STEP_TO_CHANNEL_VALUE(channelFailsafeConfig->step); return RXFAIL_STEP_TO_CHANNEL_VALUE(channelFailsafeConfig->step);
} }
@ -637,13 +641,11 @@ void detectAndApplySignalLossBehaviour(void)
{ {
const uint32_t currentTimeMs = millis(); const uint32_t currentTimeMs = millis();
const bool failsafeAuxSwitch = IS_RC_MODE_ACTIVE(BOXFAILSAFE); const bool failsafeAuxSwitch = IS_RC_MODE_ACTIVE(BOXFAILSAFE);
bool allAuxChannelsAreGood = true;
// used to record if any non-aux channel is out of range for the timeout period, assume they are good
rxFlightChannelsValid = rxSignalReceived && !failsafeAuxSwitch; rxFlightChannelsValid = rxSignalReceived && !failsafeAuxSwitch;
// set rxFlightChannelsValid false when a packet is bad or we use a failsafe switch // set rxFlightChannelsValid false when a packet is bad or we use a failsafe switch
for (int channel = 0; channel < rxChannelCount; channel++) { for (int channel = 0; channel < rxChannelCount; channel++) {
float sample = rcRaw[channel]; float sample = rcRaw[channel]; // sample has latest RC value, rcData has last 'accepted valid' value
const bool thisChannelValid = rxFlightChannelsValid && isPulseValid(sample); const bool thisChannelValid = rxFlightChannelsValid && isPulseValid(sample);
// if the whole packet is bad, consider all channels bad // if the whole packet is bad, consider all channels bad
@ -653,38 +655,37 @@ void detectAndApplySignalLossBehaviour(void)
} }
if (ARMING_FLAG(ARMED) && failsafeIsActive()) { if (ARMING_FLAG(ARMED) && failsafeIsActive()) {
// while in failsafe Stage 2, pass incoming flight channel values unless they are bad // while in failsafe Stage 2, whether Rx loss or switch induced, pass valid incoming flight channel values
// this allows GPS Return to detect the 30% requirement for termination // this allows GPS Rescue to detect the 30% requirement for termination
if (channel < NON_AUX_CHANNEL_COUNT) { if (channel < NON_AUX_CHANNEL_COUNT) {
if (!thisChannelValid) { if (!thisChannelValid) {
if (channel == THROTTLE ) { if (channel == THROTTLE ) {
sample = failsafeConfig()->failsafe_throttle; sample = failsafeConfig()->failsafe_throttle; // stage 2 failsafe throttle value
} else { } else {
sample = rxConfig()->midrc; sample = rxConfig()->midrc;
} }
} }
} else if (!failsafeAuxSwitch) { } else {
// set aux channels as per Stage 1 Configurator values, unless failsafe was initiated by switch // During Stage 2, set aux channels as per Stage 1 configuration
sample = getRxfailValue(channel); sample = getRxfailValue(channel);
} }
} else { } else {
if (failsafeAuxSwitch) { if (failsafeAuxSwitch) {
if (channel < NON_AUX_CHANNEL_COUNT) {
sample = getRxfailValue(channel); sample = getRxfailValue(channel);
// set RPYT values to Stage 1 values immediately if initiated by switch // set channels to Stage 1 values immediately failsafe switch is activated
}
} else if (!thisChannelValid) { } else if (!thisChannelValid) {
if (cmp32(currentTimeMs, validRxSignalTimeout[channel]) < 0) { if (cmp32(currentTimeMs, validRxSignalTimeout[channel]) < 0) {
// first 300ms of Stage 1 failsafe
sample = rcData[channel]; sample = rcData[channel];
// HOLD last valid value on bad channel/s for MAX_INVALID_PULSE_TIME_MS (300ms) // HOLD last valid value on bad channel/s for MAX_INVALID_PULSE_TIME_MS (300ms)
} else { } else {
// then use STAGE 1 failsafe values // remaining Stage 1 failsafe period after 300ms
if (channel < NON_AUX_CHANNEL_COUNT) { if (channel < NON_AUX_CHANNEL_COUNT) {
allAuxChannelsAreGood = false; rxFlightChannelsValid = false;
// declare signal lost after 300ms of at least one bad flight channel // declare signal lost after 300ms of any one bad flight channel
} }
sample = getRxfailValue(channel); sample = getRxfailValue(channel);
// set all channels to Stage 1 values // set channels that are invalid for more than 300ms to Stage 1 values
} }
} }
} }
@ -701,11 +702,10 @@ void detectAndApplySignalLossBehaviour(void)
{ {
// set rcData to either validated incoming values, or failsafe-modified values // set rcData to either validated incoming values, or failsafe-modified values
rcData[channel] = sample; rcData[channel] = sample;
} }
} }
if (rxFlightChannelsValid && allAuxChannelsAreGood) { if (rxFlightChannelsValid) {
failsafeOnValidDataReceived(); failsafeOnValidDataReceived();
// --> start the timer to exit stage 2 failsafe // --> start the timer to exit stage 2 failsafe
} else { } else {