class WaitForConfigureFIU(KPFTranslatorFunction):
'''Wait for the FIU to reach specified mode (kpffiu.MODE). This will retry
the configure command if the system fails to reach its destination.
Args:
mode (str): The desired FIU mode. Allowed values: Stowed, Alignment,
Acquisition, Observing, Calibration
KTL Keywords Used:
- `kpffiu.MODE`
Scripts Called:
- `kpf.calbench.ConfigureFIUOnce`
'''
@classmethod
def pre_condition(cls, args, logger, cfg):
keyword = ktl.cache('kpffiu', 'MODE')
allowed_values = list(keyword._getEnumerators())
if 'None' in allowed_values:
allowed_values.pop(allowed_values.index('None'))
check_input(args, 'mode', allowed_values=allowed_values)
return True
@classmethod
def perform(cls, args, logger, cfg):
dest = args.get('mode')
ntries = cfg.getint('retries', 'fiu_mode_tries', fallback=2)
shim_time = cfg.getfloat('times', 'fiu_mode_shim_time', fallback=2)
for i in range(ntries):
ok = WaitForConfigureFIUOnce.execute({'mode': dest})
if ok is False:
log.warning(f'FIU move failed on attempt {i+1} of {ntries}')
time.sleep(shim_time)
ConfigureFIUOnce.execute({'mode': dest, 'wait': True})
else:
break
@classmethod
def post_condition(cls, args, logger, cfg):
dest = args.get('mode')
kpffiu = ktl.cache('kpffiu')
modes = kpffiu['MODE'].read()
if dest.lower() not in modes.lower().split(','):
raise FailedToReachDestination(modes, dest)
else:
log.info(f"FIU mode is now {dest}")
@classmethod
def add_cmdline_args(cls, parser, cfg=None):
parser.add_argument('mode', type=str,
choices=['Stowed', 'Alignment', 'Acquisition',
'Observing', 'Calibration'],
help='Desired mode (see kpffiu.MODE)')
return super().add_cmdline_args(parser, cfg)