Skip to content

Ignore non-finite process measurements in PID update - #98

Closed
Fstarnb wants to merge 1 commit into
m-lundberg:masterfrom
Fstarnb:fix/nan-input-handling
Closed

Fstarnb wants to merge 1 commit into
m-lundberg:masterfrom
Fstarnb:fix/nan-input-handling

Conversation

@Fstarnb

@Fstarnb Fstarnb commented Jul 14, 2026

Copy link
Copy Markdown

Summary

A NaN or infinite process measurement could previously corrupt the integral term and produce a non-finite control output (e.g. a heater driven to full power after a bad temperature sample).

The controller now skips the update for non-finite inputs and returns the last output so it can recover on the next good sample. None and bool are treated the same way so they cannot be coerced into numeric measurements.

Changes

  • Guard non-finite / unusable inputs in PID.__call__ before error and I/D updates
  • Document the hold-last-output behavior
  • Tests for NaN, ±inf, None, bool, first-call behavior, and recovery
  • Changelog entry under Unreleased

Test plan

  • python -m pytest tests/test_pid.py::test_nan_input_does_not_poison_state tests/test_pid.py::test_nan_input_before_any_output_returns_none tests/test_pid.py::test_non_finite_variants_and_none_bool tests/test_pid.py::test_zero tests/test_pid.py::test_P tests/test_pid.py::test_output_limits -q (6 passed)

Fixes #92.

A NaN or infinite temperature/sensor reading previously corrupted the
integral term and produced a non-finite control output. Skip the update
and return the last finite output when the measurement is non-finite so
the controller can recover on the next good sample.

Also treat None and bool as unusable inputs so they cannot be coerced
into numeric measurements.

Fixes m-lundberg#92.
@Fstarnb

Fstarnb commented Jul 15, 2026

Copy link
Copy Markdown
Author

Closing this PR for now to free review bandwidth. Thanks for maintaining the project — happy to reopen or resubmit if this change is still useful later.

@Fstarnb Fstarnb closed this Jul 15, 2026
@Fstarnb Fstarnb reopened this Oct 13, 2026
@Fstarnb Fstarnb closed this Oct 14, 2026
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

Successfully merging this pull request may close these issues.

Handling NaN values

1 participant