-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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: LowPass: use calc_lowpass_alpha_dt
in apply
and prefix all class varables with _
#27582
Conversation
…l class varables with `_`
} else { | ||
alpha = calc_lowpass_alpha_dt(1.0/sample_freq, cutoff_freq); | ||
_alpha = calc_lowpass_alpha_dt(1.0/sample_freq, cutoff_freq); |
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.
note that we are already using the calc_lowpass_alpha_dt
function in this case.
return _output; | ||
} | ||
float rc = 1.0f/(M_2PI*cutoff_freq); | ||
alpha = constrain_float(dt/(dt+rc), 0.0f, 1.0f); |
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.
should this constrain be added to calc_lowpass_alpha_dt?
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.
See: #20911
The constrain will never trigger because we have already checked both values are > 0.
float _alpha = 1.0f; | ||
bool _initialised; |
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 thought we were trying to canonicalise the other way, to remove leading underscores over time
it would be good to be sure the two API approaches are not currently mixed |
replaced by #27932 |
A small simplification to our base low pass filter. It now uses
calc_lowpass_alpha_dt
andapply
so the existing code is reused rather than being re-implemented.There are some changes in behavior in the invalid dt/cutoff_freq cases. Previously the local copy of alpha was not updated where as it now is. This should not matter because the two apply methods should not be used together.
Future work
I would like to split the filter in to two classes one for each of the methods outlined here:
ardupilot/libraries/Filter/LowPassFilter.h
Lines 25 to 39 in 5a54d9a
The two methods should not be mixed, so separate classes will ensure that.
Then I would like to add a filter class which includes the cutoff frequency parameter since that is a very common usecase.