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

Delta time calculation produces erroneous results on first call to tick() on non-microcontroller platforms #13

Open
logos-electromechanical opened this issue Oct 3, 2024 · 0 comments

Comments

@logos-electromechanical
Copy link

If the time function uses system time rather than something like the Arduino millis() function that counts from the last microcontroller reset event, the initial value of deltaTime can be EXTREMELY large -- potentially large enough to cause the integral calculation to overflow. This can happen in embedded Linux, in systems that use a real time clock, in systems that either don't call tick() for extended periods (for example, when the system is disarmed), or reset the PID object for whatever reason. The result is a very large computed value of deltaTime on the first tick, which can disrupt the integral term. I see a few possible solutions:

  • A method that enables the user to initialize the lastTime member
  • Modify registerTimeFunction() so that it sets the value of lastTime to the output of the time function at the time of registration
  • Do not compute deltaTime or the integral/derivative components if lastTime == 0
  • Have a configurable limit to deltaTime and either bound it or disable integral and derivative computations if deltaTime is larger than the bound.

I like the second idea best, b/c it doesn't require any additional code from the user and still allows resetting the lastTime value any time the user feels the need. Thoughts?

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

No branches or pull requests

1 participant