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

[BUG] LowPassFilter::operator() returns nan #446

Open
manuelbaum opened this issue Jan 13, 2025 · 0 comments
Open

[BUG] LowPassFilter::operator() returns nan #446

manuelbaum opened this issue Jan 13, 2025 · 0 comments

Comments

@manuelbaum
Copy link

manuelbaum commented Jan 13, 2025

Describe the bug
LowPassFilter::operator() returns nan when called with zero dt and zero Tf.

I have a multi-threaded setup running where I asynchronously call FOCMotor::shaftAngle() from different threads. Occasionally my setup breaks down because the LPF returns nan. That happens because the LPF is initialized with zero Tf in the FOCMotor class and occasionally dt is also zero which then breaks the formula in LowPassFilter::operator():

float alpha = Tf/(Tf + dt);

I'm actually surprised that nobody else had this problem yet, so I'm wondering if I am doing sth wrong.

hardware setup

  • Motor: GB4106
  • Driver: DRV8313
  • MCU: ESP32
  • Sensor: AS5048
  • No current sensing

IDE

  • Platformio

Suggested Solution
Catch the zero case by turning

if (dt < 0.0f ) dt = 1e-3f;

into

if (dt <= 0.0f ) dt = 1e-3f;

But I think that 1e-3f is actually a little too large and would suggest to go with 1e-4f or 1e-5f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant