flowsas project as of 2025-04-14

This commit is contained in:
l_samenv
2025-04-14 11:40:12 +02:00
parent adfb561308
commit a7fd90cd6d
8 changed files with 462 additions and 31 deletions

View File

@ -62,7 +62,7 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
encoder_mode = Parameter('how to treat the encoder', EnumType('encoder', NO=0, READ=1, CHECK=2),
default=1, readonly=False)
check_limit_switches = Parameter('whethter limit switches are checked',BoolType(),
check_limit_switches = Parameter('whether limit switches are checked',BoolType(),
default=0, readonly=False)
value = PersistentParam('angle', FloatRange(unit='deg'))
status = PersistentParam()
@ -90,6 +90,8 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
status_bits = ['power stage error', 'undervoltage', 'overtemperature', 'active',
'lower switch active', 'upper switch active', 'step failure', 'encoder error']
_doing_reference = False
def get(self, cmd):
return self.communicate(f'{self.address:x}{self.axis}{cmd}')
@ -178,10 +180,14 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
def doPoll(self):
super().doPoll()
if self._running and not self.isBusy():
if self._running and not self.isBusy() and not self._doing_reference:
if time.time() > self._stopped_at + 5:
self.log.warning('stop motor not started by us')
self.hw_stop()
if self._doing_reference and self.get('=H') == 'E' :
self.status = IDLE, ''
self.target = 0
self._doing_reference = False
def read_status(self):
hexstatus = 0x100
@ -207,6 +213,9 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
if status[0] == ERROR:
self._blocking_error = status[1]
return status
if self._doing_reference and self.get('=H') == 'N':
status = BUSY, 'Doing reference run'
return status
return super().read_status() # status from state machine
def check_moving(self):
@ -346,3 +355,10 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
self.status = 'IDLE', 'after error reset'
self._blocking_error = None
self.target = self.value # clear error in target
@Command
def make_ref_run(self):
'''Do reference run'''
self._doing_reference = True
self.status = BUSY, 'Doing reference run'
self.communicate(f'{self.address:x}{self.axis}0-')