Skip to content

Commit 8182e36

Browse files
Quick-FlashnerdCopter
authored andcommitted
dynamic notch on pidsum
gyro->pidum is not a linear change. dynamic notch on pidsum might better account for dterm and other dynamics going on.
1 parent fe7710c commit 8182e36

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

src/main/build/debug.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ const char * const debugModeNames[DEBUG_COUNT] = {
9999
"TIMING_ACCURACY",
100100
"RX_EXPRESSLRS_SPI",
101101
"RX_EXPRESSLRS_PHASELOCK",
102-
"RX_STATE_TIME"
102+
"RX_STATE_TIME",
103+
"PIDSUM",
103104
};

src/main/build/debug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ typedef enum {
9898
DEBUG_RX_EXPRESSLRS_SPI,
9999
DEBUG_RX_EXPRESSLRS_PHASELOCK,
100100
DEBUG_RX_STATE_TIME,
101+
DEBUG_PIDSUM,
101102
DEBUG_COUNT
102103
} debugType_e;
103104

src/main/flight/pid.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#include "flight/mixer.h"
5050
#include "flight/rpm_filter.h"
5151
#include "flight/feedforward.h"
52+
#ifdef USE_DYN_NOTCH_FILTER
53+
#include "flight/dyn_notch_filter.h"
54+
#endif
5255

5356
#include "io/gps.h"
5457

@@ -1125,7 +1128,7 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, timeUs_t currentTim
11251128
if (feedforwardGain > 0) {
11261129
// halve feedforward in Level mode since stick sensitivity is weaker by about half
11271130
feedforwardGain *= FLIGHT_MODE(ANGLE_MODE) ? 0.5f : 1.0f;
1128-
// transition now calculated in feedforward.c when new RC data arrives
1131+
// transition now calculated in feedforward.c when new RC data arrives
11291132
float feedForward = feedforwardGain * pidSetpointDelta * pidRuntime.pidFrequency;
11301133

11311134
#ifdef USE_FEEDFORWARD
@@ -1193,7 +1196,31 @@ void FAST_CODE pidController(const pidProfile_t *pidProfile, timeUs_t currentTim
11931196
{
11941197
pidData[axis].Sum = pidSum;
11951198
}
1199+
1200+
#ifdef USE_DYN_NOTCH_FILTER
1201+
if (isDynNotchActive()) {
1202+
// if (axis == gyro.gyroDebugAxis) {
1203+
// GYRO_FILTER_DEBUG_SET(DEBUG_FFT, 0, lrintf(gyroADCf));
1204+
// GYRO_FILTER_DEBUG_SET(DEBUG_FFT_FREQ, 3, lrintf(gyroADCf));
1205+
// GYRO_FILTER_DEBUG_SET(DEBUG_DYN_LPF, 0, lrintf(gyroADCf));
1206+
// }
1207+
1208+
dynNotchPush(axis, pidData[axis].Sum);
1209+
pidData[axis].Sum = dynNotchFilter(axis, pidData[axis].Sum);
1210+
1211+
// if (axis == gyro.gyroDebugAxis) {
1212+
// GYRO_FILTER_DEBUG_SET(DEBUG_FFT, 1, lrintf(gyroADCf));
1213+
// GYRO_FILTER_DEBUG_SET(DEBUG_DYN_LPF, 3, lrintf(gyroADCf));
1214+
// }
1215+
}
1216+
#endif
1217+
DEBUG_SET(DEBUG_PIDSUM, axis, lrintf(pidData[axis].Sum));
1218+
}
1219+
#ifdef USE_DYN_NOTCH_FILTER
1220+
if (isDynNotchActive()) {
1221+
dynNotchUpdate();
11961222
}
1223+
#endif
11971224

11981225
// Disable PID control if at zero throttle or if gyro overflow detected
11991226
// This may look very innefficient, but it is done on purpose to always show real CPU usage as in flight

src/main/flight/pid_init.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#include "flight/feedforward.h"
4040
#include "flight/pid.h"
4141
#include "flight/rpm_filter.h"
42+
#ifdef USE_DYN_NOTCH_FILTER
43+
#include "flight/dyn_notch_filter.h"
44+
#endif
4245

4346
#include "sensors/gyro.h"
4447
#include "sensors/sensors.h"
@@ -238,6 +241,9 @@ void pidInitFilters(const pidProfile_t *pidProfile)
238241

239242
pt1FilterInit(&pidRuntime.antiGravityThrottleLpf, pt1FilterGain(ANTI_GRAVITY_THROTTLE_FILTER_CUTOFF, pidRuntime.dT));
240243
pt1FilterInit(&pidRuntime.antiGravitySmoothLpf, pt1FilterGain(ANTI_GRAVITY_SMOOTH_FILTER_CUTOFF, pidRuntime.dT));
244+
#ifdef USE_DYN_NOTCH_FILTER
245+
dynNotchInit(dynNotchConfig(), targetPidLooptime);
246+
#endif
241247
}
242248

243249
void pidInit(const pidProfile_t *pidProfile)
@@ -440,4 +446,3 @@ void pidCopyProfile(uint8_t dstPidProfileIndex, uint8_t srcPidProfileIndex)
440446
memcpy(pidProfilesMutable(dstPidProfileIndex), pidProfilesMutable(srcPidProfileIndex), sizeof(pidProfile_t));
441447
}
442448
}
443-

src/main/sensors/gyro.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
#include "config/config.h"
4646
#include "fc/runtime_config.h"
4747

48-
#ifdef USE_DYN_NOTCH_FILTER
49-
#include "flight/dyn_notch_filter.h"
50-
#endif
5148
#include "flight/rpm_filter.h"
5249

5350
#include "io/beeper.h"
@@ -110,7 +107,7 @@ void pgResetFn_gyroConfig(gyroConfig_t *gyroConfig)
110107
gyroConfig->gyroMovementCalibrationThreshold = 48;
111108
gyroConfig->gyro_hardware_lpf = GYRO_HARDWARE_LPF_NORMAL;
112109
gyroConfig->gyro_lpf1_type = FILTER_PT1;
113-
gyroConfig->gyro_lpf1_static_hz = GYRO_LPF1_DYN_MIN_HZ_DEFAULT;
110+
gyroConfig->gyro_lpf1_static_hz = GYRO_LPF1_DYN_MIN_HZ_DEFAULT;
114111
// NOTE: dynamic lpf is enabled by default so this setting is actually
115112
// overridden and the static lowpass 1 is disabled. We can't set this
116113
// value to 0 otherwise Configurator versions 10.4 and earlier will also
@@ -472,12 +469,6 @@ FAST_CODE void gyroFiltering(timeUs_t currentTimeUs)
472469
filterGyroDebug();
473470
}
474471

475-
#ifdef USE_DYN_NOTCH_FILTER
476-
if (isDynNotchActive()) {
477-
dynNotchUpdate();
478-
}
479-
#endif
480-
481472
if (gyro.useDualGyroDebugging) {
482473
switch (gyro.gyroToUse) {
483474
case GYRO_CONFIG_USE_GYRO_1:

src/main/sensors/gyro_filter_impl.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,6 @@ static FAST_CODE void GYRO_FILTER_FUNCTION_NAME(void)
6464
// DEBUG_GYRO_SAMPLE(3) Record the post-static notch and lowpass filter value for the selected debug axis
6565
GYRO_FILTER_AXIS_DEBUG_SET(axis, DEBUG_GYRO_SAMPLE, 3, lrintf(gyroADCf));
6666

67-
#ifdef USE_DYN_NOTCH_FILTER
68-
if (isDynNotchActive()) {
69-
if (axis == gyro.gyroDebugAxis) {
70-
GYRO_FILTER_DEBUG_SET(DEBUG_FFT, 0, lrintf(gyroADCf));
71-
GYRO_FILTER_DEBUG_SET(DEBUG_FFT_FREQ, 3, lrintf(gyroADCf));
72-
GYRO_FILTER_DEBUG_SET(DEBUG_DYN_LPF, 0, lrintf(gyroADCf));
73-
}
74-
75-
dynNotchPush(axis, gyroADCf);
76-
gyroADCf = dynNotchFilter(axis, gyroADCf);
77-
78-
if (axis == gyro.gyroDebugAxis) {
79-
GYRO_FILTER_DEBUG_SET(DEBUG_FFT, 1, lrintf(gyroADCf));
80-
GYRO_FILTER_DEBUG_SET(DEBUG_DYN_LPF, 3, lrintf(gyroADCf));
81-
}
82-
}
83-
#endif
84-
8567
// DEBUG_GYRO_FILTERED records the scaled, filtered, after all software filtering has been applied.
8668
GYRO_FILTER_DEBUG_SET(DEBUG_GYRO_FILTERED, axis, lrintf(gyroADCf));
8769

src/main/sensors/gyro_init.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@
6363

6464
#include "fc/runtime_config.h"
6565

66-
#ifdef USE_DYN_NOTCH_FILTER
67-
#include "flight/dyn_notch_filter.h"
68-
#endif
69-
7066
#include "pg/gyrodev.h"
7167

7268
#include "sensors/gyro.h"
@@ -263,9 +259,6 @@ void gyroInitFilters(void)
263259
#ifdef USE_DYN_LPF
264260
dynLpfFilterInit();
265261
#endif
266-
#ifdef USE_DYN_NOTCH_FILTER
267-
dynNotchInit(dynNotchConfig(), gyro.targetLooptime);
268-
#endif
269262
}
270263

271264
#if defined(USE_GYRO_SLEW_LIMITER)

0 commit comments

Comments
 (0)