diff --git a/libraries/AP_GyroFFT/AP_GyroFFT.cpp b/libraries/AP_GyroFFT/AP_GyroFFT.cpp index 82ac4fd49c..638a1eecef 100644 --- a/libraries/AP_GyroFFT/AP_GyroFFT.cpp +++ b/libraries/AP_GyroFFT/AP_GyroFFT.cpp @@ -248,10 +248,21 @@ void AP_GyroFFT::init(uint16_t loop_rate_hz) return; } - const uint8_t harmonics = _ins->get_gyro_harmonic_notch_harmonics(); + // check for harmonics across all harmonic notch filters + // note that we only allow one harmonic notch filter linked to the FFT code + uint8_t harmonics = 0; + uint8_t num_notches = 0; + for (uint8_t i=0; iget_gyro_harmonic_notch_tracking_mode(i) == HarmonicNotchDynamicMode::UpdateGyroFFT) { + harmonics = _ins->get_gyro_harmonic_notch_harmonics(i); + num_notches = _ins->get_num_gyro_dynamic_notches(i); + break; + } + } + // count the number of active harmonics or dynamic notchs _tracked_peaks = constrain_int16(MAX(__builtin_popcount(harmonics), - _ins->get_num_gyro_dynamic_notches()), 1, FrequencyPeak::MAX_TRACKED_PEAKS); + num_notches), 1, FrequencyPeak::MAX_TRACKED_PEAKS); // calculate harmonic multiplier. this assumes the harmonics configured on the // harmonic notch reflect the multiples of the fundamental harmonic that should be tracked