SetTipTiltPosition

Bases: KPFTranslatorFunction

Set the position of the tip tilt mirror.

This should only be used in an engineering context. To control the position of a star, set the CURRENT_BASE or PIX_TARGET keywords as appropriate, e.g. via the kpf.fiu.SetTipTiltTargetPixel translator module function.

Parameters:
  • x (float) –

    The desired X position (TTXVAX).

  • y (float) –

    The desired Y position (TTYVAX).

KTL Keywords Used:

  • kpffiu.TTXVAX
  • kpffiu.TTYVAX
Source code in kpf/fiu/SetTipTiltPosition.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class SetTipTiltPosition(KPFTranslatorFunction):
    '''Set the position of the tip tilt mirror.

    This should only be used in an engineering context. To control the position
    of a star, set the CURRENT_BASE or PIX_TARGET keywords as appropriate, e.g.
    via the `kpf.fiu.SetTipTiltTargetPixel` translator module function.

    Args:
        x (float): The desired X position (TTXVAX).
        y (float): The desired Y position (TTYVAX).

    KTL Keywords Used:

    - `kpffiu.TTXVAX`
    - `kpffiu.TTYVAX`
    '''
    @classmethod
    def pre_condition(cls, args, logger, cfg):
        check_input(args, 'x')
        check_input(args, 'y')

    @classmethod
    def perform(cls, args, logger, cfg):
        kpffiu = ktl.cache('kpffiu')
        kpffiu['TTXVAX'].write(args.get('x'))
        kpffiu['TTYVAX'].write(args.get('y'))
        time_shim = cfg.getfloat('times', 'tip_tilt_move_time', fallback=0.1)
        time.sleep(time_shim)

    @classmethod
    def post_condition(cls, args, logger, cfg):
        kpffiu = ktl.cache('kpffiu')
        timeout = cfg.getfloat('times', 'tip_tilt_move_time', fallback=0.1)
        tol = cfg.getfloat('tolerances', 'tip_tilt_move_tolerance', fallback=0.1)
        xdest = args.get('x')
        ydest = args.get('y')
        expr = (f'($kpffiu.TTXVAX > {xdest-tol}) and '\
                f'($kpffiu.TTXVAX < {xdest+tol})')
        successx = ktl.waitFor(expr, timeout=timeout)
        if successx is not True:
            raise FailedToReachDestination(kpffiu['TTXVAX'].read(), xdest)
        expr = (f'($kpffiu.TTYVAX > {ydest-tol}) and '\
                f'($kpffiu.TTYVAX < {ydest+tol})')
        successy = ktl.waitFor(expr, timeout=timeout)
        if successy is not True:
            raise FailedToReachDestination(kpffiu['TTYVAX'].read(), ydest)

    @classmethod
    def add_cmdline_args(cls, parser, cfg=None):
        parser.add_argument('x', type=float,
                            help="X position of the tip tilt mirror (TTXVAX)")
        parser.add_argument('y', type=float,
                            help="X position of the tip tilt mirror (TTYVAX)")
        return super().add_cmdline_args(parser, cfg)