Ejemplo n.º 1
0
def test_limits():
    assert limits((-10, 10)) == (-10, 10)
    assert limits((0, 0)) == (0, 0)
    assert limits() == (0, 0)
    assert limits([-10, 10]) == (-10, 10)
    assert raises(ValueError, limits, (1, ))
    assert raises(ValueError, limits, 1)
    assert raises(ValueError, limits, (10, 10, 10))
    assert raises(TypeError, limits, 1, 1)
    assert raises(ValueError, limits, (10, -10))
    assert raises(ValueError, limits, ('a', 'b'))
Ejemplo n.º 2
0
    def _generateSequence(self, target):
        self.wlmin, self.wlmax = limits(
            (target.get('wlmin', self.wlmin), target.get('wlmax', self.wlmax)))
        self.dist = target.get('D', self.dist)
        self.gap = target.get('gap', self.gap)
        chopper2_pos = target.get('chopper2_pos')

        speed, angles = chopper_config(self.wlmin,
                                       self.wlmax,
                                       self.dist,
                                       chopper2_pos,
                                       gap=self.gap)

        self.log.debug('speed: %d, angles = %s', speed, angles)

        seq = []
        shutter_pos = self._attached_shutter.read(0)
        shutter_ok = self._attached_shutter.status(0)[0] == status.OK
        if chopper2_pos == 6:
            self._setROParam('mode', 'virtual_disc2_pos_6')
        else:
            self._setROParam('mode', 'normal_mode')
            chopper2_pos_akt = self._attached_chopper2.pos
            if chopper2_pos_akt != chopper2_pos:
                if shutter_ok:
                    seq.append(
                        SeqDev(self._attached_shutter,
                               'closed',
                               stoppable=True))
                seq.append(SeqDev(self._attached_chopper1, 0, stoppable=True))
                seq.append(
                    SeqSlowParam(self._attached_chopper2, 'pos', chopper2_pos))

        for dev, t in zip(self._choppers[1:], angles[1:]):
            # The Chopper measures the phase in the opposite direction
            # as we do this was catered for here, we have moved the
            # sign conversion to the doWritePhase function
            # dev.phase = -t  # sign by history
            seq.append(SeqFuzzyParam(dev, 'phase', t, 0.5))
        seq.append(SeqDev(self._attached_chopper1, speed, stoppable=True))
        if shutter_ok:
            seq.append(
                SeqDev(self._attached_shutter, shutter_pos, stoppable=True))
        return seq
Ejemplo n.º 3
0
class ChopperDiscTranslation(CanReference, IsController, DeviceMixinBase):
    """Position of chopper disc along the x axis.

    Since the chopper disc can be translated, the chopper speed must be low
    enough (around 0, defined by its precision).

    The change of speed must be blocked if the translation device is not at
    a defined position.
    """

    valuetype = intrange(1, 5)

    attached_devices = {
        'disc': Attach('Chopper disc device', Moveable),
    }

    parameter_overrides = {
        'unit': Override(default='', mandatory=False),
        'abslimits': Override(mandatory=False, default=limits((1, 5))),
        'fmtstr': Override(default='%d'),
    }

    def doReference(self, *args):
        self.move(1)

    def doIsAllowed(self, target):
        if self._attached_disc._isStopped():
            return True, ''
        return False, 'Disc (%s) speed is too high, %.0f!' % (
            self._attached_disc, self.read(0))

    def isAdevTargetAllowed(self, dev, target):
        state = self.status(0)
        if state[0] == status.OK:
            return True, ''
        return False, 'translation is: %s' % state[1]

    def _getWaiters(self):
        return []