forked from M-Labs/thermostat
add autotune
This commit is contained in:
parent
34cdbf0c7f
commit
ff09069424
@ -17,6 +17,7 @@ class PIDAutotuneState(Enum):
|
|||||||
STATE_RELAY_STEP_DOWN = "relay step down"
|
STATE_RELAY_STEP_DOWN = "relay step down"
|
||||||
STATE_SUCCEEDED = "succeeded"
|
STATE_SUCCEEDED = "succeeded"
|
||||||
STATE_FAILED = "failed"
|
STATE_FAILED = "failed"
|
||||||
|
STATE_READY = "ready"
|
||||||
|
|
||||||
|
|
||||||
class PIDAutotune:
|
class PIDAutotune:
|
||||||
@ -57,6 +58,20 @@ class PIDAutotune:
|
|||||||
self._Ku = 0
|
self._Ku = 0
|
||||||
self._Pu = 0
|
self._Pu = 0
|
||||||
|
|
||||||
|
def setParam(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 setReady(self):
|
||||||
|
self._state = PIDAutotuneState.STATE_READY
|
||||||
|
|
||||||
|
def setOff(self):
|
||||||
|
self._state = PIDAutotuneState.STATE_OFF
|
||||||
|
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Get the current state."""
|
"""Get the current state."""
|
||||||
return self._state
|
return self._state
|
||||||
@ -82,6 +97,13 @@ class PIDAutotune:
|
|||||||
kd = divisors[2] * self._Ku * self._Pu
|
kd = divisors[2] * self._Ku * self._Pu
|
||||||
return PIDAutotune.PIDParams(kp, ki, kd)
|
return PIDAutotune.PIDParams(kp, ki, kd)
|
||||||
|
|
||||||
|
def get_tec_pid(self):
|
||||||
|
divisors = self._tuning_rules["tyreus-luyben"]
|
||||||
|
kp = self._Ku * divisors[0]
|
||||||
|
ki = divisors[1] * self._Ku / self._Pu
|
||||||
|
kd = divisors[2] * self._Ku * self._Pu
|
||||||
|
return kp, ki, kd
|
||||||
|
|
||||||
def run(self, input_val, time_input):
|
def run(self, input_val, time_input):
|
||||||
"""To autotune a system, this method must be called periodically.
|
"""To autotune a system, this method must be called periodically.
|
||||||
|
|
||||||
@ -98,6 +120,7 @@ class PIDAutotune:
|
|||||||
self._state == PIDAutotuneState.STATE_OFF
|
self._state == PIDAutotuneState.STATE_OFF
|
||||||
or self._state == PIDAutotuneState.STATE_SUCCEEDED
|
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._state = PIDAutotuneState.STATE_RELAY_STEP_UP
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user