From 47b29a4d45033e28f36bfc519b0bc34063071ca2 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Tue, 13 Nov 2018 08:42:09 -0500 Subject: [PATCH] RC Smoothing: added parameter to allow user to adjust the smoothness of the auto cutoff calc Adds `rc_smoothing_auto_smoothness` parameter that allows the user to tune the filter auto cutoff calculation. Increasing the value makes the resulting rcCommand traces smoother. Allows the user to retain the "auto" calculation which is important for protocols that can change rate (like CRSF), but still tune the resulting "smoothness" to their preference. --- src/main/blackbox/blackbox.c | 1 + src/main/fc/rc.c | 3 ++- src/main/interface/settings.c | 1 + src/main/pg/rx.c | 1 + src/main/pg/rx.h | 1 + 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index 7869a48eb..2ac8a360e 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -1333,6 +1333,7 @@ static bool blackboxWriteSysinfo(void) BLACKBOX_PRINT_HEADER_LINE("rc_smoothing_debug_axis", "%d", rxConfig()->rc_smoothing_debug_axis); BLACKBOX_PRINT_HEADER_LINE("rc_smoothing_cutoffs", "%d, %d", rxConfig()->rc_smoothing_input_cutoff, rxConfig()->rc_smoothing_derivative_cutoff); + BLACKBOX_PRINT_HEADER_LINE("rc_smoothing_auto_factor", "%d", rxConfig()->rc_smoothing_auto_factor); BLACKBOX_PRINT_HEADER_LINE("rc_smoothing_filter_type", "%d, %d", rxConfig()->rc_smoothing_input_type, rxConfig()->rc_smoothing_derivative_type); BLACKBOX_PRINT_HEADER_LINE("rc_smoothing_active_cutoffs", "%d, %d", rcSmoothingGetValue(RC_SMOOTHING_VALUE_INPUT_ACTIVE), diff --git a/src/main/fc/rc.c b/src/main/fc/rc.c index e76d0834d..63fabb514 100644 --- a/src/main/fc/rc.c +++ b/src/main/fc/rc.c @@ -288,8 +288,9 @@ FAST_CODE uint8_t processRcInterpolation(void) FAST_CODE_NOINLINE int calcRcSmoothingCutoff(int avgRxFrameTimeUs, bool pt1) { if (avgRxFrameTimeUs > 0) { + const float cutoffFactor = (100 - rxConfig()->rc_smoothing_auto_factor) / 100.0f; float cutoff = (1 / (avgRxFrameTimeUs * 1e-6f)) / 2; // calculate the nyquist frequency - cutoff = cutoff * 0.90f; // Use 90% of the calculated nyquist frequency + cutoff = cutoff * cutoffFactor; if (pt1) { cutoff = sq(cutoff) / RC_SMOOTHING_IDENTITY_FREQUENCY; // convert to a cutoff for pt1 that has similar characteristics diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index 1ffcf48ab..fccc576e5 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -631,6 +631,7 @@ const clivalue_t valueTable[] = { { "rc_smoothing_debug_axis", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_RC_SMOOTHING_DEBUG }, PG_RX_CONFIG, offsetof(rxConfig_t, rc_smoothing_debug_axis) }, { "rc_smoothing_input_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_RC_SMOOTHING_INPUT_TYPE }, PG_RX_CONFIG, offsetof(rxConfig_t, rc_smoothing_input_type) }, { "rc_smoothing_derivative_type",VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_RC_SMOOTHING_DERIVATIVE_TYPE }, PG_RX_CONFIG, offsetof(rxConfig_t, rc_smoothing_derivative_type) }, + { "rc_smoothing_auto_smoothness",VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 50 }, PG_RX_CONFIG, offsetof(rxConfig_t, rc_smoothing_auto_factor) }, #endif // USE_RC_SMOOTHING_FILTER { "fpv_mix_degrees", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 90 }, PG_RX_CONFIG, offsetof(rxConfig_t, fpvCamAngleDegrees) }, diff --git a/src/main/pg/rx.c b/src/main/pg/rx.c index e106da5f0..8454e803d 100644 --- a/src/main/pg/rx.c +++ b/src/main/pg/rx.c @@ -67,6 +67,7 @@ void pgResetFn_rxConfig(rxConfig_t *rxConfig) .rc_smoothing_debug_axis = ROLL, // default to debug logging for the roll axis .rc_smoothing_input_type = RC_SMOOTHING_INPUT_BIQUAD, .rc_smoothing_derivative_type = RC_SMOOTHING_DERIVATIVE_BIQUAD, + .rc_smoothing_auto_factor = 10, ); #ifdef RX_CHANNELS_TAER diff --git a/src/main/pg/rx.h b/src/main/pg/rx.h index b878f45f4..465ef9104 100644 --- a/src/main/pg/rx.h +++ b/src/main/pg/rx.h @@ -56,6 +56,7 @@ typedef struct rxConfig_s { uint8_t rc_smoothing_debug_axis; // Axis to log as debug values when debug_mode = RC_SMOOTHING uint8_t rc_smoothing_input_type; // Input filter type (0 = PT1, 1 = BIQUAD) uint8_t rc_smoothing_derivative_type; // Derivative filter type (0 = OFF, 1 = PT1, 2 = BIQUAD) + uint8_t rc_smoothing_auto_factor; // Used to adjust the "smoothness" determined by the auto cutoff calculations } rxConfig_t; PG_DECLARE(rxConfig_t, rxConfig);