From 68e2e06905bdc6daf2b4f288fcf105add8e7136a Mon Sep 17 00:00:00 2001 From: zebra Date: Wed, 1 Jun 2022 09:21:47 +0200 Subject: [PATCH] fixes in convergence, mercury, phytron, triton --- secop_psi/convergence.py | 4 ++-- secop_psi/mercury.py | 2 ++ secop_psi/phytron.py | 25 +++++++++++++------------ secop_psi/triton.py | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/secop_psi/convergence.py b/secop_psi/convergence.py index 627cf83..f7cddc6 100644 --- a/secop_psi/convergence.py +++ b/secop_psi/convergence.py @@ -60,8 +60,8 @@ class HasConvergence: def cleanup(self, state): state.default_cleanup(state) - if self.stopped: - if self.stopped is Stop: # and not Restart + if state.stopped: + if state.stopped is Stop: # and not Restart self.status = WARN, 'stopped' else: self.status = WARN, repr(state.last_error) diff --git a/secop_psi/mercury.py b/secop_psi/mercury.py index 87bf8a0..c05904e 100644 --- a/secop_psi/mercury.py +++ b/secop_psi/mercury.py @@ -341,6 +341,7 @@ class TemperatureLoop(TemperatureSensor, Loop, Drivable): enable_ramp = Parameter('enable ramp rate', BoolType(), readonly=False) setpoint = Parameter('working setpoint (differs from target when ramping)', FloatRange(0, unit='$')) auto_flow = Parameter('enable auto flow', BoolType(), readonly=False) + tolerance = Parameter(default=0.1) _last_setpoint_change = None def doPoll(self): @@ -452,6 +453,7 @@ class ValvePos(HasInput, MercuryChannel, Drivable): class PressureLoop(PressureSensor, Loop, Drivable): channel_type = 'PRES,AUX' output_module = Attached(ValvePos, mandatory=False) + tolerance = Parameter(default=0.1) def read_control_active(self): active = self.query('PRES:LOOP:FAUT', off_on) diff --git a/secop_psi/phytron.py b/secop_psi/phytron.py index cc0e585..c95ab52 100644 --- a/secop_psi/phytron.py +++ b/secop_psi/phytron.py @@ -31,7 +31,7 @@ from secop.lib import clamp class PhytronIO(StringIO): end_of_line = '\x03' # ETX - timeout = 0.2 + timeout = 0.5 identification = [('0IVR', 'MCC Minilog .*')] def communicate(self, command, expect_response=True): @@ -65,8 +65,9 @@ class Motor(PersistentMixin, HasIO, Drivable): 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')) - sameside_offset = Parameter('offset when always approaching from the same side', - FloatRange(unit='deg'), readonly=False, default=0) + backlash = Parameter("""backlash compensation\n + offset for always approaching from the same side""", + 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, @@ -74,7 +75,7 @@ class Motor(PersistentMixin, HasIO, Drivable): ioClass = PhytronIO fast_poll = 0.1 - _sameside_pending = False + _backlash_pending = False _mismatch_count = 0 _rawlimits = None @@ -122,10 +123,10 @@ class Motor(PersistentMixin, HasIO, Drivable): else: self.status = self.Status.BUSY, 'driving' else: - if self._sameside_pending: + if self._backlash_pending: # drive to real target self.set('A', self.sign * (self.target + self.offset)) - self._sameside_pending = False + self._backlash_pending = False return pos if (self.encoder_mode == 'CHECK' and abs(enc - pos) > self.encoder_tolerance): @@ -176,12 +177,12 @@ class Motor(PersistentMixin, HasIO, Drivable): if self.status[0] == self.Status.ERROR: raise HardwareError('need reset') self.status = self.Status.BUSY, 'changed target' - self._check_limits(value, value + self.sameside_offset) - if self.sameside_offset: - # drive first to target + sameside_offset + self._check_limits(value, value + self.backlash) + if self.backlash: + # drive first to target + backlash # we do not optimize when already driving from the right side - self._sameside_pending = True - self.set('A', self.sign * (value + self.offset + self.sameside_offset)) + self._backlash_pending = True + self.set('A', self.sign * (value + self.offset + self.backlash)) else: self.set('A', self.sign * (value + self.offset)) self.setFastPoll(True, self.fast_poll) @@ -207,7 +208,7 @@ class Motor(PersistentMixin, HasIO, Drivable): @Command def reset(self): - """reset error, set position to encoder""" + """Reset error, set position to encoder""" self.read_value() if self.status[0] == self.Status.ERROR: enc = self.encoder + self.offset diff --git a/secop_psi/triton.py b/secop_psi/triton.py index cd12ee6..dbf8e9d 100644 --- a/secop_psi/triton.py +++ b/secop_psi/triton.py @@ -32,7 +32,7 @@ open_close = Mapped(CLOSE=False, OPEN=True) actions_map = Mapped(NONE=actions.none, COND=actions.condense, COLL=actions.collect) -class Action(MercuryChannel): +class Action(MercuryChannel, Writable): channel_type = 'ACTN' value = Parameter('running action', EnumType(actions)) target = Parameter('valve target', EnumType(none=0, condense=1, collect=3), readonly=False)