31
31
#include "common/filter.h"
32
32
#include "common/maths.h"
33
33
#include "common/time.h"
34
+ #include "common/auto_notch.h"
34
35
35
36
#include "drivers/dshot.h"
36
37
@@ -62,7 +63,7 @@ typedef struct rpmNotchFilter_s {
62
63
float q ;
63
64
timeUs_t looptimeUs ;
64
65
65
- biquadFilter_t notch [XYZ_AXIS_COUNT ][MAX_SUPPORTED_MOTORS ][RPM_FILTER_MAXHARMONICS ];
66
+ autoNotch_t notch [XYZ_AXIS_COUNT ][MAX_SUPPORTED_MOTORS ][RPM_FILTER_MAXHARMONICS ];
66
67
67
68
} rpmNotchFilter_t ;
68
69
@@ -94,6 +95,8 @@ void pgResetFn_rpmFilterConfig(rpmFilterConfig_t *config)
94
95
config -> rpm_filter_q = 500 ;
95
96
96
97
config -> rpm_filter_lpf_hz = 150 ;
98
+
99
+ config -> noise_limit = 50 ;
97
100
}
98
101
99
102
static void rpmNotchFilterInit (rpmNotchFilter_t * filter , const rpmFilterConfig_t * config , const timeUs_t looptimeUs )
@@ -108,8 +111,8 @@ static void rpmNotchFilterInit(rpmNotchFilter_t *filter, const rpmFilterConfig_t
108
111
for (int axis = 0 ; axis < XYZ_AXIS_COUNT ; axis ++ ) {
109
112
for (int motor = 0 ; motor < getMotorCount (); motor ++ ) {
110
113
for (int i = 0 ; i < filter -> harmonics ; i ++ ) {
111
- biquadFilterInit (
112
- & filter -> notch [axis ][motor ][i ], filter -> minHz * i , filter -> looptimeUs , filter -> q , FILTER_NOTCH , 0.0f );
114
+ initAutoNotch (
115
+ & filter -> notch [axis ][motor ][i ], filter -> minHz * i , filter -> q , config -> noise_limit , filter -> looptimeUs );
113
116
}
114
117
}
115
118
}
@@ -153,7 +156,7 @@ static float applyFilter(rpmNotchFilter_t *filter, const int axis, float value)
153
156
}
154
157
for (int motor = 0 ; motor < getMotorCount (); motor ++ ) {
155
158
for (int i = 0 ; i < filter -> harmonics ; i ++ ) {
156
- value = biquadFilterApplyDF1Weighted (& filter -> notch [axis ][motor ][i ], value );
159
+ value = applyAutoNotch (& filter -> notch [axis ][motor ][i ], value );
157
160
}
158
161
}
159
162
return value ;
@@ -183,31 +186,37 @@ FAST_CODE_NOINLINE void rpmFilterUpdate(void)
183
186
184
187
float frequency = constrainf (
185
188
(currentHarmonic + 1 ) * motorFrequency [currentMotor ], currentFilter -> minHz , currentFilter -> maxHz );
186
- biquadFilter_t * template = & currentFilter -> notch [0 ][currentMotor ][currentHarmonic ];
189
+ autoNotch_t * template = & currentFilter -> notch [0 ][currentMotor ][currentHarmonic ];
187
190
// uncomment below to debug filter stepping. Need to also comment out motor rpm DEBUG_SET above
188
191
/* DEBUG_SET(DEBUG_RPM_FILTER, 0, harmonic); */
189
192
/* DEBUG_SET(DEBUG_RPM_FILTER, 1, motor); */
190
193
/* DEBUG_SET(DEBUG_RPM_FILTER, 2, currentFilter == &gyroFilter); */
191
194
/* DEBUG_SET(DEBUG_RPM_FILTER, 3, frequency) */
192
-
195
+
193
196
// fade out notch when approaching minHz (turn it off)
194
197
float weight = 1.0f ;
195
198
if (frequency < currentFilter -> minHz + currentFilter -> fadeRangeHz ) {
196
199
weight = (frequency - currentFilter -> minHz ) / currentFilter -> fadeRangeHz ;
197
200
}
198
201
199
- biquadFilterUpdate (
200
- template , frequency , currentFilter -> looptimeUs , currentFilter -> q , FILTER_NOTCH , weight );
202
+ updateAutoNotch (
203
+ template , frequency , currentFilter -> q , weight , currentFilter -> looptimeUs );
201
204
202
205
for (int axis = 1 ; axis < XYZ_AXIS_COUNT ; axis ++ ) {
203
- biquadFilter_t * clone = & currentFilter -> notch [axis ][currentMotor ][currentHarmonic ];
204
- clone -> b0 = template -> b0 ;
205
- clone -> b1 = template -> b1 ;
206
- clone -> b2 = template -> b2 ;
207
- clone -> a1 = template -> a1 ;
208
- clone -> a2 = template -> a2 ;
209
- clone -> weight = template -> weight ;
210
- }
206
+ autoNotch_t * clone = & currentFilter -> notch [axis ][currentMotor ][currentHarmonic ];
207
+ clone -> notchFilter .b0 = template -> notchFilter .b0 ;
208
+ clone -> notchFilter .b1 = template -> notchFilter .b1 ;
209
+ clone -> notchFilter .b2 = template -> notchFilter .b2 ;
210
+ clone -> notchFilter .a1 = template -> notchFilter .a1 ;
211
+ clone -> notchFilter .a2 = template -> notchFilter .a2 ;
212
+
213
+ clone -> preVarianceBandpass .b0 = template -> preVarianceBandpass .b0 ;
214
+ //clone->preVarianceBandpass.b1 = template->preVarianceBandpass.b1; // always 0
215
+ clone -> preVarianceBandpass .b2 = template -> preVarianceBandpass .b2 ;
216
+ clone -> preVarianceBandpass .b0 = template -> preVarianceBandpass .a1 ;
217
+ clone -> preVarianceBandpass .b2 = template -> preVarianceBandpass .a2 ;
218
+ updateWeight (clone , weight );
219
+ }
211
220
212
221
if (++ currentHarmonic == currentFilter -> harmonics ) {
213
222
currentHarmonic = 0 ;
0 commit comments