remove do_now argument for next_action
This commit is contained in:
parent
1c1911f8a8
commit
ccf38f87d9
@ -107,7 +107,7 @@ class Uniax(PersistentMixin, Drivable):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def next_action(self, action, do_now=True):
|
def next_action(self, action):
|
||||||
"""call next action
|
"""call next action
|
||||||
|
|
||||||
:param action: function to be called next time
|
:param action: function to be called next time
|
||||||
@ -116,8 +116,6 @@ class Uniax(PersistentMixin, Drivable):
|
|||||||
self._action = action
|
self._action = action
|
||||||
self._init_action = True
|
self._init_action = True
|
||||||
self.log.info('action %r', action.__name__)
|
self.log.info('action %r', action.__name__)
|
||||||
if do_now:
|
|
||||||
self._next_cycle = False
|
|
||||||
|
|
||||||
def init_action(self):
|
def init_action(self):
|
||||||
"""return true when called the first time after next_action"""
|
"""return true when called the first time after next_action"""
|
||||||
@ -126,13 +124,6 @@ class Uniax(PersistentMixin, Drivable):
|
|||||||
return True
|
return True
|
||||||
return False
|
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,):
|
def zero_pos(self, value,):
|
||||||
"""get high_pos or low_pos, depending on sign of 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.log.info('motor stopped - substantial force detected: %g', force)
|
||||||
self._motor.stop()
|
self._motor.stop()
|
||||||
elif self.init_action():
|
elif self.init_action():
|
||||||
self.next_action(self.adjust, True)
|
self.next_action(self.adjust)
|
||||||
return
|
return
|
||||||
if abs(force) > self.hysteresis:
|
if abs(force) > self.hysteresis:
|
||||||
self.set_zero_pos(force, self._motor.read_value())
|
self.set_zero_pos(force, self._motor.read_value())
|
||||||
self.next_action(self.adjust, True)
|
self.next_action(self.adjust)
|
||||||
return
|
return
|
||||||
if force * sign < -self.hysteresis:
|
if force * sign < -self.hysteresis:
|
||||||
self._previous_force = force
|
self._previous_force = force
|
||||||
@ -333,7 +324,7 @@ class Uniax(PersistentMixin, Drivable):
|
|||||||
return Done
|
return Done
|
||||||
if self.zero_pos(force) is None and abs(force) > self.hysteresis and self._filtered:
|
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.set_zero_pos(force, self._motor.read_value())
|
||||||
self.execute_action()
|
self._action(self.value, self.target)
|
||||||
return Done
|
return Done
|
||||||
|
|
||||||
def write_target(self, target):
|
def write_target(self, target):
|
||||||
@ -351,7 +342,10 @@ class Uniax(PersistentMixin, Drivable):
|
|||||||
self._cnt_rderr = 0
|
self._cnt_rderr = 0
|
||||||
self._cnt_wrerr = 0
|
self._cnt_wrerr = 0
|
||||||
self.status = 'BUSY', 'changed target'
|
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
|
return target
|
||||||
|
|
||||||
@Command()
|
@Command()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user