fixes in convergence and statemachine
- set spent_inside to 0 on set_target - additional debug log messages in statemachine
This commit is contained in:
@ -186,6 +186,7 @@ class StateMachine:
|
|||||||
ret = self.state(self)
|
ret = self.state(self)
|
||||||
self.init = False
|
self.init = False
|
||||||
if self.stopped:
|
if self.stopped:
|
||||||
|
self.log.debug('%r', self.stopped)
|
||||||
self.last_error = self.stopped
|
self.last_error = self.stopped
|
||||||
self.cleanup(self)
|
self.cleanup(self)
|
||||||
self.stopped = False
|
self.stopped = False
|
||||||
@ -268,6 +269,7 @@ class StateMachine:
|
|||||||
self.stopped = Restart
|
self.stopped = Restart
|
||||||
with self._lock: # wait for running cycle finished
|
with self._lock: # wait for running cycle finished
|
||||||
if self.stopped: # cleanup is not yet done
|
if self.stopped: # cleanup is not yet done
|
||||||
|
self.log.debug('restart')
|
||||||
self.last_error = self.stopped
|
self.last_error = self.stopped
|
||||||
self.cleanup(self) # ignore return state on restart
|
self.cleanup(self) # ignore return state on restart
|
||||||
self.stopped = False
|
self.stopped = False
|
||||||
|
@ -78,11 +78,11 @@ class HasConvergence:
|
|||||||
return dif / self.timeout # assume exponential decay of dif, with time constant <tolerance>
|
return dif / self.timeout # assume exponential decay of dif, with time constant <tolerance>
|
||||||
|
|
||||||
def get_dif_tol(self):
|
def get_dif_tol(self):
|
||||||
self.read_value()
|
value = self.read_value()
|
||||||
tol = self.tolerance
|
tol = self.tolerance
|
||||||
if not tol:
|
if not tol:
|
||||||
tol = 0.01 * max(abs(self.target), abs(self.value))
|
tol = 0.01 * max(abs(self.target), abs(value))
|
||||||
dif = abs(self.target - self.value)
|
dif = abs(self.target - value)
|
||||||
return dif, tol
|
return dif, tol
|
||||||
|
|
||||||
def start_state(self):
|
def start_state(self):
|
||||||
@ -91,6 +91,7 @@ class HasConvergence:
|
|||||||
|
|
||||||
def state_approach(self, state):
|
def state_approach(self, state):
|
||||||
"""approaching, checking progress (busy)"""
|
"""approaching, checking progress (busy)"""
|
||||||
|
state.spent_inside = 0
|
||||||
dif, tol = self.get_dif_tol()
|
dif, tol = self.get_dif_tol()
|
||||||
if dif < tol:
|
if dif < tol:
|
||||||
state.timeout_base = state.now
|
state.timeout_base = state.now
|
||||||
@ -101,7 +102,6 @@ class HasConvergence:
|
|||||||
state.timeout_base = state.now
|
state.timeout_base = state.now
|
||||||
state.dif_crit = dif # criterium for resetting timeout base
|
state.dif_crit = dif # criterium for resetting timeout base
|
||||||
self.status = BUSY, 'approaching'
|
self.status = BUSY, 'approaching'
|
||||||
state.spent_inside = 0
|
|
||||||
state.dif_crit -= self.get_min_slope(dif) * state.delta()
|
state.dif_crit -= self.get_min_slope(dif) * state.delta()
|
||||||
if dif < state.dif_crit: # progress is good: reset timeout base
|
if dif < state.dif_crit: # progress is good: reset timeout base
|
||||||
state.timeout_base = state.now
|
state.timeout_base = state.now
|
||||||
|
Reference in New Issue
Block a user