diff --git a/secop/modules.py b/secop/modules.py index ed1df5d..c4e1d83 100644 --- a/secop/modules.py +++ b/secop/modules.py @@ -419,6 +419,8 @@ class Module(HasAccessibles): def announceUpdate(self, pname, value=None, err=None, timestamp=None): """announce a changed value or readerror""" pobj = self.parameters[pname] + timestamp = timestamp or time.time() + changed = pobj.value != value or timestamp > (pobj.timestamp or 0) + 1 if value is not None: pobj.value = value # store the value even in case of error if err: @@ -431,7 +433,9 @@ class Module(HasAccessibles): pobj.value = pobj.datatype(value) except Exception as e: err = secop_error(e) - pobj.timestamp = timestamp or time.time() + if not changed: + return # experimental: do not update unchanged values within 1 sec + pobj.timestamp = timestamp pobj.readerror = err if pobj.export: self.DISPATCHER.announce_update(self.name, pname, pobj) diff --git a/secop_psi/dpm.py b/secop_psi/dpm.py index 6cb57d6..4069c6c 100644 --- a/secop_psi/dpm.py +++ b/secop_psi/dpm.py @@ -116,28 +116,37 @@ class DPM3(HasIodev, Drivable): def read_value(self): value = float(self._iodev.communicate('*1B1')) - if self._target is not None: - mot = self._motor - if self._direction * (self._target - value) > 0: - if not mot.isBusy(): - step = self.step * self._direction - mot.write_target(mot.value + step) + mot = self._motor + if self._target is None: + if mot.isBusy(): + self.status = self.Status.IDLE, 'stopping' + else: + self.status = self.Status.IDLE, '' + else: + if self._direction * (self._target - value) > 0: + if self._mot_target != mot.target: + self.stop() + self.status = self.Status.IDLE, 'motor was stopped' + elif not mot.isBusy(): + step = self.step * self._direction + mot_target = mot.value + step + self._mot_target = mot.write_target(mot_target) else: - print(value) self.stop() self.status = self.Status.IDLE, 'target reached' return value def write_target(self, target): self._target = target + self._started = True if target - self.value > 0: self._direction = 1 else: self._direction = -1 - print('direction', self._direction) self.status = self.Status.BUSY, 'moving motor' if self._motor.status[0] == self.Status.ERROR: self._motor.reset() + self._mot_target = self._motor.target return target @Command() diff --git a/secop_psi/trinamic.py b/secop_psi/trinamic.py index 67c9aa2..b62e3aa 100644 --- a/secop_psi/trinamic.py +++ b/secop_psi/trinamic.py @@ -81,7 +81,7 @@ class Motor(PersistentMixin, HasIodev, Drivable): # TupleOf(IntRange(0, 15), IntRange(0, 15)), # default=(8, 0)) - value = Parameter('motor position', FloatRange(unit='deg', fmtstr='%.3f')) + value = Parameter('motor position', FloatRange(unit='deg', fmtstr='%.3f'), poll=False, default=0) # polling by read_status zero = PersistentParam('zero point', FloatRange(unit='$'), readonly=False, default=0) encoder = HwParam('encoder reading', FloatRange(unit='$', fmtstr='%.1f'), 209, ANGLE_SCALE, readonly=True, initwrite=False, persistent=True) @@ -124,7 +124,8 @@ class Motor(PersistentMixin, HasIodev, Drivable): iodevClass = BytesIO - fast_pollfactor = 0.001 # poll as fast as possible when busy + # fast_pollfactor = 0.001 # poll as fast as possible when busy + fast_pollfactor = 0.05 _started = 0 _calcTimeout = True _need_reset = None @@ -400,6 +401,7 @@ class Motor(PersistentMixin, HasIodev, Drivable): def stop(self): self.comm(MOTOR_STOP, 0) self.status = self.Status.IDLE, 'stopped' + self.target = self.value # indicate to customers that this was stopped self._started = 0 #@Command()