PyThermostat: Modify PIDAutotune for GUI usage

Co-authored-by: topquark12 <aw@m-labs.hk>
This commit is contained in:
atse 2024-11-04 12:54:58 +08:00
parent 8db4867ebf
commit 3246929f69

View File

@ -18,6 +18,7 @@ class PIDAutotuneState(Enum):
STATE_RELAY_STEP_DOWN = 'relay step down'
STATE_SUCCEEDED = 'succeeded'
STATE_FAILED = 'failed'
STATE_READY = "ready"
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
@ -96,7 +112,8 @@ class PIDAutotune:
if (self._state == PIDAutotuneState.STATE_OFF
or self._state == PIDAutotuneState.STATE_SUCCEEDED
or self._state == PIDAutotuneState.STATE_FAILED):
or self._state == PIDAutotuneState.STATE_FAILED
or self._state == PIDAutotuneState.STATE_READY):
self._state = PIDAutotuneState.STATE_RELAY_STEP_UP
self._last_run_timestamp = now