add limits to phytron

Change-Id: I431374efab7a858db6a652f78533b13b12ba6d57
This commit is contained in:
zolliker 2022-05-19 18:05:52 +02:00
parent 0972e8c7e8
commit 39171fe06e
3 changed files with 83 additions and 49 deletions

View File

@ -8,7 +8,7 @@ uri = tcp://5000
[drv_io] [drv_io]
description = description =
class = secop_psi.phytron.PhytronIO class = secop_psi.phytron.PhytronIO
uri = ma10-ts.psi.ch:3004 uri = ma7-ts.psi.ch:3007
# uri = serial:///dev/tty.usbserial?baudrate=57600 # uri = serial:///dev/tty.usbserial?baudrate=57600
# uri = serial:///dev/ttyUSB0?baudrate=9600 # uri = serial:///dev/ttyUSB0?baudrate=9600
@ -16,4 +16,5 @@ uri = ma10-ts.psi.ch:3004
description = a phytron motor description = a phytron motor
class = secop_psi.phytron.Motor class = secop_psi.phytron.Motor
io = drv_io io = drv_io
abslimits = -180,360
encoder_mode = CHECK encoder_mode = CHECK

View File

@ -14,111 +14,111 @@ io = ppms
class = secop_psi.ppms.Field class = secop_psi.ppms.Field
target.min = -9 target.min = -9
target.max = 9 target.max = 9
.description = magnetic field description = magnetic field
.io = ppms io = ppms
[pos] [pos]
class = secop_psi.ppms.Position class = secop_psi.ppms.Position
.description = sample rotator description = sample rotator
.io = ppms io = ppms
[lev] [lev]
class = secop_psi.ppms.Level class = secop_psi.ppms.Level
.description = helium level description = helium level
.io = ppms io = ppms
[chamber] [chamber]
class = secop_psi.ppms.Chamber class = secop_psi.ppms.Chamber
.description = chamber state description = chamber state
.io = ppms io = ppms
[r1] [r1]
class = secop_psi.ppms.BridgeChannel class = secop_psi.ppms.BridgeChannel
.description = resistivity channel 1 description = resistivity channel 1
.no = 1 no = 1
value.unit = Ohm value.unit = Ohm
.io = ppms io = ppms
[r2] [r2]
class = secop_psi.ppms.BridgeChannel class = secop_psi.ppms.BridgeChannel
.description = resistivity channel 2 description = resistivity channel 2
.no = 2 no = 2
value.unit = Ohm value.unit = Ohm
.io = ppms io = ppms
[r3] [r3]
class = secop_psi.ppms.BridgeChannel class = secop_psi.ppms.BridgeChannel
.description = resistivity channel 3 description = resistivity channel 3
.no = 3 no = 3
value.unit = Ohm value.unit = Ohm
.io = ppms io = ppms
[r4] [r4]
class = secop_psi.ppms.BridgeChannel class = secop_psi.ppms.BridgeChannel
.description = resistivity channel 4 description = resistivity channel 4
.no = 4 no = 4
value.unit = Ohm value.unit = Ohm
.io = ppms io = ppms
[i1] [i1]
class = secop_psi.ppms.Channel class = secop_psi.ppms.Channel
.description = current channel 1 description = current channel 1
.no = 1 no = 1
value.unit = uA value.unit = uA
.io = ppms io = ppms
[i2] [i2]
class = secop_psi.ppms.Channel class = secop_psi.ppms.Channel
.description = current channel 2 description = current channel 2
.no = 2 no = 2
value.unit = uA value.unit = uA
.io = ppms io = ppms
[i3] [i3]
class = secop_psi.ppms.Channel class = secop_psi.ppms.Channel
.description = current channel 3 description = current channel 3
.no = 3 no = 3
value.unit = uA value.unit = uA
.io = ppms io = ppms
[i4] [i4]
class = secop_psi.ppms.Channel class = secop_psi.ppms.Channel
.description = current channel 4 description = current channel 4
.no = 4 no = 4
value.unit = uA value.unit = uA
.io = ppms io = ppms
[v1] [v1]
class = secop_psi.ppms.DriverChannel class = secop_psi.ppms.DriverChannel
.description = voltage channel 1 description = voltage channel 1
.no = 1 no = 1
value.unit = V value.unit = V
.io = ppms io = ppms
[v2] [v2]
class = secop_psi.ppms.DriverChannel class = secop_psi.ppms.DriverChannel
.description = voltage channel 2 description = voltage channel 2
.no = 2 no = 2
value.unit = V value.unit = V
.io = ppms io = ppms
[tv] [tv]
class = secop_psi.ppms.UserChannel class = secop_psi.ppms.UserChannel
.description = VTI temperature description = VTI temperature
enabled = 1 enabled = 1
value.unit = K value.unit = K
.io = ppms io = ppms
[ts] [ts]
class = secop_psi.ppms.UserChannel class = secop_psi.ppms.UserChannel
.description = sample temperature description = sample temperature
enabled = 1 enabled = 1
value.unit = K value.unit = K
.io = ppms io = ppms
[ppms] [ppms]
class = secop_psi.ppms.Main class = secop_psi.ppms.Main
.description = the main and poller module description = the main and poller module
.class_id = QD.MULTIVU.PPMS.1 class_id = QD.MULTIVU.PPMS.1
.visibility = 3 visibility = 3
pollinterval = 2 pollinterval = 2

View File

@ -20,11 +20,13 @@
# #
# ***************************************************************************** # *****************************************************************************
"""driver for pythron motors""" """driver for phytron motors"""
from secop.core import Done, Command, EnumType, FloatRange, IntRange, \ from secop.core import Done, Command, EnumType, FloatRange, IntRange, \
HasIO, Parameter, Property, Drivable, PersistentMixin, PersistentParam, StringIO, StringType HasIO, Parameter, Property, Drivable, PersistentMixin, PersistentParam, \
from secop.errors import CommunicationFailedError, HardwareError StringIO, StringType, TupleOf
from secop.errors import CommunicationFailedError, HardwareError, BadValueError
from secop.lib import clamp
class PhytronIO(StringIO): class PhytronIO(StringIO):
@ -65,14 +67,24 @@ class Motor(PersistentMixin, HasIO, Drivable):
encoder = Parameter('encoder reading', FloatRange(unit='deg')) encoder = Parameter('encoder reading', FloatRange(unit='deg'))
sameside_offset = Parameter('offset when always approaching from the same side', sameside_offset = Parameter('offset when always approaching from the same side',
FloatRange(unit='deg'), readonly=False, default=0) FloatRange(unit='deg'), readonly=False, default=0)
abslimits = Parameter('abs limits (raw values)', default=(0, 0),
datatype=TupleOf(FloatRange(unit='deg'), FloatRange(unit='deg')))
userlimits = PersistentParam('user limits', readonly=False, default=(0, 0), initwrite=True,
datatype=TupleOf(FloatRange(unit='deg'), FloatRange(unit='deg')))
ioClass = PhytronIO ioClass = PhytronIO
fast_poll = 0.1 fast_poll = 0.1
_sameside_pending = False _sameside_pending = False
_mismatch_count = 0 _mismatch_count = 0
_rawlimits = None
def earlyInit(self): def earlyInit(self):
super().earlyInit() super().earlyInit()
if self.abslimits == (0, 0):
self.abslimits = -9e99, 9e99
if self.userlimits == (0, 0):
self._rawlimits = self.abslimits
self.read_userlimits()
self.loadParameters() self.loadParameters()
def get(self, cmd): def get(self, cmd):
@ -151,10 +163,20 @@ class Motor(PersistentMixin, HasIO, Drivable):
raise HardwareError('speed factor does not match') raise HardwareError('speed factor does not match')
return float(self.set_get('P15S', int(value * self.speed_factor), 'P15R')) / self.speed_factor return float(self.set_get('P15S', int(value * self.speed_factor), 'P15R')) / self.speed_factor
def _check_limits(self, *values):
for name, (mn, mx) in ('user', self._rawlimits), ('abs', self.abslimits):
mn -= self.offset
mx -= self.offset
for v in values:
if not (mn <= v <= mx):
raise BadValueError('%s limits violation: %g <= %g <= %g' % (name, mn, v, mx))
v += self.offset
def write_target(self, value): def write_target(self, value):
if self.status[0] == self.Status.ERROR: if self.status[0] == self.Status.ERROR:
raise HardwareError('need reset') raise HardwareError('need reset')
self.status = self.Status.BUSY, 'changed target' self.status = self.Status.BUSY, 'changed target'
self._check_limits(value, value + self.sameside_offset)
if self.sameside_offset: if self.sameside_offset:
# drive first to target + sameside_offset # drive first to target + sameside_offset
# we do not optimize when already driving from the right side # we do not optimize when already driving from the right side
@ -165,8 +187,18 @@ class Motor(PersistentMixin, HasIO, Drivable):
self.setFastPoll(True, self.fast_poll) self.setFastPoll(True, self.fast_poll)
return value return value
def read_userlimits(self):
return self._rawlimits[0] - self.offset, self._rawlimits[1] - self.offset
def write_userlimits(self, value):
self._rawlimits = [clamp(self.abslimits[0], v + self.offset, self.abslimits[1]) for v in value]
value = self.read_userlimits()
self.saveParameters()
return value
def write_offset(self, value): def write_offset(self, value):
self.offset = value self.offset = value
self.read_userlimits()
self.saveParameters() self.saveParameters()
return Done return Done
@ -182,6 +214,7 @@ class Motor(PersistentMixin, HasIO, Drivable):
pos = self.value + self.offset pos = self.value + self.offset
if abs(enc - pos) > self.encoder_tolerance: if abs(enc - pos) > self.encoder_tolerance:
if enc < 0: if enc < 0:
# assume we have a rotation (not a linear motor)
while enc < 0: while enc < 0:
self.offset += 360 self.offset += 360
enc += 360 enc += 360