-
Notifications
You must be signed in to change notification settings - Fork 18.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filtering: re-work harmonic notch filter freq clamping and disable #25442
Changes from all commits
22f2b3f
d24c2be
210b2a1
1559dcd
ffc6590
5706eab
4b3780e
210ea26
f2c9f5a
f38f154
b4a493f
088e1d3
d6a9627
07cd9f8
4a921e1
f45fd83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -750,7 +750,6 @@ void AP_Vehicle::update_throttle_notch(AP_InertialSensor::HarmonicNotch ¬ch) | |
#if APM_BUILD_TYPE(APM_BUILD_ArduPlane)||APM_BUILD_COPTER_OR_HELI||APM_BUILD_TYPE(APM_BUILD_Rover) | ||
const float ref_freq = notch.params.center_freq_hz(); | ||
const float ref = notch.params.reference(); | ||
const float min_ratio = notch.params.freq_min_ratio(); | ||
|
||
#if APM_BUILD_TYPE(APM_BUILD_ArduPlane)||APM_BUILD_COPTER_OR_HELI | ||
const AP_Motors* motors = AP::motors(); | ||
|
@@ -760,7 +759,7 @@ void AP_Vehicle::update_throttle_notch(AP_InertialSensor::HarmonicNotch ¬ch) | |
const float motors_throttle = motors != nullptr ? abs(motors->get_throttle() / 100.0f) : 0; | ||
#endif | ||
|
||
float throttle_freq = ref_freq * MAX(min_ratio, sqrtf(motors_throttle / ref)); | ||
float throttle_freq = ref_freq * sqrtf(MAX(0,motors_throttle) / ref); | ||
tridge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
notch.update_freq_hz(throttle_freq); | ||
#endif | ||
|
@@ -780,17 +779,6 @@ void AP_Vehicle::update_dynamic_notch(AP_InertialSensor::HarmonicNotch ¬ch) | |
return; | ||
} | ||
|
||
#if APM_BUILD_TYPE(APM_BUILD_ArduPlane)||APM_BUILD_COPTER_OR_HELI | ||
const AP_Motors* motors = AP::motors(); | ||
if (motors != nullptr && motors->get_spool_state() == AP_Motors::SpoolState::SHUT_DOWN) { | ||
notch.set_inactive(true); | ||
} else { | ||
notch.set_inactive(false); | ||
} | ||
#else // APM_BUILD_Rover: keep notch active | ||
notch.set_inactive(false); | ||
#endif | ||
|
||
switch (notch.params.tracking_mode()) { | ||
case HarmonicNotchDynamicMode::UpdateThrottle: // throttle based tracking | ||
// set the harmonic notch filter frequency approximately scaled on motor rpm implied by throttle | ||
|
@@ -805,9 +793,9 @@ void AP_Vehicle::update_dynamic_notch(AP_InertialSensor::HarmonicNotch ¬ch) | |
float rpm; | ||
if (rpm_sensor != nullptr && rpm_sensor->get_rpm(sensor, rpm)) { | ||
// set the harmonic notch filter frequency from the main rotor rpm | ||
notch.update_freq_hz(MAX(ref_freq * notch.params.freq_min_ratio(), rpm * ref * (1.0/60))); | ||
notch.update_freq_hz(rpm * ref * (1.0/60)); | ||
} else { | ||
notch.update_freq_hz(ref_freq); | ||
notch.update_freq_hz(0); | ||
tridge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
break; | ||
} | ||
|
@@ -819,18 +807,13 @@ void AP_Vehicle::update_dynamic_notch(AP_InertialSensor::HarmonicNotch ¬ch) | |
float notches[INS_MAX_NOTCHES]; | ||
// ESC telemetry will return 0 for missing data, but only after 1s | ||
const uint8_t num_notches = AP::esc_telem().get_motor_frequencies_hz(INS_MAX_NOTCHES, notches); | ||
for (uint8_t i = 0; i < num_notches; i++) { | ||
if (!is_zero(notches[i])) { | ||
notches[i] = MAX(ref_freq, notches[i]); | ||
} | ||
} | ||
if (num_notches > 0) { | ||
notch.update_frequencies_hz(num_notches, notches); | ||
} else { // throttle fallback | ||
update_throttle_notch(notch); | ||
} | ||
} else { | ||
notch.update_freq_hz(MAX(ref_freq, AP::esc_telem().get_average_motor_frequency_hz() * ref)); | ||
notch.update_freq_hz(AP::esc_telem().get_average_motor_frequency_hz() * ref); | ||
} | ||
break; | ||
#endif | ||
|
@@ -842,20 +825,14 @@ void AP_Vehicle::update_dynamic_notch(AP_InertialSensor::HarmonicNotch ¬ch) | |
const uint8_t peaks = gyro_fft.get_weighted_noise_center_frequencies_hz(notch.num_dynamic_notches, notches); | ||
|
||
if (peaks > 0) { | ||
for (uint8_t i = 0; i < peaks; i++) { | ||
notches[i] = MAX(ref_freq, notches[i]); | ||
} | ||
notch.set_inactive(false); | ||
notch.update_frequencies_hz(peaks, notches); | ||
} else { // since FFT can be used post-filter it is better to disable the notch when there is no data | ||
notch.set_inactive(true); | ||
} | ||
} else { | ||
float center_freq = gyro_fft.get_weighted_noise_center_freq_hz(); | ||
if (!is_zero(center_freq)) { | ||
notch.update_freq_hz(MAX(ref_freq, center_freq)); | ||
} else { // since FFT can be used post-filter it is better to disable the notch when there is no data | ||
notch.set_inactive(true); | ||
} | ||
notch.update_freq_hz(center_freq); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think zero is special in the FFT engine here - we should check - so this code might be wrong to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you check that? looks like zero could be returned if unhealthy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes zero is a special value here. Unhealthy simply means that no peaks were detected, which is quite common in post-filter analysis hence why we need to switch off the notches. Same is actually true for the first if clause above it so we need to make sure we disable the notches that do not have peaks - or return a special value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using zero will switch off the notch, unless you have TreatLowAsMin which means the user wants to keep it running anyway. So this really should be equivalent to the old code |
||
} | ||
break; | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is the existing behavior, but this looks like I could not change bandwidth or attenuation at runtime for any of the moving notches?
Why not call a init for param change for all types? Then just call update if moving.
Should we also track the enable param? What if I turn on or off a notch at run time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is existing behaviour?