check for last_target in conditions for redo
This commit is contained in:
parent
bb40a0820c
commit
3496e391f6
@ -84,7 +84,7 @@ class Magfield(HasLimits, Drivable):
|
|||||||
_state = None
|
_state = None
|
||||||
_init = True
|
_init = True
|
||||||
_super_sw_check = False
|
_super_sw_check = False
|
||||||
_target_changed = False
|
_last_target = None
|
||||||
switch_time = None
|
switch_time = None
|
||||||
|
|
||||||
def doPoll(self):
|
def doPoll(self):
|
||||||
@ -114,7 +114,6 @@ class Magfield(HasLimits, Drivable):
|
|||||||
|
|
||||||
def write_target(self, target):
|
def write_target(self, target):
|
||||||
self.check_limits(target)
|
self.check_limits(target)
|
||||||
self._target_changed = target != self.target
|
|
||||||
self.target = target
|
self.target = target
|
||||||
if not self._state.is_active:
|
if not self._state.is_active:
|
||||||
# as long as the state machine is still running, it takes care of changing targets
|
# as long as the state machine is still running, it takes care of changing targets
|
||||||
@ -147,7 +146,8 @@ class Magfield(HasLimits, Drivable):
|
|||||||
def start_field_change(self, state):
|
def start_field_change(self, state):
|
||||||
self.setFastPoll(True, 1.0)
|
self.setFastPoll(True, 1.0)
|
||||||
self.status = Status.PREPARING, 'changed target field'
|
self.status = Status.PREPARING, 'changed target field'
|
||||||
if abs(self.target - self.persistent_field) <= self.tolerance: # short cut
|
if (self.target == self._last_target and
|
||||||
|
abs(self.target - self.persistent_field) <= self.tolerance): # short cut
|
||||||
return self.check_switch_off
|
return self.check_switch_off
|
||||||
return self.start_ramp_to_field
|
return self.start_ramp_to_field
|
||||||
|
|
||||||
@ -160,7 +160,8 @@ class Magfield(HasLimits, Drivable):
|
|||||||
|
|
||||||
def ramp_to_field(self, state):
|
def ramp_to_field(self, state):
|
||||||
"""ramping, wait for current at persistent field"""
|
"""ramping, wait for current at persistent field"""
|
||||||
if abs(self.target - self.persistent_field) <= self.tolerance: # short cut
|
if (self.target == self._last_target and
|
||||||
|
abs(self.target - self.persistent_field) <= self.tolerance): # short cut
|
||||||
return self.check_switch_off
|
return self.check_switch_off
|
||||||
if abs(self.current - self.persistent_field) > self.tolerance:
|
if abs(self.current - self.persistent_field) > self.tolerance:
|
||||||
if state.init:
|
if state.init:
|
||||||
@ -186,11 +187,11 @@ class Magfield(HasLimits, Drivable):
|
|||||||
|
|
||||||
def start_switch_on(self, state):
|
def start_switch_on(self, state):
|
||||||
"""switch heater on"""
|
"""switch heater on"""
|
||||||
self._super_sw_check = False
|
|
||||||
if self.switch_heater != 0:
|
if self.switch_heater != 0:
|
||||||
self.status = Status.PREPARING, 'wait for heater on'
|
self.status = Status.PREPARING, 'wait for heater on'
|
||||||
else:
|
else:
|
||||||
self.status = Status.PREPARING, 'turn switch heater on'
|
self.status = Status.PREPARING, 'turn switch heater on'
|
||||||
|
self._super_sw_check = False
|
||||||
self.write_switch_heater(True)
|
self.write_switch_heater(True)
|
||||||
if not self._super_sw_check:
|
if not self._super_sw_check:
|
||||||
raise ProgrammingError('missing super call in write_switch_heater')
|
raise ProgrammingError('missing super call in write_switch_heater')
|
||||||
@ -198,11 +199,12 @@ class Magfield(HasLimits, Drivable):
|
|||||||
|
|
||||||
def switch_on(self, state):
|
def switch_on(self, state):
|
||||||
"""wait for switch heater open"""
|
"""wait for switch heater open"""
|
||||||
if abs(self.target - self.persistent_field) <= self.tolerance: # short cut
|
if (self.target == self._last_target and
|
||||||
|
abs(self.target - self.persistent_field) <= self.tolerance): # short cut
|
||||||
return self.check_switch_off
|
return self.check_switch_off
|
||||||
if state.now - self.switch_time < self.wait_switch_on:
|
if state.now - self.switch_time < self.wait_switch_on:
|
||||||
return Retry()
|
return Retry()
|
||||||
self._target_changed = False
|
self._last_target = self.target
|
||||||
return self.start_ramp_to_target
|
return self.start_ramp_to_target
|
||||||
|
|
||||||
def start_ramp_to_target(self, state):
|
def start_ramp_to_target(self, state):
|
||||||
@ -214,8 +216,8 @@ class Magfield(HasLimits, Drivable):
|
|||||||
|
|
||||||
def ramp_to_target(self, state):
|
def ramp_to_target(self, state):
|
||||||
"""ramp field to target"""
|
"""ramp field to target"""
|
||||||
if self._target_changed:
|
if self.target != self._last_target: # target was changed
|
||||||
self._target_changed = False
|
self._last_target = self.target
|
||||||
return self.start_ramp_to_target
|
return self.start_ramp_to_target
|
||||||
self.persistent_field = self.value
|
self.persistent_field = self.value
|
||||||
# Remarks: assume there is a ramp limiting feature
|
# Remarks: assume there is a ramp limiting feature
|
||||||
@ -228,8 +230,8 @@ class Magfield(HasLimits, Drivable):
|
|||||||
|
|
||||||
def stabilize_field(self, state):
|
def stabilize_field(self, state):
|
||||||
"""stabilize field"""
|
"""stabilize field"""
|
||||||
if self._target_changed:
|
if self.target != self._last_target: # target was changed
|
||||||
self._target_changed = False
|
self._last_target = self.target
|
||||||
return self.start_ramp_to_target
|
return self.start_ramp_to_target
|
||||||
self.persistent_field = self.value
|
self.persistent_field = self.value
|
||||||
if state.now - state.stabilize_start < self.wait_stable_field:
|
if state.now - state.stabilize_start < self.wait_stable_field:
|
||||||
@ -250,16 +252,15 @@ class Magfield(HasLimits, Drivable):
|
|||||||
self.status = Status.FINALIZING, 'turn switch heater off'
|
self.status = Status.FINALIZING, 'turn switch heater off'
|
||||||
else:
|
else:
|
||||||
self.status = Status.FINALIZING, 'wait for heater off'
|
self.status = Status.FINALIZING, 'wait for heater off'
|
||||||
self._super_sw_check = False
|
|
||||||
self.write_switch_heater(False)
|
self.write_switch_heater(False)
|
||||||
if not self._super_sw_check:
|
# no check for super call needed here (would have been detected in start_switch_on)
|
||||||
raise ProgrammingError('missing super call in write_switch_heater')
|
|
||||||
return self.switch_off
|
return self.switch_off
|
||||||
|
|
||||||
def switch_off(self, state):
|
def switch_off(self, state):
|
||||||
"""wait for switch heater closed"""
|
"""wait for switch heater closed"""
|
||||||
if self._target_changed or self.mode == Mode.DRIVEN:
|
if self.target != self._last_target or self.mode == Mode.DRIVEN:
|
||||||
# target or mode has changed -> redo
|
# target or mode has changed -> redo
|
||||||
|
self._last_target = None
|
||||||
return self.start_switch_on
|
return self.start_switch_on
|
||||||
self.persistent_field = self.value
|
self.persistent_field = self.value
|
||||||
if state.now - self.switch_time < self.wait_switch_off:
|
if state.now - self.switch_time < self.wait_switch_off:
|
||||||
@ -269,15 +270,16 @@ class Magfield(HasLimits, Drivable):
|
|||||||
def start_ramp_to_zero(self, state):
|
def start_ramp_to_zero(self, state):
|
||||||
"""start ramping current to target
|
"""start ramping current to target
|
||||||
|
|
||||||
initiate ramp to zero (with corresponding ramp rate
|
initiate ramp to zero (with corresponding ramp rate)
|
||||||
should return ramp_to_zero
|
should return ramp_to_zero
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def ramp_to_zero(self, state):
|
def ramp_to_zero(self, state):
|
||||||
"""ramp field to zero"""
|
"""ramp field to zero"""
|
||||||
if self._target_changed or self.mode == Mode.DRIVEN:
|
if self.target != self._last_target or self.mode == Mode.DRIVEN:
|
||||||
# target or mode has changed -> redo
|
# target or mode has changed -> redo
|
||||||
|
self._last_target = None
|
||||||
return self.start_field_change
|
return self.start_field_change
|
||||||
if abs(self.current) > self.tolerance:
|
if abs(self.current) > self.tolerance:
|
||||||
if state.init:
|
if state.init:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user