fixes in convergence and statemachine

- set spent_inside to 0 on set_target
- additional debug log messages in statemachine
This commit is contained in:
2022-06-14 14:07:24 +02:00
parent a35231f5bd
commit f855b9db40
2 changed files with 6 additions and 4 deletions

View File

@ -186,6 +186,7 @@ class StateMachine:
ret = self.state(self)
self.init = False
if self.stopped:
self.log.debug('%r', self.stopped)
self.last_error = self.stopped
self.cleanup(self)
self.stopped = False
@ -268,6 +269,7 @@ class StateMachine:
self.stopped = Restart
with self._lock: # wait for running cycle finished
if self.stopped: # cleanup is not yet done
self.log.debug('restart')
self.last_error = self.stopped
self.cleanup(self) # ignore return state on restart
self.stopped = False

View File

@ -78,11 +78,11 @@ class HasConvergence:
return dif / self.timeout # assume exponential decay of dif, with time constant <tolerance>
def get_dif_tol(self):
self.read_value()
value = self.read_value()
tol = self.tolerance
if not tol:
tol = 0.01 * max(abs(self.target), abs(self.value))
dif = abs(self.target - self.value)
tol = 0.01 * max(abs(self.target), abs(value))
dif = abs(self.target - value)
return dif, tol
def start_state(self):
@ -91,6 +91,7 @@ class HasConvergence:
def state_approach(self, state):
"""approaching, checking progress (busy)"""
state.spent_inside = 0
dif, tol = self.get_dif_tol()
if dif < tol:
state.timeout_base = state.now
@ -101,7 +102,6 @@ class HasConvergence:
state.timeout_base = state.now
state.dif_crit = dif # criterium for resetting timeout base
self.status = BUSY, 'approaching'
state.spent_inside = 0
state.dif_crit -= self.get_min_slope(dif) * state.delta()
if dif < state.dif_crit: # progress is good: reset timeout base
state.timeout_base = state.now