remove do_now argument for next_action

This commit is contained in:
zolliker 2021-11-04 12:57:18 +01:00
parent 1c1911f8a8
commit ccf38f87d9

View File

@ -107,7 +107,7 @@ class Uniax(PersistentMixin, Drivable):
return True
return False
def next_action(self, action, do_now=True):
def next_action(self, action):
"""call next action
:param action: function to be called next time
@ -116,8 +116,6 @@ class Uniax(PersistentMixin, Drivable):
self._action = action
self._init_action = True
self.log.info('action %r', action.__name__)
if do_now:
self._next_cycle = False
def init_action(self):
"""return true when called the first time after next_action"""
@ -126,13 +124,6 @@ class Uniax(PersistentMixin, Drivable):
return True
return False
def execute_action(self):
for _ in range(5): # limit number of subsequent actions in one cycle
self._next_cycle = True
self._action(self.value, self.target)
if self._next_cycle:
break
def zero_pos(self, value,):
"""get high_pos or low_pos, depending on sign of value
@ -173,11 +164,11 @@ class Uniax(PersistentMixin, Drivable):
self.log.info('motor stopped - substantial force detected: %g', force)
self._motor.stop()
elif self.init_action():
self.next_action(self.adjust, True)
self.next_action(self.adjust)
return
if abs(force) > self.hysteresis:
self.set_zero_pos(force, self._motor.read_value())
self.next_action(self.adjust, True)
self.next_action(self.adjust)
return
if force * sign < -self.hysteresis:
self._previous_force = force
@ -333,7 +324,7 @@ class Uniax(PersistentMixin, Drivable):
return Done
if self.zero_pos(force) is None and abs(force) > self.hysteresis and self._filtered:
self.set_zero_pos(force, self._motor.read_value())
self.execute_action()
self._action(self.value, self.target)
return Done
def write_target(self, target):
@ -351,7 +342,10 @@ class Uniax(PersistentMixin, Drivable):
self._cnt_rderr = 0
self._cnt_wrerr = 0
self.status = 'BUSY', 'changed target'
self.next_action(self.find, False)
if self.value * math.copysign(1, target) > self.hysteresis:
self.next_action(self.adjust)
else:
self.next_action(self.find)
return target
@Command()