frappy_psi.phytron: implement limit switches

This commit is contained in:
zolliker 2023-10-02 16:58:09 +02:00
parent 06bec41ed3
commit 03c356590b

View File

@ -20,15 +20,12 @@
#
# *****************************************************************************
"""driver for phytron motors
limits switches are not yet implemented
"""
"""driver for phytron motors """
import time
from frappy.core import Done, Command, EnumType, FloatRange, IntRange, \
HasIO, Parameter, Property, Drivable, PersistentMixin, PersistentParam, \
StringIO, StringType, IDLE, BUSY, ERROR, Limit
StringIO, StringType, IDLE, BUSY, ERROR, Limit, BoolType
from frappy.errors import CommunicationFailedError, HardwareError
from frappy.features import HasOffset
from frappy.states import HasStates, status_code, Retry
@ -66,6 +63,8 @@ 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(),
default=0, readonly=False)
value = PersistentParam('angle', FloatRange(unit='deg'))
status = PersistentParam()
target = Parameter('target angle', FloatRange(unit='deg'), readonly=False)
@ -186,11 +185,14 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable):
self.hw_stop()
def read_status(self):
hexstatus = 0x100
for _ in range(3):
sysstatus = self.communicate(f'{self.address:x}SE')
try:
sysstatus = sysstatus[1:4] if self.axis == 'X' else sysstatus[5:8]
hexstatus = int(sysstatus, base=16)
if not self.check_limit_switches:
hexstatus &= 0xfcf # ignore limit switch bits
status_items = formatStatusBits(hexstatus & 0xf7, self.status_bits)
if status_items:
status = ERROR, ', '.join(status_items)