Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

non-monotonic time issue #1

Closed
deniz195 opened this issue Oct 1, 2018 · 2 comments
Closed

non-monotonic time issue #1

deniz195 opened this issue Oct 1, 2018 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@deniz195
Copy link

deniz195 commented Oct 1, 2018

Hi martin,

i'm using a similar PID implementation on a raspberry pi in a production environement (PID code is also based Brett Beauregard's code at ).

Turns out that both time.time() and datetime.datetime.now() are non-monotonic time signals. I.e. if a system service or the user turns the time back, the PID will see negative time differences. This happens on many systems (in particular the raspberry pi) regularly which has given me rare, but quite erratic behavior of the machine.

Fixed the problem using time.monotonic() which is available since python 3.3. Maybe this is helpful to your code too.

Best,
Deniz

@m-lundberg
Copy link
Owner

Hello,

Thanks for the feedback!

This sounds like a tricky bug to track down if you are unaware of this. I will definitely look into using time.monotonic() instead when I get the chance. It might save me or someone else a headache in the future.

@m-lundberg m-lundberg added the bug Something isn't working label Oct 2, 2018
@m-lundberg m-lundberg self-assigned this Oct 2, 2018
m-lundberg added a commit that referenced this issue Oct 2, 2018
…s due to changed system time. Will default back to time.time() if time.monotonic() is not available. Fixes #1.
@m-lundberg
Copy link
Owner

I changed to using time.monotonic() for calculating time instead as you suggested if the python version is > 3.3. If time.monotonic() is not available it will fall back to using time.time() instead, with a warning to the user.

Thank you again for the feedback @deniz195!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants