Skip to content
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

Filter: protect against extremely low notch filter frequencies #25352

Merged
merged 2 commits into from
Nov 2, 2023

Conversation

tridge
Copy link
Contributor

@tridge tridge commented Oct 24, 2023

an incorrectly configured ESC telemetry source can lead to a notch running at very low frequencies. A simple example is a lua script like this:

function update()
esc_telem:update_rpm(12, 0, 0)
return update, 10
end
return update()

where motor 12 is unused.

with that script in place we get a 1.0078 Hz filter which leads to massive phase lag and a crashed aircraft. I suspect the 1.0078 is the last value from the slew limiter before we hit 1.0 Hz
Note: this is a safety protection. We should also try to find out why the INS_HNTCH_FREQ lower limit is not working

this is what the filtered (in red) vs unfiltered (in green) looks like with the above lua script for a quadplane takeoff in QLOITER in SITL:
image
this is the same test with the protection in place:
image

@tridge tridge added the BUG label Oct 24, 2023
@tridge tridge requested a review from andyp1per October 24, 2023 08:32
Copy link
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better to change the existing limit in the init_with_A_and_Q function so initialised is never set true.

This line:

if ((new_center_freq > 0.0) && (new_center_freq < 0.5 * sample_freq_hz) && (Q > 0.0)) {

Would become:

if ((new_center_freq > 2.0) && (new_center_freq < 0.5 * sample_freq_hz) && (Q > 0.0)) {

@IamPete1
Copy link
Member

I think #25355 is the root of this issue.

@tridge tridge force-pushed the pr-zero-rpm-esc-notch branch from 60a1e96 to 5fab0e9 Compare November 1, 2023 04:42
@tridge
Copy link
Contributor Author

tridge commented Nov 1, 2023

I think #25355 is the root of this issue.

as noted on that PR, that does not properly fix the issue

Copy link
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good. I think the zero check on last_update_ms is needed in lots more places. Might be worth a helper function. There are 8 places that check the timeout.

@@ -107,7 +107,7 @@ uint32_t AP_ESC_Telem::get_active_esc_mask() const {
// have never seen telem from this ESC
continue;
}
if (now - _telem_data[i].last_update_ms >= ESC_TELEM_DATA_TIMEOUT_MS
if ((_telem_data[i].last_update_ms == 0 || now - _telem_data[i].last_update_ms >= ESC_TELEM_DATA_TIMEOUT_MS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though @WickedShell already had a helper for this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think a helper woulud make this clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added stale() helper

@andyp1per
Copy link
Collaborator

I think #25355 is the root of this issue.

as noted on that PR, that does not properly fix the issue

Yes, but its still a valid change. I think we need both changes.

an incorrectly configured ESC telemetry source can lead to a notch
running at very low frequencies. A simple example is a lua script like
this:

function update()
   esc_telem:update_rpm(12, 0, 0)
   return update, 10
end
return update()

where motor 12 is unused.

with that script in place we get a 1.0078 Hz filter which leads to
massive phase lag and a crashed aircraft

this is a safety protection. We should also try to find out why the
INS_HNTCH_FREQ lower limit is not working
@tridge tridge force-pushed the pr-zero-rpm-esc-notch branch from 5fab0e9 to b03933b Compare November 1, 2023 22:48
prevents use of stale data when close to zero time
@tridge tridge force-pushed the pr-zero-rpm-esc-notch branch from b03933b to a4c3f67 Compare November 1, 2023 22:52
Copy link
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@peterbarker peterbarker merged commit 1bf7c9e into ArduPilot:master Nov 2, 2023
86 checks passed
@andyp1per
Copy link
Collaborator

I think this is the wrong change. I have updated https://github.com/ArduPilot/ardupilot/pull/25355to reflect what I think should go in. I was going to put a blocking review on this and now wish I had. Please, please can we have a little more discussion.

@tridge
Copy link
Contributor Author

tridge commented Nov 4, 2023

I have updated https://github.com/ArduPilot/ardupilot/pull/25355to reflect what I think should go in.

I had a look, and it doesn't really fix the problem. It still ends up running the uninitialised RPM sources at the min frequency.
Remember that we also just fixed a bug where all ESC_TELEM_MAX_ESCS (32 by default) ESCs get seen as zero RPM for a short time at boot due to the race in the time handling in AP_ESC_Telem. If a board boots fast enough then we'd end up with 32 ESCs populating zero RPM, ending up with 32 sets of notch filters at INS_HNTCH_BW.
That is an example of why I don't want this in 4.4.x. We just can't cover all the unintended consequences.
For 4.5.x we need to work out how to fix this all properly, and I think the approach you are taking here is a bandaid over a bad design

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 4.4.3-beta1
Development

Successfully merging this pull request may close these issues.

4 participants