You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because y_prev is initialized to zero, the first calls to operator() returns the wrong result. At the first call, y_prev should probably be initialized with x instead of zero. In other words, the first call to LowPassFilter(5) should return 5 and not a weighted average of 5 with zero.
Notice that, in LowPassFilter::operator(), you can also see:
So if you are lucky enough to have spent 0.3 seconds between the class construction and the first call to operator(), then y_prev is correctly initialized.
The text was updated successfully, but these errors were encountered:
You're right, in principle. The code has been this way for a long time. I think it works well in practice because the assumption is more or less that the motor starts at 0, so x would be 0.
But in the case where the motor is moving when you start, or if you're applying the LPF to angle rather than velocity, it probably makes more sense to initialize it from x.
Another goal we have is to make the filter configurable, so you could swap it for a different kind of filter implementation. Maybe these issues can be solved at the same time by giving the user more control over the filter setup and initialisation.
Yes, I discovered this when investigating an issue with BLDCMotor::shaftAngle(): the result is wrong at startup because it uses the LPF with an angle which is never initially zero.
Not sure what kind of actual impact this might have on the rest of the library, but I believe there is something wrong in the LowPassFilter class:
Because
y_prev
is initialized to zero, the first calls tooperator()
returns the wrong result. At the first call,y_prev
should probably be initialized withx
instead of zero. In other words, the first call toLowPassFilter(5)
should return 5 and not a weighted average of 5 with zero.Notice that, in
LowPassFilter::operator()
, you can also see:So if you are lucky enough to have spent 0.3 seconds between the class construction and the first call to
operator()
, theny_prev
is correctly initialized.The text was updated successfully, but these errors were encountered: