From 9077d41df139b2e570c99d32dca5343f324c2841 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Fri, 29 May 2020 17:31:46 +0100 Subject: [PATCH] Plane: add support for tracking fft peaks and individual motor rpms with harmonic notches log harmonic notch even if FFT is disabled. Fallback to throttle notch for BLHeli move harmonic notch update to AP_Vehicle --- ArduPlane/ArduPlane.cpp | 3 ++- ArduPlane/Plane.h | 2 +- ArduPlane/system.cpp | 30 +++++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ArduPlane/ArduPlane.cpp b/ArduPlane/ArduPlane.cpp index 6693fde987..67c92216da 100644 --- a/ArduPlane/ArduPlane.cpp +++ b/ArduPlane/ArduPlane.cpp @@ -110,7 +110,6 @@ const AP_Scheduler::Task Plane::scheduler_tasks[] = { #if EFI_ENABLED SCHED_TASK(efi_update, 10, 200), #endif - SCHED_TASK(update_dynamic_notch, 50, 200), }; void Plane::get_scheduler_tasks(const AP_Scheduler::Task *&tasks, @@ -218,6 +217,8 @@ void Plane::update_logging2(void) Log_Write_Control_Tuning(); #if HAL_GYROFFT_ENABLED gyro_fft.write_log_messages(); +#else + write_notch_log_messages(); #endif } diff --git a/ArduPlane/Plane.h b/ArduPlane/Plane.h index 8e643995ac..537106f601 100644 --- a/ArduPlane/Plane.h +++ b/ArduPlane/Plane.h @@ -1014,7 +1014,7 @@ private: void startup_INS_ground(void); bool should_log(uint32_t mask); int8_t throttle_percentage(void); - void update_dynamic_notch(); + void update_dynamic_notch() override; void notify_mode(const Mode& mode); // takeoff.cpp diff --git a/ArduPlane/system.cpp b/ArduPlane/system.cpp index 2a2c0fb660..0f2dd4c7b9 100644 --- a/ArduPlane/system.cpp +++ b/ArduPlane/system.cpp @@ -456,7 +456,7 @@ void Plane::update_dynamic_notch() } switch (ins.get_gyro_harmonic_notch_tracking_mode()) { - case HarmonicNotchDynamicMode::UpdateThrottle: // throttle based tracking + case HarmonicNotchDynamicMode::UpdateThrottle: // throttle based tracking // set the harmonic notch filter frequency approximately scaled on motor rpm implied by throttle if (quadplane.available()) { ins.update_harmonic_notch_freq_hz(ref_freq * MAX(1.0f, sqrtf(quadplane.motors->get_throttle_out() / ref))); @@ -474,13 +474,37 @@ void Plane::update_dynamic_notch() break; #ifdef HAVE_AP_BLHELI_SUPPORT case HarmonicNotchDynamicMode::UpdateBLHeli: // BLHeli based tracking - ins.update_harmonic_notch_freq_hz(MAX(ref_freq, AP_BLHeli::get_singleton()->get_average_motor_frequency_hz() * ref)); + // set the harmonic notch filter frequency scaled on measured frequency + if (ins.has_harmonic_option(HarmonicNotchFilterParams::Options::DynamicHarmonic)) { + float notches[INS_MAX_NOTCHES]; + const uint8_t num_notches = AP_BLHeli::get_singleton()->get_motor_frequencies_hz(INS_MAX_NOTCHES, notches); + + for (uint8_t i = 0; i < num_notches; i++) { + notches[i] = MAX(ref_freq, notches[i]); + } + if (num_notches > 0) { + ins.update_harmonic_notch_frequencies_hz(num_notches, notches); + } else if (quadplane.available()) { // throttle fallback + ins.update_harmonic_notch_freq_hz(ref_freq * MAX(1.0f, sqrtf(quadplane.motors->get_throttle_out() / ref))); + } else { + ins.update_harmonic_notch_freq_hz(ref_freq); + } + } else { + ins.update_harmonic_notch_freq_hz(MAX(ref_freq, AP_BLHeli::get_singleton()->get_average_motor_frequency_hz() * ref)); + } break; #endif #if HAL_GYROFFT_ENABLED case HarmonicNotchDynamicMode::UpdateGyroFFT: // FFT based tracking // set the harmonic notch filter frequency scaled on measured frequency - ins.update_harmonic_notch_freq_hz(gyro_fft.get_weighted_noise_center_freq_hz()); + if (ins.has_harmonic_option(HarmonicNotchFilterParams::Options::DynamicHarmonic)) { + float notches[INS_MAX_NOTCHES]; + const uint8_t peaks = gyro_fft.get_weighted_noise_center_frequencies_hz(INS_MAX_NOTCHES, notches); + + ins.update_harmonic_notch_frequencies_hz(peaks, notches); + } else { + ins.update_harmonic_notch_freq_hz(gyro_fft.get_weighted_noise_center_freq_hz()); + } break; #endif case HarmonicNotchDynamicMode::Fixed: // static