MeasureTipTiltMirrorRange

Bases: KPFFunction

Measure the range of the tip tilt mirror. Prints to screen the keyword modify commands to update the range parameters.

KTL Keywords Used:

  • kpffiu.TTXVAX
  • kpffiu.TTYVAX
  • kpffiu.TTXMEX
  • kpffiu.TTYMEX
  • kpffiu.TTXMED
  • kpffiu.TTYMED
  • kpfguide.TIPTILT_HOME

Functions Called:

  • kpf.fiu.InitializeTipTilt
  • kpf.fiu.ShutdownTipTilt
Source code in kpf/fiu/MeasureTipTiltMirrorRange.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
class MeasureTipTiltMirrorRange(KPFFunction):
    '''Measure the range of the tip tilt mirror.  Prints to screen the keyword
    modify commands to update the range parameters.

    KTL Keywords Used:

    - `kpffiu.TTXVAX`
    - `kpffiu.TTYVAX`
    - `kpffiu.TTXMEX`
    - `kpffiu.TTYMEX`
    - `kpffiu.TTXMED`
    - `kpffiu.TTYMED`
    - `kpfguide.TIPTILT_HOME`

    Functions Called:

    - `kpf.fiu.InitializeTipTilt`
    - `kpf.fiu.ShutdownTipTilt`
    '''
    @classmethod
    def pre_condition(cls, args):
        pass

    @classmethod
    def perform(cls, args):
        # Measure tip tilt ranges
        log.info('Beginning MeasureTipTiltMirrorRange')
        InitializeTipTilt.execute({})

        sleeptime = 10 # Set by the 5 second time in the %MEX and %MEV keywords
                       # Need to account for worst case
        tol = cfg.getfloat('tolerances', 'tip_tilt_move_tolerance', fallback=0.1)
        n = args.get('repeats')

        kpffiu = ktl.cache('kpffiu')
        kpfguide = ktl.cache('kpfguide')

        measured_range = {}
        axis = ['X', 'Y']
        rawvals = {}
        update_ax = {'X': False, 'Y': False}
        for i,ax in enumerate(axis):
            nominal_range = {'X': 15.9, 'Y': 24.6}[ax]
            home = 0
            measured_range[ax] = [-nominal_range, nominal_range]
            rawvals[ax] = [None, None]

            # Negative side
            commanded_position = home-nominal_range
            new_limit = find_new_limit(ax, commanded_position,
                                       sleeptime=sleeptime, tol=tol, n=n)
            if new_limit is not None:
                update_ax[ax] = True
                measured_range[ax][0] = new_limit

            # Positive side
            commanded_position = home+nominal_range
            new_limit = find_new_limit(ax, commanded_position,
                                       sleeptime=sleeptime, tol=tol, n=n)
            if new_limit is not None:
                update_ax[ax] = True
                measured_range[ax][1] = new_limit

            time.sleep(sleeptime)
            InitializeTipTilt.execute({})
            time.sleep(sleeptime)

        log.info(f"Measured X range: {measured_range['X']}")
        log.info(f"Measured Y range: {measured_range['Y']}")

        new_home = [np.mean(measured_range['X']), np.mean(measured_range['Y'])]
        current_home = kpfguide['TIPTILT_HOME'].read(binary=True)
        if np.isclose(current_home[0], new_home[0]) and np.isclose(current_home[1], new_home[1]):
            print(f'TIPTILT_HOME OK: gshow -s kpfguide TIPTILT_HOME matches {new_home}')
        else:
            print(f"modify -s kpfguide TIPTILT_HOME='{new_home[0]:.1f} {new_home[1]:.1f}'")

        for i,ax in enumerate(axis):
            print()
            range = (max(measured_range[ax]) - min(measured_range[ax]))/2
            print(f"modify -s kpfguide TIPTILT_{ax}RANGE={range:.1f}")
            print(f"  Sending {ax} to home")
            kpffiu[f'TT{ax}VAX'].write(new_home[i])
            time.sleep(sleeptime)
            new_RON = kpffiu[f'TT{ax}MED'].read()
            print(f"modify -s kpffiu TT{ax}RON='|{new_RON}|0|Home'")


    @classmethod
    def post_condition(cls, args):
        pass

    @classmethod
    def add_cmdline_args(cls, parser):
        parser.add_argument('--repeats', type=int, default=1,
                            help="The number of iterations to use in the calculation")
        return super().add_cmdline_args(parser)