Merge branch 'wip' of gitlab.psi.ch:samenv/frappy into wip
This commit is contained in:
commit
7fc030191d
@ -67,5 +67,6 @@ uri = ma10-ts.psi.ch:3004
|
|||||||
description = stick rotation, typically used for omega
|
description = stick rotation, typically used for omega
|
||||||
class = secop_psi.phytron.Motor
|
class = secop_psi.phytron.Motor
|
||||||
io = om_io
|
io = om_io
|
||||||
|
sign = -1
|
||||||
encoder_mode = CHECK
|
encoder_mode = CHECK
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -10,7 +10,7 @@ service = stick
|
|||||||
|
|
||||||
[ts]
|
[ts]
|
||||||
class = secop_psi.sea.SeaReadable
|
class = secop_psi.sea.SeaReadable
|
||||||
iodev = sea_stick
|
io = sea_stick
|
||||||
sea_object = tt
|
sea_object = tt
|
||||||
json_file = ma10.config.json
|
json_file = ma10.config.json
|
||||||
rel_paths = ts
|
rel_paths = ts
|
||||||
|
@ -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):
|
||||||
@ -60,18 +62,29 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
|||||||
speed = Parameter('', FloatRange(0, 20, unit='deg/s'), readonly=False)
|
speed = Parameter('', FloatRange(0, 20, unit='deg/s'), readonly=False)
|
||||||
accel = Parameter('', FloatRange(2, 250, unit='deg/s/s'), readonly=False)
|
accel = Parameter('', FloatRange(2, 250, unit='deg/s/s'), readonly=False)
|
||||||
encoder_tolerance = Parameter('', FloatRange(unit='deg'), readonly=False, default=0.01)
|
encoder_tolerance = Parameter('', FloatRange(unit='deg'), readonly=False, default=0.01)
|
||||||
zero = PersistentParam('', FloatRange(unit='deg'), readonly=False, default=0)
|
offset = PersistentParam('', FloatRange(unit='deg'), readonly=False, default=0)
|
||||||
|
sign = PersistentParam('', IntRange(-1,1), readonly=False, default=1)
|
||||||
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):
|
||||||
@ -86,7 +99,7 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
|||||||
|
|
||||||
def read_value(self):
|
def read_value(self):
|
||||||
prev_enc = self.encoder
|
prev_enc = self.encoder
|
||||||
pos = float(self.get('P20R')) + self.zero
|
pos = float(self.get('P20R')) * self.sign - self.offset
|
||||||
if self.encoder_mode != 'NO':
|
if self.encoder_mode != 'NO':
|
||||||
enc = self.read_encoder()
|
enc = self.read_encoder()
|
||||||
else:
|
else:
|
||||||
@ -111,7 +124,7 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
|||||||
else:
|
else:
|
||||||
if self._sameside_pending:
|
if self._sameside_pending:
|
||||||
# drive to real target
|
# drive to real target
|
||||||
self.set('A', self.target - self.zero)
|
self.set('A', self.sign * (self.target + self.offset))
|
||||||
self._sameside_pending = False
|
self._sameside_pending = False
|
||||||
return pos
|
return pos
|
||||||
if (self.encoder_mode == 'CHECK' and
|
if (self.encoder_mode == 'CHECK' and
|
||||||
@ -131,7 +144,7 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
|||||||
def read_encoder(self):
|
def read_encoder(self):
|
||||||
if self.encoder_mode == 'NO':
|
if self.encoder_mode == 'NO':
|
||||||
return self.value
|
return self.value
|
||||||
return float(self.get('P22R')) + self.zero
|
return float(self.get('P22R')) * self.sign - self.offset
|
||||||
|
|
||||||
def read_speed(self):
|
def read_speed(self):
|
||||||
return float(self.get('P14R')) / self.speed_factor
|
return float(self.get('P14R')) / self.speed_factor
|
||||||
@ -150,22 +163,42 @@ 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
|
||||||
self._sameside_pending = True
|
self._sameside_pending = True
|
||||||
self.set('A', value - self.zero + self.sameside_offset)
|
self.set('A', self.sign * (value + self.offset + self.sameside_offset))
|
||||||
else:
|
else:
|
||||||
self.set('A', value - self.zero)
|
self.set('A', self.sign * (value + self.offset))
|
||||||
self.setFastPoll(True, self.fast_poll)
|
self.setFastPoll(True, self.fast_poll)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def write_zero(self, value):
|
def read_userlimits(self):
|
||||||
self.zero = value
|
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):
|
||||||
|
self.offset = value
|
||||||
|
self.read_userlimits()
|
||||||
self.saveParameters()
|
self.saveParameters()
|
||||||
return Done
|
return Done
|
||||||
|
|
||||||
@ -177,16 +210,17 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
|||||||
"""reset error, set position to encoder"""
|
"""reset error, set position to encoder"""
|
||||||
self.read_value()
|
self.read_value()
|
||||||
if self.status[0] == self.Status.ERROR:
|
if self.status[0] == self.Status.ERROR:
|
||||||
enc = self.encoder - self.zero
|
enc = self.encoder + self.offset
|
||||||
pos = self.value - self.zero
|
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.zero -= 360
|
self.offset += 360
|
||||||
enc += 360
|
enc += 360
|
||||||
self.set('P22S', enc)
|
self.set('P22S', enc * self.sign)
|
||||||
self.saveParameters()
|
self.saveParameters()
|
||||||
self.set('P20S', enc) # set pos to encoder
|
self.set('P20S', enc * self.sign) # set pos to encoder
|
||||||
self.read_value()
|
self.read_value()
|
||||||
# self.status = self.Status.IDLE, ''
|
# self.status = self.Status.IDLE, ''
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ class SeaClient(ProxyClient, Module):
|
|||||||
self._connect_thread = None
|
self._connect_thread = None
|
||||||
mkthread(self._rxthread, started_callback)
|
mkthread(self._rxthread, started_callback)
|
||||||
|
|
||||||
def request(self, command):
|
def request(self, command, quiet=False):
|
||||||
"""send a request and wait for reply"""
|
"""send a request and wait for reply"""
|
||||||
with self._write_lock:
|
with self._write_lock:
|
||||||
if not self.syncio or not self.syncio.connection:
|
if not self.syncio or not self.syncio.connection:
|
||||||
@ -181,7 +181,8 @@ class SeaClient(ProxyClient, Module):
|
|||||||
print('connected to %s' % self.uri)
|
print('connected to %s' % self.uri)
|
||||||
self.syncio.flush_recv()
|
self.syncio.flush_recv()
|
||||||
# print('> %s' % command)
|
# print('> %s' % command)
|
||||||
self.syncio.writeline(('fulltransact %s' % command).encode())
|
ft = 'fulltransAct' if quiet else 'fulltransact'
|
||||||
|
self.syncio.writeline(('%s %s' % (ft, command)).encode())
|
||||||
result = None
|
result = None
|
||||||
deadline = time.time() + 10
|
deadline = time.time() + 10
|
||||||
while time.time() < deadline:
|
while time.time() < deadline:
|
||||||
@ -292,11 +293,11 @@ class SeaClient(ProxyClient, Module):
|
|||||||
return reply
|
return reply
|
||||||
|
|
||||||
@Command(StringType(), result=StringType())
|
@Command(StringType(), result=StringType())
|
||||||
def query(self, cmd):
|
def query(self, cmd, quiet=False):
|
||||||
"""a request checking for errors and accepting 0 or 1 line as result"""
|
"""a request checking for errors and accepting 0 or 1 line as result"""
|
||||||
errors = []
|
errors = []
|
||||||
reply = None
|
reply = None
|
||||||
for line in self.request(cmd).split('\n'):
|
for line in self.request(cmd, quiet).split('\n'):
|
||||||
if line.strip().startswith('ERROR:'):
|
if line.strip().startswith('ERROR:'):
|
||||||
errors.append(line[6:].strip())
|
errors.append(line[6:].strip())
|
||||||
elif reply is None:
|
elif reply is None:
|
||||||
@ -408,6 +409,7 @@ class SeaModule(Module):
|
|||||||
if issubclass(cls, SeaWritable):
|
if issubclass(cls, SeaWritable):
|
||||||
if paramdesc.get('readonly', True):
|
if paramdesc.get('readonly', True):
|
||||||
raise ConfigError('%s/%s is not writable' % (sea_object, paramdesc['path']))
|
raise ConfigError('%s/%s is not writable' % (sea_object, paramdesc['path']))
|
||||||
|
params.insert(0, paramdesc.copy()) # copy value
|
||||||
paramdesc['key'] = 'target'
|
paramdesc['key'] = 'target'
|
||||||
paramdesc['readonly'] = False
|
paramdesc['readonly'] = False
|
||||||
extra_module_set = ()
|
extra_module_set = ()
|
||||||
@ -543,7 +545,7 @@ class SeaModule(Module):
|
|||||||
# print('override %s.read_%s' % (cls.__name__, key))
|
# print('override %s.read_%s' % (cls.__name__, key))
|
||||||
|
|
||||||
def rfunc(self, cmd='hval %s/%s' % (base, path)):
|
def rfunc(self, cmd='hval %s/%s' % (base, path)):
|
||||||
reply = self.io.query(cmd)
|
reply = self.io.query(cmd, True)
|
||||||
try:
|
try:
|
||||||
reply = float(reply)
|
reply = float(reply)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user