Skip to content

Commit

Permalink
using same curve of dyn dterm lpf
Browse files Browse the repository at this point in the history
  • Loading branch information
IllusionFpv committed Aug 8, 2020
1 parent 988024e commit d0fe845
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/cli/settings.c
Expand Up @@ -666,6 +666,7 @@ const clivalue_t valueTable[] = {
#ifdef USE_DYN_LPF
{ "dyn_lpf_gyro_min_hz", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 1000 }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, dyn_lpf_gyro_min_hz) },
{ "dyn_lpf_gyro_max_hz", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 1000 }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, dyn_lpf_gyro_max_hz) },
{ "dyn_lpf_gyro_curve_expo", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 10 }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, dyn_lpf_curve_expo) },
#endif
{ "gyro_filter_debug_axis", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_GYRO_FILTER_DEBUG }, PG_GYRO_CONFIG, offsetof(gyroConfig_t, gyro_filter_debug_axis) },

Expand Down
4 changes: 2 additions & 2 deletions src/main/flight/pid.c
Expand Up @@ -1189,7 +1189,7 @@ void dynLpfDTermUpdate(float throttle)
static unsigned int cutoffFreq;
if (pidRuntime.dynLpfFilter != DYN_LPF_NONE) {
if (pidRuntime.dynLpfCurveExpo > 0) {
cutoffFreq = dynDtermLpfCutoffFreq(throttle, pidRuntime.dynLpfMin, pidRuntime.dynLpfMax, pidRuntime.dynLpfCurveExpo);
cutoffFreq = dynLpfCutoffFreq(throttle, pidRuntime.dynLpfMin, pidRuntime.dynLpfMax, pidRuntime.dynLpfCurveExpo);
} else {
cutoffFreq = fmax(dynThrottle(throttle) * pidRuntime.dynLpfMax, pidRuntime.dynLpfMin);
}
Expand All @@ -1207,7 +1207,7 @@ void dynLpfDTermUpdate(float throttle)
}
#endif

float dynDtermLpfCutoffFreq(float throttle, uint16_t dynLpfMin, uint16_t dynLpfMax, uint8_t expo) {
float dynLpfCutoffFreq(float throttle, uint16_t dynLpfMin, uint16_t dynLpfMax, uint8_t expo) {
const float expof = expo / 10.0f;
static float curve;
curve = throttle * (1 - throttle) * expof + throttle;
Expand Down
2 changes: 1 addition & 1 deletion src/main/flight/pid.h
Expand Up @@ -414,4 +414,4 @@ float pidGetPidFrequency();
float pidGetFfBoostFactor();
float pidGetFfSmoothFactor();
float pidGetSpikeLimitInverse();
float dynDtermLpfCutoffFreq(float throttle, uint16_t dynLpfMin, uint16_t dynLpfMax, uint8_t expo);
float dynLpfCutoffFreq(float throttle, uint16_t dynLpfMin, uint16_t dynLpfMax, uint8_t expo);
9 changes: 7 additions & 2 deletions src/main/sensors/gyro.c
Expand Up @@ -132,6 +132,7 @@ void pgResetFn_gyroConfig(gyroConfig_t *gyroConfig)
gyroConfig->dyn_notch_q = 120;
gyroConfig->dyn_notch_min_hz = 150;
gyroConfig->gyro_filter_debug_axis = FD_ROLL;
gyroConfig->dyn_lpf_curve_expo = 0;
}

#ifdef USE_GYRO_DATA_ANALYSE
Expand Down Expand Up @@ -625,8 +626,12 @@ float dynThrottle(float throttle) {
void dynLpfGyroUpdate(float throttle)
{
if (gyro.dynLpfFilter != DYN_LPF_NONE) {
const unsigned int cutoffFreq = (gyro.dynLpfMax - gyro.dynLpfMin) * dynThrottle(throttle) + gyro.dynLpfMin;

static unsigned int cutoffFreq;
if (gyro.dynLpfCurveExpo > 0) {
cutoffFreq = dynLpfCutoffFreq(throttle, gyro.dynLpfMin, gyro.dynLpfMax, gyro.dynLpfCurveExpo);
} else {
cutoffFreq = fmax(dynThrottle(throttle) * gyro.dynLpfMax, gyro.dynLpfMin);
}
if (gyro.dynLpfFilter == DYN_LPF_PT1) {
DEBUG_SET(DEBUG_DYN_LPF, 2, cutoffFreq);
const float gyroDt = gyro.targetLooptime * 1e-6f;
Expand Down
2 changes: 2 additions & 0 deletions src/main/sensors/gyro.h
Expand Up @@ -122,6 +122,7 @@ typedef struct gyro_s {
uint8_t dynLpfFilter;
uint16_t dynLpfMin;
uint16_t dynLpfMax;
uint8_t dynLpfCurveExpo;
#endif

#ifdef USE_GYRO_OVERFLOW_CHECK
Expand Down Expand Up @@ -197,6 +198,7 @@ typedef struct gyroConfig_s {
uint8_t gyro_filter_debug_axis;

uint8_t gyrosDetected; // What gyros should detection be attempted for on startup. Automatically set on first startup.
uint8_t dyn_lpf_curve_expo; // set the curve for dynamic gyro lowpass filter
} gyroConfig_t;

PG_DECLARE(gyroConfig_t, gyroConfig);
Expand Down
1 change: 1 addition & 0 deletions src/main/sensors/gyro_init.c
Expand Up @@ -228,6 +228,7 @@ static void dynLpfFilterInit()
}
gyro.dynLpfMin = gyroConfig()->dyn_lpf_gyro_min_hz;
gyro.dynLpfMax = gyroConfig()->dyn_lpf_gyro_max_hz;
gyro.dynLpfCurveExpo = gyroConfig()->dyn_lpf_curve_expo;
}
#endif

Expand Down

0 comments on commit d0fe845

Please sign in to comment.