mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 14:55:21 +03:00
Merge pull request #6067 from etracer65/rc_smoohting_crsf_init
RC smoothing - add rx frame training delay to deal with CRSF initialization
This commit is contained in:
commit
0210be305a
1 changed files with 43 additions and 33 deletions
|
@ -70,7 +70,8 @@ enum {
|
||||||
|
|
||||||
#ifdef USE_RC_SMOOTHING_FILTER
|
#ifdef USE_RC_SMOOTHING_FILTER
|
||||||
#define RC_SMOOTHING_IDENTITY_FREQUENCY 80 // Used in the formula to convert a BIQUAD cutoff frequency to PT1
|
#define RC_SMOOTHING_IDENTITY_FREQUENCY 80 // Used in the formula to convert a BIQUAD cutoff frequency to PT1
|
||||||
#define RC_SMOOTHING_FILTER_TRAINING_DELAY_MS 5000 // Wait 5 seconds after power to let the PID loop stabilize before starting average frame rate calculation
|
#define RC_SMOOTHING_FILTER_STARTUP_DELAY_MS 5000 // Time to wait after power to let the PID loop stabilize before starting average frame rate calculation
|
||||||
|
#define RC_SMOOTHING_FILTER_TRAINING_DELAY_MS 1000 // Additional time to wait after receiving first valid rx frame before training starts
|
||||||
#define RC_SMOOTHING_FILTER_TRAINING_SAMPLES 50
|
#define RC_SMOOTHING_FILTER_TRAINING_SAMPLES 50
|
||||||
|
|
||||||
static FAST_RAM_ZERO_INIT uint16_t defaultInputCutoffFrequency;
|
static FAST_RAM_ZERO_INIT uint16_t defaultInputCutoffFrequency;
|
||||||
|
@ -290,6 +291,7 @@ FAST_CODE uint8_t processRcSmoothingFilter(void)
|
||||||
static FAST_RAM_ZERO_INIT int rxFrameCount;
|
static FAST_RAM_ZERO_INIT int rxFrameCount;
|
||||||
static FAST_RAM uint16_t minRxFrameInterval = UINT16_MAX;
|
static FAST_RAM uint16_t minRxFrameInterval = UINT16_MAX;
|
||||||
static FAST_RAM_ZERO_INIT uint16_t maxRxFrameInterval;
|
static FAST_RAM_ZERO_INIT uint16_t maxRxFrameInterval;
|
||||||
|
static FAST_RAM_ZERO_INIT timeMs_t validRxFrameTimeMs;
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
@ -306,7 +308,11 @@ FAST_CODE uint8_t processRcSmoothingFilter(void)
|
||||||
// If the filter cutoffs are set to auto and we have good rx data, then determine the average rx frame rate
|
// If the filter cutoffs are set to auto and we have good rx data, then determine the average rx frame rate
|
||||||
// and use that to calculate the filter cutoff frequencies
|
// and use that to calculate the filter cutoff frequencies
|
||||||
if (!filterInitialized) {
|
if (!filterInitialized) {
|
||||||
if (rxIsReceivingSignal() && (targetPidLooptime > 0) && (millis() > RC_SMOOTHING_FILTER_TRAINING_DELAY_MS)) {
|
const timeMs_t currentTimeMs = millis();
|
||||||
|
if (rxIsReceivingSignal() && (targetPidLooptime > 0) && (currentTimeMs > RC_SMOOTHING_FILTER_STARTUP_DELAY_MS)) {
|
||||||
|
if (validRxFrameTimeMs == 0) {
|
||||||
|
validRxFrameTimeMs = currentTimeMs;
|
||||||
|
} else if ((currentTimeMs - validRxFrameTimeMs) > RC_SMOOTHING_FILTER_TRAINING_DELAY_MS) {
|
||||||
rxFrameTimeSum += currentRxRefreshRate;
|
rxFrameTimeSum += currentRxRefreshRate;
|
||||||
rxFrameCount++;
|
rxFrameCount++;
|
||||||
maxRxFrameInterval = MAX(maxRxFrameInterval, currentRxRefreshRate);
|
maxRxFrameInterval = MAX(maxRxFrameInterval, currentRxRefreshRate);
|
||||||
|
@ -345,9 +351,13 @@ FAST_CODE uint8_t processRcSmoothingFilter(void)
|
||||||
pidInitSetpointDerivativeLpf(derivativeCutoffFrequency, rxConfig()->rc_smoothing_debug_axis, rxConfig()->rc_smoothing_derivative_type);
|
pidInitSetpointDerivativeLpf(derivativeCutoffFrequency, rxConfig()->rc_smoothing_debug_axis, rxConfig()->rc_smoothing_derivative_type);
|
||||||
filterInitialized = true;
|
filterInitialized = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
rxFrameTimeSum = 0;
|
rxFrameTimeSum = 0;
|
||||||
rxFrameCount = 0;
|
rxFrameCount = 0;
|
||||||
|
validRxFrameTimeMs = 0;
|
||||||
|
minRxFrameInterval = UINT16_MAX;
|
||||||
|
maxRxFrameInterval = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue