Filter: HarmonicNotch: fix Quintuple Notch - #33974
Conversation
|
There might be some argument that we should increment the filter version flag again since updating it to 3 did not really add support for quintuple notch. |
|
Some more proof that they never worked, they are never hit in the coverage test https://firmware.ardupilot.org/coverage/Filter/HarmonicNotchFilter.cpp.gcov.html.
|
|
When I tested it it would have been on a 4.6 derivative rather than master so its conceivable that I did not get bitten by some of the other rework of this area of code. |
The constrain was added in #21026, it is in 4.6 |
DynamicNotches enabled the double, triple and quintuple notch options and checked only that the FFT peak beat the single-notch peak. A quintuple notch which silently ran as a triple notch passed that check, so the option being entirely non-functional went unnoticed. Enable notch-per-motor for the composite notch runs so that the number of allocated filters appears in the NF field of FCN, and check it against the expected motors * harmonics * composite count. This also moves throttle tracking onto per-motor thrust, so those runs fly a notch per motor; the existing peak checks still hold. Note this does not cover the case where the filter count is clamped to HAL_HNF_MAX_FILTERS, which is not reachable from SITL. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
update() checks that a spare filter is available once per harmonic, but then writes one filter for each notch of the composite. When the filter count is clamped to HAL_HNF_MAX_FILTERS the last composite can run off the end of the array, as neither 78 nor 39 is a multiple of 5. More frequency sources can arrive than were allocated for at startup, as AP_ESC_Telem::get_motor_frequencies_hz reports every ESC sending telemetry rather than only those in the motor mask, so the clamp is reachable in flight. Fails under address sanitizer with a heap-buffer-overflow in set_center_frequency at index 78 of 78. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
0cf0889 to
5217e0e
Compare
…le number of harmonics
5217e0e to
caad765
Compare
|
I have added a fix for the notch count allocation. Because the notch count is not evaluated for the composite filters it could end up off the end of the array. This is a problem if the max number of notches is not a multiple of the number of composite filters. I think this bug exists in 4.6 and 4.7 with F7 as it has a limit of 39 notches. 39 is not divisible by 2, so with a double notch it would be possible to hit the bug. The other limits are all multiples of 1,2, and 3. |
|
Automated review note - AI-generated (Claude), independently cross-checked by a second model and re-verified against the diff. Please sanity-check before acting. Reviewed at head Verdict: COMMENT
Full report, including what was checked and found clean: https://uav.tridgell.net/DevCallReviews/DevCallTopic/devcall_pr_reviews.html |

Summary
As far as I can tell Quintuple Notch has never worked, this constrain resulted in them being silently converted to a triple notch. Found when writing ArduPilot/WebTools#332
They were added in #30994 and supposedly were tested and have a autotest.
Classification & Testing (check all that apply and add your own)
Description