Skip to content

Instantly share code, notes, and snippets.

@bmechtley
Created April 29, 2022 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmechtley/5fb44c500d98b1644b5676c2daec13b5 to your computer and use it in GitHub Desktop.
Save bmechtley/5fb44c500d98b1644b5676c2daec13b5 to your computer and use it in GitHub Desktop.
set_z0 test using custom IDL set_z0 function
; Writes into the secondary mirror memory a vector of constant NCPA KL coefficents
;
; params:
;
; v = fltarr(672) vector of KL coefficents
; if a vector with less elements is passed, it will be padded with zeroes
;
; /ZERNIKE: if set, the coefficents are Zernikes and will be converted to KL
; before being written into the ASM memory.
; Zernikes are in canonical order [piston, tip, tilt, focus, astigmatism...]
; /MAXKL:
; /LUCI:
; /KL:
; /BANK: which bank to write to. Can be 1 ("A"), 2 ("B"), or 0 for both 1 and 2.
; Modification history:
;
; Created based on set_z0.pro by B. Mechtley on 2022-04-19
function bm_test_set_z0_bank, v, ZERNIKE=ZERNIKE, MAXKL=MAXKL, LUCI=LUCI, KL=KL, BANK=BANK
@adsec_common
n_slopes = rtr.n_slope
if not keyword_set(KL) then KL='KL_v16'
if not keyword_set(BANK) then BANK=0
if keyword_set(ZERNIKE) then begin
if not keyword_set(MAXKL) then MAXKL=50
; ao_status.m2c
v = z2m4adsec( KL, indgen(n_elements(v)-1), v[1:*], MAXKL, LUCI=keyword_set(LUCI))
endif
if n_elements(v) lt 672 then begin
v1 = v
v = fltarr(672)
v[0:n_elements(v1)-1] = v1
endif
for bcu=0,5 do begin
if (bank eq 0) or (bank eq 1) then err = write_seq(bcu*28, bcu*28+27, rtr_map.matrix_B0A+(n_slopes*4)-4, float(v[bcu*28*4 : bcu*28*4 + (28*4-1)]))
if (bank eq 0) or (bank eq 2) then err = write_seq(bcu*28, bcu*28+27, rtr_map.matrix_B0B+(n_slopes*4)-4, float(v[bcu*28*4 : bcu*28*4 + (28*4-1)]))
; print, "Bank ", bank, " bcu ", bcu
endfor
return, 1
end
#!/usr/bin/env python
'''
2022-04-18
run-ncpa.py
usage: run-ncpa.py [-h] [--delay delay] [--count count] [--bank bank] [--test]
Execute repeating set_z0 commands with varying delay.
optional arguments:
-h, --help show this help message and exit
--delay delay Delay time in seconds before issuing resume command.
--count count Number of times to repeat each sequence (default=1).
--bank bank Bank to write z0 values to (default=0).
--test Do not actually run AO commands.
'''
import time, argparse, socket, os
from datetime import datetime as dt
from AdOpt import thAOApp, asm
z0_values = [0, 0, 0, 10E-6, 10E-6]
idlctrl = 'idlctrl.L'
idlfunction = 'bm_test_set_z0_bank' # Function is named something unique to avoid conflict with existing IDL functions.
parser = argparse.ArgumentParser(description="Execute repeating set_z0 commands with varying delay.")
parser.add_argument('--delay', metavar='delay', type=float, default=1, help='Delay time in seconds before issuing resume command.')
parser.add_argument('--count', metavar='count', type=int, default=1, help='Number of times to repeat each sequence (default=1).')
parser.add_argument('--bank', metavar='bank', type=int, default=0, help='Bank to write z0 values to (default=0).')
parser.add_argument('--test', dest='test', action='store_true', default=False, help='Do not actually run AO commands.')
parser.set_defaults(test=False)
args = parser.parse_args()
if args.test: print('--test used. Will not execute commands.')
cmd = 'retval=%s([%s], KL="KL_v20", BANK=%d, /ZERNIKE, /LUCI)' % (idlfunction, ','.join([str(z0) for z0 in z0_values]), args.bank)
ao_app = thAOApp(myname='setz0banks', ip=socket.gethostbyname('localhost'))
idl_dir = os.path.join(os.path.realpath(os.getenv('ADOPT_ROOT')), 'idl')
script_dir = os.path.dirname(os.path.realpath(__file__))
print 'IDL directory: %s' % idl_dir
print 'Script directory: %s' % script_dir
# cd to the script directory, compile the modified set_z0 function, and cd back to the normal IDL directory.
ao_app.IDLCmd('cd, "%s"' % script_dir, idlctrl)
ao_app.IDLCmd('.COMPILE %s' % idlfunction, idlctrl)
ao_app.IDLCmd('cd, "%s"' % idl_dir, idlctrl)
# Run the command args.count times, sleeping for args.delay seconds in between iterations.
for i in range(args.count):
print('%s\tReptition: %d\tDelay: %.2f\t%s' % (dt.now(), i, args.delay, cmd))
if not args.test:
ao_app.IDLCmd(cmd, idlctrl)
time.sleep(args.delay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment