From 877c046a19c5f287ed9862330838e9388eba1ebe Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 20 Jan 2025 11:35:47 +0800 Subject: [PATCH] PyThermostat: Modify PIDAutotune for GUI usage This adds: - An extra ready PIDAutotuneState and corresponding state transitions - A setter for autotune parameters, allowing change after construction --- pythermostat/pythermostat/autotune.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pythermostat/pythermostat/autotune.py b/pythermostat/pythermostat/autotune.py index 0ad6e00..6b93dbe 100644 --- a/pythermostat/pythermostat/autotune.py +++ b/pythermostat/pythermostat/autotune.py @@ -18,6 +18,7 @@ class PIDAutotuneState(Enum): STATE_RELAY_STEP_DOWN = auto() STATE_SUCCEEDED = auto() STATE_FAILED = auto() + STATE_READY = auto() class PIDAutotune: @@ -57,6 +58,21 @@ class PIDAutotune: self._Ku = 0 self._Pu = 0 + def set_param(self, target, step, noiseband, sampletime, lookback): + self._setpoint = target + self._outputstep = step + self._out_max = step + self._out_min = -step + self._noiseband = noiseband + self._inputs = deque(maxlen=round(lookback / sampletime)) + + def set_ready(self): + self._state = PIDAutotuneState.STATE_READY + self._peak_count = 0 + + def set_off(self): + self._state = PIDAutotuneState.STATE_OFF + def state(self): """Get the current state.""" return self._state @@ -98,6 +114,7 @@ class PIDAutotune: PIDAutotuneState.STATE_OFF, PIDAutotuneState.STATE_SUCCEEDED, PIDAutotuneState.STATE_FAILED, + PIDAutotuneState.STATE_READY, }: self._state = PIDAutotuneState.STATE_RELAY_STEP_UP