phytron
better handling of restart status Change-Id: I28f97b49d39ed7c6b781f0d8edb218e63e1b1fc9
This commit is contained in:
@ -183,13 +183,13 @@ class HasStates:
|
|||||||
override for code to be executed after stopping
|
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
|
"""start or restart the state machine
|
||||||
|
|
||||||
:param statefunc: the initial state to be called
|
:param statefunc: the initial state to be called
|
||||||
:param fast_poll: flag to indicate that polling has to switched to fast
|
:param fast_poll: flag to indicate that polling has to switched to fast
|
||||||
:param cleanup: a cleanup function
|
: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
|
:param kwds: attributes to be added to the state machine on start
|
||||||
|
|
||||||
If the state machine is already running, the following happens:
|
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
|
4) the state machine continues at the given statefunc
|
||||||
"""
|
"""
|
||||||
sm = self._state_machine
|
sm = self._state_machine
|
||||||
if sm.statefunc:
|
if status is None:
|
||||||
sm.status = sm.status[0], restart_text
|
|
||||||
else:
|
|
||||||
sm.status = self.get_status(statefunc, BUSY)
|
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)
|
sm.start(statefunc, cleanup=kwds.pop('cleanup', self.on_cleanup), **kwds)
|
||||||
self.read_status()
|
self.read_status()
|
||||||
if fast_poll:
|
if fast_poll:
|
||||||
@ -214,23 +216,24 @@ class HasStates:
|
|||||||
self.setFastPoll(True)
|
self.setFastPoll(True)
|
||||||
self.pollInfo.trigger(True) # trigger poller
|
self.pollInfo.trigger(True) # trigger poller
|
||||||
|
|
||||||
def stopping(self, sm):
|
def stop_machine(self, stopped_status=(IDLE, 'stopped')):
|
||||||
return self.final_status(IDLE, 'stopped')
|
|
||||||
|
|
||||||
def stop_machine(self):
|
|
||||||
"""stop the currently running machine
|
"""stop the currently running machine
|
||||||
|
|
||||||
:param stopped_status: status to be set after stopping
|
:param stopped_status: status to be set after stopping
|
||||||
|
|
||||||
If the state machine is not running, nothing happens.
|
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
|
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.
|
An already running cleanup sequence is not executed again.
|
||||||
"""
|
"""
|
||||||
sm = self._state_machine
|
sm = self._state_machine
|
||||||
if sm.is_active:
|
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
|
@Command
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
@ -20,7 +20,10 @@
|
|||||||
#
|
#
|
||||||
# *****************************************************************************
|
# *****************************************************************************
|
||||||
|
|
||||||
"""driver for phytron motors"""
|
"""driver for phytron motors
|
||||||
|
|
||||||
|
limits switches are not yet implemented
|
||||||
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from frappy.core import Done, Command, EnumType, FloatRange, IntRange, \
|
from frappy.core import Done, Command, EnumType, FloatRange, IntRange, \
|
||||||
@ -175,7 +178,6 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
|
|||||||
# drive first to target + backlash
|
# drive first to target + backlash
|
||||||
# we do not optimize when already driving from the right side
|
# we do not optimize when already driving from the right side
|
||||||
self.set('A', self.sign * (value + self.backlash))
|
self.set('A', self.sign * (value + self.backlash))
|
||||||
self.start_machine(self.predriving)
|
|
||||||
else:
|
else:
|
||||||
self.set('A', self.sign * value)
|
self.set('A', self.sign * value)
|
||||||
self.start_machine(self.driving)
|
self.start_machine(self.driving)
|
||||||
@ -219,11 +221,11 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
|
|||||||
if self.backlash:
|
if self.backlash:
|
||||||
# drive to real target
|
# drive to real target
|
||||||
self.set('A', self.sign * self.target)
|
self.set('A', self.sign * self.target)
|
||||||
return self.driving_to_final
|
return self.driving_to_final_position
|
||||||
return self.finishing
|
return self.finishing
|
||||||
|
|
||||||
@status_code(BUSY)
|
@status_code(BUSY)
|
||||||
def driving_to_final(self, sm):
|
def driving_to_final_position(self, sm):
|
||||||
if self.check_moving():
|
if self.check_moving():
|
||||||
return Retry
|
return Retry
|
||||||
return self.finishing
|
return self.finishing
|
||||||
@ -256,7 +258,7 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
|
|||||||
@Command
|
@Command
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.get('S')
|
self.get('S')
|
||||||
self.start_machine(self.stopping, status=(BUSY, 'stopping0'))
|
self.start_machine(self.stopping, status=(BUSY, 'stopping'))
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
def reset_error(self):
|
def reset_error(self):
|
||||||
@ -284,7 +286,3 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
|
|||||||
self.read_value()
|
self.read_value()
|
||||||
self.status = 'IDLE', 'after error reset'
|
self.status = 'IDLE', 'after error reset'
|
||||||
self._blocking_error = None
|
self._blocking_error = None
|
||||||
|
|
||||||
# TODO:
|
|
||||||
# '=E' electronics status
|
|
||||||
# '=I+' / '=I-': limit switches
|
|
||||||
|
Reference in New Issue
Block a user