ControlAOHatch

Bases: KPFTranslatorFunction

Command the AO Hatch to open or close.

Parameters:
  • destination (str) –

    The destination position. Allowed Values: 'open' or 'close'.

KTL Keywords Used:

  • ao.AOHATCHCMD
  • ao.AOHATCHSTS
Source code in kpf/ao/ControlAOHatch.py
 8
 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
class ControlAOHatch(KPFTranslatorFunction):
    '''Command the AO Hatch to open or close.

    Args:
        destination (str): The destination position. Allowed Values: 'open' or
            'close'.

    KTL Keywords Used:

    - `ao.AOHATCHCMD`
    - `ao.AOHATCHSTS`
    '''
    @classmethod
    def pre_condition(cls, args, logger, cfg):
        check_input(args, 'destination', allowed_values=['close', 'closed', 'open'])

    @classmethod
    def perform(cls, args, logger, cfg):
        destination = args.get('destination', '').strip()
        ao = ktl.cache('ao')
        log.debug(f"Setting AO Hatch to {destination}")
        cmd = {'close': 1, 'closed': 1, 'open': 0}[destination]
        ao['aohatchcmd'].write(cmd)

    @classmethod
    def post_condition(cls, args, logger, cfg):
        destination = args.get('destination', '').strip()
        final_dest = {'close': 'closed', 'closed': 'closed', 'open': 'open'}[destination]
        aohatchsts = ktl.cache('ao', 'AOHATCHSTS')
        success = aohatchsts.waitfor(f"== '{final_dest}'", timeout=30)
        if success is not True:
            raise FailedToReachDestination(aohatchsts.read(), final_dest)

    @classmethod
    def add_cmdline_args(cls, parser, cfg=None):
        parser.add_argument('destination', type=str,
                            choices=['open', 'close'],
                            help='Desired hatch position')
        return super().add_cmdline_args(parser, cfg)