Adding more servos
[inav.git] / src / main / flight / gyroanalyse.h
blob2cfd19389fcc7ca346428c49620225b792e9cbf5
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #ifdef USE_DYNAMIC_FILTERS
25 #include "arm_math.h"
26 #include "common/filter.h"
29 * Current code works only with 64 window size. Changing it do a different size would require
30 * adapting the gyroDataAnalyseUpdate in STEP_ARM_CFFT_F32 step
32 #define FFT_WINDOW_SIZE 64
34 typedef struct peak_s {
35 int bin;
36 float value;
37 } peak_t;
39 typedef struct gyroAnalyseState_s {
40 // accumulator for oversampled data => no aliasing and less noise
41 float currentSample[XYZ_AXIS_COUNT];
43 // downsampled gyro data circular buffer for frequency analysis
44 uint8_t circularBufferIdx;
45 float downsampledGyroData[XYZ_AXIS_COUNT][FFT_WINDOW_SIZE];
47 // update state machine step information
48 uint8_t updateStep;
49 uint8_t updateAxis;
51 arm_rfft_fast_instance_f32 fftInstance;
52 float fftData[FFT_WINDOW_SIZE];
53 float rfftData[FFT_WINDOW_SIZE];
55 pt1Filter_t detectedFrequencyFilter[XYZ_AXIS_COUNT][DYN_NOTCH_PEAK_COUNT];
56 float centerFrequency[XYZ_AXIS_COUNT][DYN_NOTCH_PEAK_COUNT];
58 peak_t peaks[DYN_NOTCH_PEAK_COUNT];
60 bool filterUpdateExecute;
61 uint8_t filterUpdateAxis;
62 uint16_t filterUpdateFrequency;
64 uint16_t fftSamplingRateHz;
65 uint8_t fftStartBin;
66 float fftResolution;
67 uint16_t minFrequency;
68 uint16_t maxFrequency;
70 // Hanning window, see https://en.wikipedia.org/wiki/Window_function#Hann_.28Hanning.29_window
71 float hanningWindow[FFT_WINDOW_SIZE];
72 } gyroAnalyseState_t;
74 STATIC_ASSERT(FFT_WINDOW_SIZE <= (uint8_t) -1, window_size_greater_than_underlying_type);
76 void gyroDataAnalyseStateInit(
77 gyroAnalyseState_t *state,
78 uint16_t minFrequency,
79 uint32_t targetLooptimeUs
81 void gyroDataAnalysePush(gyroAnalyseState_t *gyroAnalyse, int axis, float sample);
82 void gyroDataAnalyse(gyroAnalyseState_t *gyroAnalyse);
83 #endif