better handling of restart status

Change-Id: I28f97b49d39ed7c6b781f0d8edb218e63e1b1fc9
This commit is contained in:
zolliker 2023-05-16 09:39:20 +02:00
parent 050a2dc8dc
commit 1407514458
2 changed files with 23 additions and 22 deletions

View File

@ -183,13 +183,13 @@ class HasStates:
override for code to be executed after stopping
"""
def start_machine(self, statefunc, fast_poll=True, restart_text='restarting', **kwds):
def start_machine(self, statefunc, fast_poll=True, status=None, **kwds):
"""start or restart the state machine
:param statefunc: the initial state to be called
:param fast_poll: flag to indicate that polling has to switched to fast
:param cleanup: a cleanup function
:param restart_text: status text when machine was already running
:param status: override automatic immediate status before first state
:param kwds: attributes to be added to the state machine on start
If the state machine is already running, the following happens:
@ -203,10 +203,12 @@ class HasStates:
4) the state machine continues at the given statefunc
"""
sm = self._state_machine
if sm.statefunc:
sm.status = sm.status[0], restart_text
else:
if status is None:
sm.status = self.get_status(statefunc, BUSY)
if sm.statefunc:
sm.status = sm.status[0], 'restarting'
else:
sm.status = status
sm.start(statefunc, cleanup=kwds.pop('cleanup', self.on_cleanup), **kwds)
self.read_status()
if fast_poll:
@ -214,23 +216,24 @@ class HasStates:
self.setFastPoll(True)
self.pollInfo.trigger(True) # trigger poller
def stopping(self, sm):
return self.final_status(IDLE, 'stopped')
def stop_machine(self):
def stop_machine(self, stopped_status=(IDLE, 'stopped')):
"""stop the currently running machine
:param stopped_status: status to be set after stopping
If the state machine is not running, nothing happens.
Else the state machine is stopped, the predefined cleanup
Else the state machine is stoppen, the predefined cleanup
sequence is executed and then the status is set to the value
given in the stopped_status argument.
given in the sopped_status argument.
An already running cleanup sequence is not executed again.
"""
sm = self._state_machine
if sm.is_active:
self.start_machine(self.stopping, restart_text='stopping')
sm.idle_status = stopped_status
sm.stop()
sm.status = self.get_status(sm.statefunc, sm.status[0])[0], 'stopping'
self.read_status()
self.pollInfo.trigger(True) # trigger poller
@Command
def stop(self):

View File

@ -20,7 +20,10 @@
#
# *****************************************************************************
"""driver for phytron motors"""
"""driver for phytron motors
limits switches are not yet implemented
"""
import time
from frappy.core import Done, Command, EnumType, FloatRange, IntRange, \
@ -175,10 +178,9 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
# drive first to target + backlash
# we do not optimize when already driving from the right side
self.set('A', self.sign * (value + self.backlash))
self.start_machine(self.predriving)
else:
self.set('A', self.sign * value)
self.start_machine(self.driving)
self.start_machine(self.driving)
self._running = True
return value
@ -219,11 +221,11 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
if self.backlash:
# drive to real target
self.set('A', self.sign * self.target)
return self.driving_to_final
return self.driving_to_final_position
return self.finishing
@status_code(BUSY)
def driving_to_final(self, sm):
def driving_to_final_position(self, sm):
if self.check_moving():
return Retry
return self.finishing
@ -256,7 +258,7 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
@Command
def stop(self):
self.get('S')
self.start_machine(self.stopping, status=(BUSY, 'stopping0'))
self.start_machine(self.stopping, status=(BUSY, 'stopping'))
@Command
def reset_error(self):
@ -284,7 +286,3 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
self.read_value()
self.status = 'IDLE', 'after error reset'
self._blocking_error = None
# TODO:
# '=E' electronics status
# '=I+' / '=I-': limit switches