Beispiel #1
0
    def _checkArrival(self):
        theta, trans = self._calcMonoPosition(self.target)
        th1 = self._attached_mth1.read(0)
        th2 = self._attached_mth2.read(0)
        if abs(th1 - th2) > self._attached_mth1.precision:
            raise PositionError('Double Monochromator blades out of sync, '
                                '%f versus %d' % (th1, th2))
        if abs(th1 - theta) > self._attached_mth1.precision:
            raise PositionError('Blades did not arrive at target')

        if (abs(trans - self._attached_mtx.read(
                0))) > self._attached_mtx.precision:
            raise PositionError('Double monochromator translation not in '
                                'position, should %f, is %f'
                                % (trans, self._attached_mtx.read(0)))
Beispiel #2
0
    def _readBit(self, byte, bit):
        raw = self._get_pv('readpv')
        if byte > len(raw):
            raise PositionError('Byte specified is out of bounds')

        powered = 1 << bit
        return raw[byte] & powered == powered
Beispiel #3
0
 def _d(self, maxage=0):
     crystal = self._crystal(maxage)
     if crystal:
         p = crystal.get(self.plane, None)
         if p:
             return p[0]
     raise PositionError('No valid setup of the monochromator')
Beispiel #4
0
    def doRead(self, maxage=0):
        distances = self._attached_distances

        # Check if the sample and polariser distances are available
        if not isinstance(distances.sample, number_types):
            raise PositionError('Distances for sample and polariser unknown')

        soz = self._read_dev('soz')

        if not self._is_active('polariser'):
            actm2t = 0.0
        else:
            dist = abs(distances.sample - distances.polariser)
            tmp = soz / dist if dist else 0
            actm2t = math.degrees(-1 * math.atan(tmp)) if abs(tmp) > 1e-4 else 0.0

        if self._is_active('analyser'):
            aom = self._read_dev('aom')
            aoz = self._read_dev('aoz')
            sah = abs(distances.analyser - distances.sample)
            acts2t = math.degrees(math.atan((aoz - soz) / sah)) + actm2t
            actath = -1 * (acts2t - actm2t - aom)
        else:
            com = self._read_dev('com')
            acts2t = com + actm2t
            aom = self._read_dev('aom')
            actath = aom - com

        return {
            M2T: round(actm2t, 3),
            S2T: round(acts2t, 3),
            ATH: round(actath, 3)
        }
Beispiel #5
0
    def doStart(self, position):
        """Move coupled axis (tt/th).

        The tt axis should without moving the coupled axis th (tt + th == 0)
        """
        if self.doStatus(0)[0] == status.BUSY:
            self.log.error('device busy')

        target = (position, -position)
        if not self._checkReachedPosition(target):
            try:
                self._setROParam('_status', True)

                self.__setDiffLimit()

                tt = self.tt.read(0)
                th = self.th.read(0)

                if abs(tt - target[0]) > self.difflimit or \
                   abs(th - target[1]) > self.difflimit:
                    delta = abs(tt - position)
                    mod = math.fmod(delta, self.difflimit)
                    steps = int(delta / self.difflimit)
                    self.log.debug('delta/self.difflimit, mod: %s, %s', steps,
                                   mod)

                    if tt > position:
                        self.log.debug('case tt > position')
                        delta = -self.difflimit
                    elif tt < position:
                        self.log.debug('case tt < position')
                        delta = self.difflimit

                    for i in range(1, steps + 1):
                        d = i * delta
                        self.log.debug('step: %d, move tt: %.2f, th: %.2f:', i,
                                       tt + d, th - d)
                        self.__setDiffLimit()
                        self.th.move(th - d)
                        self.tt.move(tt + d)
                        self._hw_wait()
                else:
                    steps = 1

                if not self._checkReachedPosition(target):
                    self.log.debug('step: %d, move tt: %.2f, th: %.2f:', steps,
                                   position, -position)
                    self.__setDiffLimit()
                    self.th.move(-position)
                    self.tt.move(position)
                    self._hw_wait()
                if not self._checkReachedPosition(target):
                    PositionError(
                        self, "couldn't reach requested position "
                        '%7.3f' % position)
            finally:
                self.log.debug('Clear status flag')
                self._setROParam('_status', False)
                self.poll()
Beispiel #6
0
 def _mapReadValue(self, value):
     for val in self.mapping:
         if self._is_at_target(value, self.mapping[val]):
             return val
     if self.fallback is not None:
         return self.fallback
     else:
         raise PositionError(self, 'unknown unmapped position %r' % value)
Beispiel #7
0
def move_dev(dev, pos, sleeptime=0, maxtries=3):
    session.log.info('Moving %s to %f', dev, pos)
    d = session.getDevice(dev)
    for _ in range(maxtries):
        d.maw(pos)
        if sleeptime:
            sleep(sleeptime)
        if abs(d.read() - pos) < d.precision:
            return
    raise PositionError(dev, 'Could not move %d to %f' % (dev, pos))
Beispiel #8
0
 def doWritePlane(self, target):
     crystal = self._crystal(0)
     if crystal:
         if not crystal.get(target, None):
             raise ValueError(
                 'The "%s" plane is not allowed for "%s" crystal' %
                 (target, crystal))
     else:
         raise PositionError('No valid setup of the monochromator')
     return target
Beispiel #9
0
 def doStart(self, target):
     _from = self.read(0)
     for _ in range(self.maxtries):
         self.log.debug('try %d: move to %s', _, target)
         self._moveto(target)
         if self.read(0) == target:
             return
         self.log.debug('move back to start pos: %s', _from)
         self._moveto(_from)  # move back to starting point
     raise PositionError(self, 'could not move to target: %r' % target)
Beispiel #10
0
    def doReset(self):
        """Reset individual axes, set angle between axes within one degree."""
        multiReset([self.tt, self.th])
        tt, th = self.tt.read(0), self.th.read(0)

        if not self._checkZero(tt, th):
            if (tt + th) <= self.difflimit:
                self.tt.maw(-th)
                return
            raise PositionError(
                self, '%s and %s are not close enough' % (self.tt, self.th))
Beispiel #11
0
    def _move_translations(self, target):
        # first check for translation
        mvt = self._checkPositionReachedTrans(target)
        if mvt:
            self.log.debug('The following translation axes start moving: %r',
                           mvt)
            # check if translation movement is allowed, i.e. if all
            # rotation axis at reference switch
            if not self._checkRefSwitchRotation():
                if not self._refrotation():
                    raise PositionError(self, 'Could not reference rotations')

            self.log.debug('all rotation at refswitch, start translation')
            for i, dev in enumerate(self._translation):
                with self._allowed():
                    dev.move(target[i])
            self._hw_wait(self._translation)

            if self._checkPositionReachedTrans(target):
                raise PositionError(self, 'Translation drive not successful')
            self.log.debug('translation movement done')
Beispiel #12
0
 def doStart(self, target):
     crystal = self._crystal(0)
     if not crystal:
         raise PositionError(self, 'Not valid setup')
     tthm = asin(target / (2 * self._d(0))) / pi * 360.
     plane = crystal.get(self.plane, None)
     if not plane:
         raise ConfigurationError(self, 'No valid mono configuration')
     omgm = tthm / 2.0 + plane[1] + plane[2]
     self.log.debug(self._attached_tthm, 'will be moved to %.3f' % tthm)
     self.log.debug(self._attached_omgm, 'will be moved to %.3f' % omgm)
     if self._attached_tthm.isAllowed(tthm) and \
        self._attached_omgm.isAllowed(omgm):
         self._attached_tthm.start(tthm)
         self._attached_omgm.start(omgm)
Beispiel #13
0
 def __setDiffLimit(self):
     """Set limits of device in dependence of allowed set of difflimit."""
     if self._checkZero(self.tt.read(0), self.th.read(0)):
         for ax in [self.tt, self.th]:
             p = ax.read(0)
             self.log.debug('%s, %s', ax, p)
             limit = self.difflimit
             absMin = p - (limit + 2. * ax.precision - 0.0001)
             absMax = p + (limit + 2. * ax.precision - 0.0001)
             self.log.debug('user limits for %s: %r',
                            ax.name, (absMin, absMax))
             # ax.userlimits = (absMin, absMax)
             self.log.debug('user limits for %s: %r', ax.name,
                            ax.userlimits)
     else:
         raise PositionError(self, 'cannot set new limits; coupled axes %s '
                             'and %s are not close enough difference > %f '
                             'deg.' % (self.tt, self.th, self.difflimit))
Beispiel #14
0
 def _move_rotations(self, target):
     # Rotation Movement
     mvr = self._checkPositionReachedRot(self.doRead(0), target)
     if mvr:
         self.log.debug('The following rotation axes start moving: %r', mvr)
         for i in mvr:
             ll, hl = self._calc_rotlimits(i, target)
             if not ll <= target[self._num_axes + i] <= hl:
                 self.log.warning('neighbour is to close; cannot move '
                                  'rotation!')
                 continue
             with self._allowed():
                 self._rotation[i].move(target[self._num_axes + i])
         self._hw_wait([self._rotation[i] for i in mvr])
         if self._checkPositionReachedRot(self.doRead(0), target):
             raise PositionError(self, 'Rotation drive not successful: '
                                 '%r' % ['%s' % d for d in mvr])
         self.log.debug('rotation movement done')