from GseosSequencer import TSequencer
from HostCommands import CMD

# Created: 2022-02-24 09:59:28 EST by APL
# Based on sim for flyby 66E42
# Modified: 2022-05-12 by Rick Redick for TM DITL rev A

# Macro IDs 0-19 are reserved for autonomy.  They can be overridden so
# do not define any macros with an ID less than 20 unless you know
# what you're doing!

# In general, macros should not include MISE_MAC_DELAY within them
# except after MISE_DET_OP or MISE_COOL_OP or if commands are being
# run inside MISE_MAC_LOOP_BEG/MISE_MAC_LOOP_END.  Each macro's
# execution time should be added as a delay in MISE_OBS_SEQUENCE.

# NOTE TO APL:  Rick reverted all MEM_STR_LOAD commands to *_1WORD.
# Generally, neither command is fully flight like since GSEOS always calculates byte count.
# *_1WORD is more human readable for values > 255.


def fDefineDITLMacros(oSeq):

	# Macro 2: Safing macro
	CMD('MISE_MAC_DEF', 2)
	CMD('MISE_OBS_ENB', 'Disable')
	CMD('MISE_DET_POWER', 'Off')
	CMD('MISE_COOL_POWER', 'Off')
	CMD('MISE_COOL_HEATER', 'Off')
	CMD('MISE_PARAM_MAXSCANRATE', 133509)  # Scanner max scan rate to 5.730 deg/s
	CMD('MISE_MEM_STR_READ', 1)  # Read out DPU Parameters
	CMD('MISE_SCAN_ANGLE', -2318518) 
	CMD('MISE_SCAN_MODE', 'Slew')
	CMD('MISE_MAC_DELAY', 55)
	CMD('MISE_SCAN_MODE', 'Off')
	CMD('MISE_SCAN_LOOP', 'CoarseOpen')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro   3: Overwrites default startup macro.
	CMD('MISE_MAC_DEF', 3)
	# NEED CONTENTS FOR MONITOR LIMIT UPDATES, MISE_MEM_STR_LOAD
	CMD('MISE_MAC_NEST', 200)							# Call the macro that disables unused temp sensor channels
	# Scanner Parameters
	CMD('MISE_PARAM_KP', 120)							# Set scanner PIV parameters - Kp, medium
	CMD('MISE_PARAM_KI', 20)							# Set scanner PIV parameters - Ki, medium
	CMD('MISE_PARAM_KV', 1400)							# Set scanner PIV parameters - Kv, medium
	CMD('MISE_PARAM_MAXSCAN', 5126372)  			# Scanner max position limit to +220.000 degrees
	CMD('MISE_PARAM_MINSCAN', -2686976)  			# Scanner min position limit to -115.313 degrees
	CMD('MISE_PARAM_MAXSCANRATE', 133509)  		# Scanner max scan rate to 5.730 deg/s
	CMD('MISE_PARAM_HBRIDGEPWM', 16)  				# Set scanner h-bridge PWM to 16
	CMD('MISE_PARAM_STALLERRORTHRESH', 34953) 	# Set Stall Error Thresh to 1.500 deg
	CMD('MISE_PARAM_STALLERRORCOUNTTHRESH', 999)	# Set Stall Error Count Thresh to 999 counts/s
	CMD('MISE_PARAM_STALLRESPONSEMACRO', 12)		# Set Stall Response Macro to macro 12
	CMD('MISE_PARAM_MAXSTALLMACRORESPONSES', 255)	# Set Max Stall Macro Responses to unlimited per DPU power cycle
	CMD('MISE_SCAN_LOOP', 'FineClosed')  			# Set scanner control loop mode to Fine Closed
	# CEU/Cryocooler Parms
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 0, 11574)  # Compressor frequency to 135 Hz
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 2, 4096)  # CEU integral gain for cryo operations
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 4, 41216)  # CEU proportional gain for cryo operations
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 6, 1340)  	# CEU peak drive voltage limit to 18.0 V (applies only in temp control mode)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 8, 1)  		# CEU drive voltage ramp rate (value = 0.8862 V/s)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 10, 447)  	# CEU test drive voltage limit to 6 V
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 13, 0)  	# CEU control temp sensor = Sensor 1
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 14, 65535) # Cryocooler max on time = forever
	# Cryocooler Operational Heater Parms
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 16, 1572)  # Set cryocooler heater temp thresh to 195K
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 18, 46)  # Set cryocooler heater temp hysteresis to 5K @ 195K
	# FPIE Parameters
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 81, 0)  # Set Conversion Phase Offset to 0
	# Other parameter updates?
	# Read out saved values
	CMD('MISE_MEM_STR_READ', 0)  # Read out DPU Monitor Limits
	CMD('MISE_MEM_STR_READ', 1)  # Read out DPU Parameters
	CMD('MISE_MEM_STR_READ', 2)  # Read out FPIE Register Parameters
	CMD('MISE_MAC_READ', 0, 255)  # Read out all macros
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro   8: Removed by Redick.  This macro is configuration dependent.
	
	# Macro  12: Scanner Obstruction Response Macro
	CMD('MISE_MAC_DEF', 12)
	CMD('MISE_OBS_ENB', 'Disable') # Turn off observation timeline
	# Halt all other macros except macro 12
	CMD('MISE_MAC_HALT', 0)
	CMD('MISE_MAC_HALT', 1)
	CMD('MISE_MAC_HALT', 2)
	CMD('MISE_MAC_HALT', 3)
	CMD('MISE_MAC_HALT', 4)
	CMD('MISE_MAC_HALT', 5)
	CMD('MISE_MAC_HALT', 6)
	CMD('MISE_MAC_HALT', 7)
	CMD('MISE_MAC_HALT', 8)
	CMD('MISE_MAC_HALT', 9)
	CMD('MISE_MAC_HALT', 10)
	CMD('MISE_MAC_HALT', 11)
	# Do not halt macro 12
	CMD('MISE_MAC_HALT', 13)
	CMD('MISE_MAC_HALT', 14)
	CMD('MISE_MAC_HALT', 15)
	CMD('MISE_MAC_HALT', 16)
	CMD('MISE_MAC_HALT', 17)
	CMD('MISE_MAC_HALT', 18)
	CMD('MISE_MAC_HALT', 19)
	CMD('MISE_MAC_HALT', 20)
	CMD('MISE_MAC_HALT', 21)
	CMD('MISE_MAC_HALT', 22)
	CMD('MISE_MAC_HALT', 23)
	CMD('MISE_MAC_HALT', 24)
	CMD('MISE_MAC_HALT', 25)
	CMD('MISE_MAC_HALT', 26)
	CMD('MISE_MAC_HALT', 27)
	CMD('MISE_MAC_HALT', 28)
	CMD('MISE_MAC_HALT', 29)
	CMD('MISE_MAC_HALT', 30)
	CMD('MISE_MAC_HALT', 31)
	CMD('MISE_MAC_HALT', 32)
	CMD('MISE_MAC_HALT', 33)
	CMD('MISE_MAC_HALT', 34)
	CMD('MISE_MAC_HALT', 35)
	CMD('MISE_MAC_HALT', 36)
	CMD('MISE_MAC_HALT', 37)
	CMD('MISE_MAC_HALT', 38)
	CMD('MISE_MAC_HALT', 39)
	CMD('MISE_MAC_HALT', 40)
	CMD('MISE_MAC_HALT', 41)
	CMD('MISE_MAC_HALT', 42)
	CMD('MISE_MAC_HALT', 43)
	CMD('MISE_MAC_HALT', 44)
	CMD('MISE_MAC_HALT', 45)
	CMD('MISE_MAC_HALT', 46)
	CMD('MISE_MAC_HALT', 47)
	CMD('MISE_MAC_HALT', 48)
	CMD('MISE_MAC_HALT', 49)
	CMD('MISE_MAC_HALT', 50)
	CMD('MISE_MAC_HALT', 51)
	CMD('MISE_MAC_HALT', 52)
	CMD('MISE_MAC_HALT', 53)
	CMD('MISE_MAC_HALT', 54)
	CMD('MISE_MAC_HALT', 55)
	CMD('MISE_MAC_HALT', 56)
	CMD('MISE_MAC_HALT', 57)
	CMD('MISE_MAC_HALT', 58)
	CMD('MISE_MAC_HALT', 59)
	CMD('MISE_MAC_HALT', 60)
	CMD('MISE_MAC_HALT', 61)
	CMD('MISE_MAC_HALT', 62)
	CMD('MISE_MAC_HALT', 63)
	CMD('MISE_MAC_HALT', 64)
	CMD('MISE_MAC_HALT', 65)
	CMD('MISE_MAC_HALT', 66)
	CMD('MISE_MAC_HALT', 67)
	CMD('MISE_MAC_HALT', 68)
	CMD('MISE_MAC_HALT', 69)
	CMD('MISE_MAC_HALT', 70)
	CMD('MISE_MAC_HALT', 71)
	CMD('MISE_MAC_HALT', 72)
	CMD('MISE_MAC_HALT', 73)
	CMD('MISE_MAC_HALT', 74)
	CMD('MISE_MAC_HALT', 75)
	CMD('MISE_MAC_HALT', 76)
	CMD('MISE_MAC_HALT', 77)
	CMD('MISE_MAC_HALT', 78)
	CMD('MISE_MAC_HALT', 79)
	CMD('MISE_MAC_HALT', 80)
	CMD('MISE_MAC_HALT', 81)
	CMD('MISE_MAC_HALT', 82)
	CMD('MISE_MAC_HALT', 83)
	CMD('MISE_MAC_HALT', 84)
	CMD('MISE_MAC_HALT', 85)
	CMD('MISE_MAC_HALT', 86)
	CMD('MISE_MAC_HALT', 87)
	CMD('MISE_MAC_HALT', 88)
	CMD('MISE_MAC_HALT', 89)
	CMD('MISE_MAC_HALT', 90)
	CMD('MISE_MAC_HALT', 91)
	CMD('MISE_MAC_HALT', 92)
	CMD('MISE_MAC_HALT', 93)
	CMD('MISE_MAC_HALT', 94)
	CMD('MISE_MAC_HALT', 95)
	CMD('MISE_MAC_HALT', 96)
	CMD('MISE_MAC_HALT', 97)
	CMD('MISE_MAC_HALT', 98)
	CMD('MISE_MAC_HALT', 99)
	CMD('MISE_MAC_HALT', 100)
	CMD('MISE_MAC_HALT', 101)
	CMD('MISE_MAC_HALT', 102)
	CMD('MISE_MAC_HALT', 103)
	CMD('MISE_MAC_HALT', 104)
	CMD('MISE_MAC_HALT', 105)
	CMD('MISE_MAC_HALT', 106)
	CMD('MISE_MAC_HALT', 107)
	CMD('MISE_MAC_HALT', 108)
	CMD('MISE_MAC_HALT', 109)
	CMD('MISE_MAC_HALT', 110)
	CMD('MISE_MAC_HALT', 111)
	CMD('MISE_MAC_HALT', 112)
	CMD('MISE_MAC_HALT', 113)
	CMD('MISE_MAC_HALT', 114)
	CMD('MISE_MAC_HALT', 115)
	CMD('MISE_MAC_HALT', 116)
	CMD('MISE_MAC_HALT', 117)
	CMD('MISE_MAC_HALT', 118)
	CMD('MISE_MAC_HALT', 119)
	CMD('MISE_MAC_HALT', 120)
	CMD('MISE_MAC_HALT', 121)
	CMD('MISE_MAC_HALT', 122)
	CMD('MISE_MAC_HALT', 123)
	CMD('MISE_MAC_HALT', 124)
	CMD('MISE_MAC_HALT', 125)
	CMD('MISE_MAC_HALT', 126)
	CMD('MISE_MAC_HALT', 127)
	CMD('MISE_MAC_HALT', 128)
	CMD('MISE_MAC_HALT', 129)
	CMD('MISE_MAC_HALT', 130)
	CMD('MISE_MAC_HALT', 131)
	CMD('MISE_MAC_HALT', 132)
	CMD('MISE_MAC_HALT', 133)
	CMD('MISE_MAC_HALT', 134)
	CMD('MISE_MAC_HALT', 135)
	CMD('MISE_MAC_HALT', 136)
	CMD('MISE_MAC_HALT', 137)
	CMD('MISE_MAC_HALT', 138)
	CMD('MISE_MAC_HALT', 139)
	CMD('MISE_MAC_HALT', 140)
	CMD('MISE_MAC_HALT', 141)
	CMD('MISE_MAC_HALT', 142)
	CMD('MISE_MAC_HALT', 143)
	CMD('MISE_MAC_HALT', 144)
	CMD('MISE_MAC_HALT', 145)
	CMD('MISE_MAC_HALT', 146)
	CMD('MISE_MAC_HALT', 147)
	CMD('MISE_MAC_HALT', 148)
	CMD('MISE_MAC_HALT', 149)
	CMD('MISE_MAC_HALT', 150)
	CMD('MISE_MAC_HALT', 151)
	CMD('MISE_MAC_HALT', 152)
	CMD('MISE_MAC_HALT', 153)
	CMD('MISE_MAC_HALT', 154)
	CMD('MISE_MAC_HALT', 155)
	CMD('MISE_MAC_HALT', 156)
	CMD('MISE_MAC_HALT', 157)
	CMD('MISE_MAC_HALT', 158)
	CMD('MISE_MAC_HALT', 159)
	CMD('MISE_MAC_HALT', 160)
	CMD('MISE_MAC_HALT', 161)
	CMD('MISE_MAC_HALT', 162)
	CMD('MISE_MAC_HALT', 163)
	CMD('MISE_MAC_HALT', 164)
	CMD('MISE_MAC_HALT', 165)
	CMD('MISE_MAC_HALT', 166)
	CMD('MISE_MAC_HALT', 167)
	CMD('MISE_MAC_HALT', 168)
	CMD('MISE_MAC_HALT', 169)
	CMD('MISE_MAC_HALT', 170)
	CMD('MISE_MAC_HALT', 171)
	CMD('MISE_MAC_HALT', 172)
	CMD('MISE_MAC_HALT', 173)
	CMD('MISE_MAC_HALT', 174)
	CMD('MISE_MAC_HALT', 175)
	CMD('MISE_MAC_HALT', 176)
	CMD('MISE_MAC_HALT', 177)
	CMD('MISE_MAC_HALT', 178)
	CMD('MISE_MAC_HALT', 179)
	CMD('MISE_MAC_HALT', 180)
	CMD('MISE_MAC_HALT', 181)
	CMD('MISE_MAC_HALT', 182)
	CMD('MISE_MAC_HALT', 183)
	CMD('MISE_MAC_HALT', 184)
	CMD('MISE_MAC_HALT', 185)
	CMD('MISE_MAC_HALT', 186)
	CMD('MISE_MAC_HALT', 187)
	CMD('MISE_MAC_HALT', 188)
	CMD('MISE_MAC_HALT', 189)
	CMD('MISE_MAC_HALT', 190)
	CMD('MISE_MAC_HALT', 191)
	CMD('MISE_MAC_HALT', 192)
	CMD('MISE_MAC_HALT', 193)
	CMD('MISE_MAC_HALT', 194)
	CMD('MISE_MAC_HALT', 195)
	CMD('MISE_MAC_HALT', 196)
	CMD('MISE_MAC_HALT', 197)
	CMD('MISE_MAC_HALT', 198)
	CMD('MISE_MAC_HALT', 199)
	CMD('MISE_MAC_HALT', 200)
	CMD('MISE_MAC_HALT', 201)
	CMD('MISE_MAC_HALT', 202)
	CMD('MISE_MAC_HALT', 203)
	CMD('MISE_MAC_HALT', 204)
	CMD('MISE_MAC_HALT', 205)
	CMD('MISE_MAC_HALT', 206)
	CMD('MISE_MAC_HALT', 207)
	CMD('MISE_MAC_HALT', 208)
	CMD('MISE_MAC_HALT', 209)
	CMD('MISE_MAC_HALT', 210)
	CMD('MISE_MAC_HALT', 211)
	CMD('MISE_MAC_HALT', 212)
	CMD('MISE_MAC_HALT', 213)
	CMD('MISE_MAC_HALT', 214)
	CMD('MISE_MAC_HALT', 215)
	CMD('MISE_MAC_HALT', 216)
	CMD('MISE_MAC_HALT', 217)
	CMD('MISE_MAC_HALT', 218)
	CMD('MISE_MAC_HALT', 219)
	CMD('MISE_MAC_HALT', 220)
	CMD('MISE_MAC_HALT', 221)
	CMD('MISE_MAC_HALT', 222)
	CMD('MISE_MAC_HALT', 223)
	CMD('MISE_MAC_HALT', 224)
	CMD('MISE_MAC_HALT', 225)
	CMD('MISE_MAC_HALT', 226)
	CMD('MISE_MAC_HALT', 227)
	CMD('MISE_MAC_HALT', 228)
	CMD('MISE_MAC_HALT', 229)
	CMD('MISE_MAC_HALT', 230)
	CMD('MISE_MAC_HALT', 231)
	CMD('MISE_MAC_HALT', 232)
	CMD('MISE_MAC_HALT', 233)
	CMD('MISE_MAC_HALT', 234)
	CMD('MISE_MAC_HALT', 235)
	CMD('MISE_MAC_HALT', 236)
	CMD('MISE_MAC_HALT', 237)
	CMD('MISE_MAC_HALT', 238)
	CMD('MISE_MAC_HALT', 239)
	CMD('MISE_MAC_HALT', 240)
	CMD('MISE_MAC_HALT', 241)
	CMD('MISE_MAC_HALT', 242)
	CMD('MISE_MAC_HALT', 243)
	CMD('MISE_MAC_HALT', 244)
	CMD('MISE_MAC_HALT', 245)
	CMD('MISE_MAC_HALT', 246)
	CMD('MISE_MAC_HALT', 247)
	CMD('MISE_MAC_HALT', 248)
	CMD('MISE_MAC_HALT', 249)
	CMD('MISE_MAC_HALT', 250)
	CMD('MISE_MAC_HALT', 251)
	CMD('MISE_MAC_HALT', 252)
	CMD('MISE_MAC_HALT', 253)
	CMD('MISE_MAC_HALT', 254)
	CMD('MISE_MAC_HALT', 255)
	CMD('MISE_SCAN_MODE', 'Off') # Set ScanMode to OFF
	CMD('MISE_PARAM_MAXSCANRATE', 133509)  # Scanner max scan rate to 5.730 deg/s
	CMD('MISE_SCAN_LOOP', 'CoarseOpen') # Set LoopMode to CoarseOpen
	CMD('MISE_PARAM_HBRIDGEPWM', 63) # Set PWM to half the maximum value (11 in-oz)
	CMD('MISE_MEM_STR_READ', 1)  # Read out DPU Parameters
	CMD('MISE_MAC_DELAY', 1) # JRH: added; allow time for SCAN_MODE and SCAN_LOOP
	CMD('MISE_SCAN_MODE', 'Hold') # SW v3 Hold mode supports offsets
	CMD('MISE_SCAN_OFF_MODE', 'Enable')
	CMD('MISE_SCAN_OFF_RATE', -133509)
	CMD('MISE_MAC_DELAY', 5)
	CMD('MISE_MAC_LOOP_BEGIN', 5)
	CMD('MISE_SCAN_OFF_RATE', 133509)
	CMD('MISE_MAC_DELAY', 10)
	CMD('MISE_SCAN_OFF_RATE', -133509)
	CMD('MISE_MAC_DELAY', 10)
	CMD('MISE_MAC_LOOP_END')
	CMD('MISE_SCAN_OFF_ANGLE', 0)
	CMD('MISE_SCAN_OFF_RATE', 0)
	CMD('MISE_MAC_DELAY', 10)
	CMD('MISE_SCAN_OFF_MODE', 'Disable')
	CMD('MISE_SCAN_MODE', 'Off') # Set ScanMode to OFF
	CMD('MISE_SCAN_LOOP', 'FineClosed') # Set LoopMode to FineClosed
	CMD('MISE_OBS_ENB', 'Enable') # Enable observation timeline
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  20: Scan mode off
	CMD('MISE_MAC_DEF', 20)
	CMD('MISE_SCAN_MODE', 'Off')
	CMD('MISE_SCAN_DIAG','Disable')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  21: hold at fixed position
	CMD('MISE_MAC_DEF', 21)
	CMD('MISE_SCAN_DIAG','Enable')
	CMD('MISE_SCAN_MODE', 'Hold')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  22: slew mode
	CMD('MISE_MAC_DEF', 22)
	CMD('MISE_SCAN_DIAG','Enable')
	CMD('MISE_SCAN_MODE', 'Slew')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  23: profile mode.  Medium PIV parameters from P17868_MISEMacroDefinitions_DITL.
	# See macros 53 and 54 for other PIV parameters.
	CMD('MISE_MAC_DEF', 23)
	CMD('MISE_SCAN_DIAG','Enable')
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 42, 120)  # Kp
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 44, 20)  # Ki
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 46, 1400)  # Kd (aka Kv)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 56, 120)  # Fallback Kp to slow
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 58, 5)  # Fallback Ki to slow
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 60, 600)  # Fallback Kd (aka Kv) to slow
	CMD('MISE_MEM_STR_READ', 1)                  # Read out DPU Parameters
	CMD('MISE_SCAN_MODE', 'Profile')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  24: home
	CMD('MISE_MAC_DEF', 24)
	CMD('MISE_SCAN_MODE', 'Home')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  25: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 25)
	CMD('MISE_NVSTORE_CUBE_SET', 1)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  26: Capture 6000 frames.
	# Execution time (s): 356
	CMD('MISE_MAC_DEF', 26)
	CMD('MISE_NVSTORE_CUBE_SET', 2)
	CMD('MISE_FRAME_CAPTURE', 6000)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  27: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 27)
	CMD('MISE_NVSTORE_CUBE_SET', 3)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  28: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 28)
	CMD('MISE_NVSTORE_CUBE_SET', 4)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  29: Capture 6000 frames.
	# Execution time (s): 356
	CMD('MISE_MAC_DEF', 29)
	CMD('MISE_NVSTORE_CUBE_SET', 5)
	CMD('MISE_FRAME_CAPTURE', 6000)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  30: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 30)
	CMD('MISE_NVSTORE_CUBE_SET', 6)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  31: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 31)
	CMD('MISE_NVSTORE_CUBE_SET', 7)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  32: Capture 6000 frames.
	# Execution time (s): 356
	CMD('MISE_MAC_DEF', 32)
	CMD('MISE_NVSTORE_CUBE_SET', 8)
	CMD('MISE_FRAME_CAPTURE', 6000)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  33: Capture 486 frames.
	# Execution time (s): 34
	CMD('MISE_MAC_DEF', 33)
	CMD('MISE_NVSTORE_CUBE_SET', 9)
	CMD('MISE_FRAME_CAPTURE', 486)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  34: Capture 509 frames.
	# Execution time (s): 34
	CMD('MISE_MAC_DEF', 34)
	CMD('MISE_NVSTORE_CUBE_SET', 10)
	CMD('MISE_FRAME_CAPTURE', 509)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  35: Capture 486 frames.
	# Execution time (s): 34
	CMD('MISE_MAC_DEF', 35)
	CMD('MISE_NVSTORE_CUBE_SET', 11)
	CMD('MISE_FRAME_CAPTURE', 486)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  36: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 36)
	CMD('MISE_NVSTORE_CUBE_SET', 12)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  37: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 37)
	CMD('MISE_NVSTORE_CUBE_SET', 13)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  38: Capture 6000 frames.
	# Execution time (s): 356
	CMD('MISE_MAC_DEF', 38)
	CMD('MISE_NVSTORE_CUBE_SET', 14)
	CMD('MISE_FRAME_CAPTURE', 6000)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  39: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 39)
	CMD('MISE_NVSTORE_CUBE_SET', 15)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  40: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 40)
	CMD('MISE_NVSTORE_CUBE_SET', 16)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  41: Capture 6000 frames.
	# Execution time (s): 356
	CMD('MISE_MAC_DEF', 41)
	CMD('MISE_NVSTORE_CUBE_SET', 17)
	CMD('MISE_FRAME_CAPTURE', 6000)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  42: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 42)
	CMD('MISE_NVSTORE_CUBE_SET', 18)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  43: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 43)
	CMD('MISE_NVSTORE_CUBE_SET', 19)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  44: Capture 6000 frames.
	# Execution time (s): 356
	CMD('MISE_MAC_DEF', 44)
	CMD('MISE_NVSTORE_CUBE_SET', 20)
	CMD('MISE_FRAME_CAPTURE', 6000)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  45: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 45)
	CMD('MISE_NVSTORE_CUBE_SET', 21)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  46: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 46)
	CMD('MISE_NVSTORE_CUBE_SET', 22)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  47: Capture 6000 frames.
	# Execution time (s): 356
	CMD('MISE_MAC_DEF', 47)
	CMD('MISE_NVSTORE_CUBE_SET', 23)
	CMD('MISE_FRAME_CAPTURE', 6000)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  48: Capture 320 frames.
	# Execution time (s): 19
	CMD('MISE_MAC_DEF', 48)
	CMD('MISE_NVSTORE_CUBE_SET', 24)
	CMD('MISE_FRAME_CAPTURE', 320)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  50: Slew to -99.5 degrees.
	CMD('MISE_MAC_DEF', 50)
	CMD('MISE_SCAN_DIAG','Enable')
	CMD('MISE_SCAN_ANGLE', -2318517)
	CMD('MISE_SCAN_MODE', 'Slew')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  51: Slew to -20.0 degrees.
	CMD('MISE_MAC_DEF', 51)
	CMD('MISE_SCAN_DIAG','Enable')
	CMD('MISE_SCAN_ANGLE', -466033)
	CMD('MISE_SCAN_MODE', 'Slew')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  52: Slew to -46.242 degrees darkest dark position)
	CMD('MISE_MAC_DEF', 52)
	CMD('MISE_SCAN_DIAG','Enable')
	CMD('MISE_SCAN_ANGLE', -1077517)
	CMD('MISE_SCAN_MODE', 'Slew')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  53: profile mode.  Fast PIV parameters
	CMD('MISE_MAC_DEF', 53)
	CMD('MISE_SCAN_DIAG','Enable')
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 42, 260)  # Kp
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 44, 50)  # Ki
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 46, 1700)  # Kd (aka Kv)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 56, 120)  # Fallback Kp to medium
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 58, 20)  # Fallback Ki to medium
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 60, 1400)  # Fallback Kd (aka Kv) to medium
	CMD('MISE_MEM_STR_READ', 1)                  # Read out DPU Parameters
	CMD('MISE_SCAN_MODE', 'Profile')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  54: profile mode.  Slow PIV parameters
	CMD('MISE_MAC_DEF', 54)
	CMD('MISE_SCAN_DIAG','Enable')
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 42, 120)  # Kp
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 44, 5)  # Ki
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 46, 600)  # Kd (aka Kv)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 56, 30)  # Fallback Kp to (extra slow?)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 58, 1)  # Fallback Ki to (extra slow?)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 60, 800)  # Fallback Kd (aka Kv) to (extra slow?)
	CMD('MISE_MEM_STR_READ', 1)                  # Read out DPU Parameters
	CMD('MISE_SCAN_MODE', 'Profile')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  60: Configure FPIE Registers for Science / FPA Frame Data at 53.5 ms integration
	CMD('MISE_MAC_DEF', 60)
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 0x0e, 0x01)
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 0x19, 0x0f)
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 0x1a, 0x00)
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 0x1f, 0xd7)
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 0x20, 0x01)
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 0x22, 0x08)
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 0x34, 0x0e)
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 0x3c, 0xfb)
	CMD('MISE_MEM_STR_LOAD_1BYTE', 2, 0x51, 0x00)  # Set Conversion Phase Offset to 0
	CMD('MISE_MEM_STR_READ', 2)  # Read out FPIE Register Parameters
	CMD('MISE_MAC_ENDDEF')

	# Macro  61: Disable autonomy.
	# Redick updated this for the all configurations with the RCM.
	CMD('MISE_MAC_DEF', 61)
	CMD('MISE_COOL_HEATER', 'Off')
	CMD('MISE_PARAM_IFCTEMPENABLES', 36587)
	CMD('MISE_SAF_AUTONOMY', 'Set',  1)
	CMD('MISE_MEM_STR_READ', 1)                  # Read out DPU Parameters
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  62: Power on focal plane.
# Execution time (s): 9
	# Note:
	#	0x607e0000=1618870272
	#	0x607c0000=1618739200
	#	0x607a0000=1618608128
	CMD('MISE_MAC_DEF', 62)
	CMD('MISE_DET_POWER', 'On')
	CMD('MISE_MAC_DELAY', 1)
	CMD('MISE_FPMEM_GO', 1618870272)
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_FPMEM_GO', 1618739200)
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_FPMEM_GO', 1618608128)
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_FPMEM_STR_READ', 0)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  63: Power FPA and reset
	CMD('MISE_MAC_DEF', 63)
	CMD('MISE_DET_OP', 'InitFPA')
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_DET_OP', 'ConfigDet')
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_DET_OP', 'RegDump')
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  64: Enable autonomy.  Nests macro 200
	# Redick updated the PRT enables to call the config-specific macro
	CMD('MISE_MAC_DEF', 64)
	CMD('MISE_SAF_AUTONOMY', 'Clear',  1)
	CMD('MISE_MAC_NEST', 200)  # PRT enables
	CMD('MISE_COOL_HEATER', 'Software')
	# Heater setpoints are configured in the startup macro.
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  65: Verify detector
	CMD('MISE_MAC_DEF', 65)
	CMD('MISE_DET_OP', 'RegDump')
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  66: From P17868_setup.  Power on focal plane memory card only.
# Execution time (s): 9
	# Note:
	#	0x607e0000=1618870272
	#	0x607c0000=1618739200
	#	0x607a0000=1618608128
	CMD('MISE_MAC_DEF', 66)
	CMD('MISE_DET_POWER', 'FPMCOnly')
	CMD('MISE_MAC_DELAY', 1)
	CMD('MISE_FPMEM_GO', 1618870272)
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_FPMEM_GO', 1618739200)
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_FPMEM_GO', 1618608128)
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_FPMEM_STR_READ', 0)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro 67:  Nominal Cooldown - FM with RCM TVAC ONLY
	CMD('MISE_MAC_DEF', 67)
	# Set CEU/Cryocooler Parms
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 0, 11574)  # Compressor frequency to 135 Hz
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 2, 4096)   # CEU integral gain for cryo operations
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 4, 41216)  # CEU proportional gain for cryo operations
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 6, 1340)   # CEU peak drive voltage limit to 18.0 V (applies only in temp control mode)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 8, 1)      # CEU drive voltage ramp rate (value = 0.8862 V/s)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 10, 447)   # CEU test drive voltage limit to 6 V
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 13, 0)     # CEU control temp sensor = Sensor 1
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 14, 65535) # Cryocooler max on time = forever
	CMD('MISE_COOL_POWER', 'On') 				 # Apply power to the CEU; boot the CEU
	CMD('MISE_MAC_DELAY', 10)  # Rick changed this to 10s from 40s
	CMD('MISE_COOL_OP', 'RegDump')	# Dump CEU registers
	CMD('MISE_SAF_AUTONOMY', 'Set', 2)  # s/c cryocooler temp FP enable
	CMD('MISE_COOL_TEMP', 958)  	# This sets the target temperature to 84.0 K (Max-AFT case), assuming Sensor 1 is the control sensor.
	CMD('MISE_COOL_OP', 'Cool')  	# This starts temperature-controlled cooldown
	CMD('MISE_MAC_DELAY', 10) 
	CMD('MISE_COOL_OP', 'RegDump')	# Dump CEU registers
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  68: From P17868_setup.  Power off cryocooler and heater; s/c FP
	CMD('MISE_MAC_DEF', 68)
#	CMD('MISE_COOL_POWER', 'Off') # Commenting out for TVAC2
	CMD('MISE_MAC_DELAY', 5)
	CMD('MISE_SAF_AUTONOMY', 'Clear',  2)
#	CMD('MISE_COOL_HEATER', 'Off') # Commenting out for TVAC2
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  70: From P17868_setup.  Flyby restore commands
	CMD('MISE_MAC_DEF', 70)
	CMD('MISE_SCAN_PRO_RESTORE')
	CMD('MISE_OBS_RESTORE')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro 71:  Cryocooler Heater Enable
	CMD('MISE_MAC_DEF', 71)
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 16, 1572)  # Set cryocooler heater temp thresh to 195K
	CMD('MISE_MEM_STR_LOAD_1WORD', 1, 18, 46)  # Set cryocooler heater temp hysteresis to 5K @ 195K
	CMD('MISE_COOL_HEATER', 'Software')  # Power on heater when cryocooler is in cooling mode
	CMD('MISE_MEM_STR_READ', 1)                  # Read out DPU Parameters
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  73: From P17868_setup.  Cryocooler and CEU shutdown
	CMD('MISE_MAC_DEF', 73)
	CMD('MISE_COOL_POWER', 'Off')
	CMD('MISE_MAC_DELAY', 5)
	CMD('MISE_SAF_AUTONOMY', 'Clear',  2)
	CMD('MISE_COOL_HEATER', 'Off')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  76: From P17868_setup.  Read bad block maps.
# Execution time (s): 64
	# Note:
	#	0x60000000=1610612736
	#	0x60001000=1610616832
	CMD('MISE_MAC_DEF', 76)
	CMD('MISE_FPMEM_READ', 1610612736, 4096)
	CMD('MISE_MAC_DELAY', 30)
	CMD('MISE_FPMEM_READ', 1610616832, 4096)
	CMD('MISE_MAC_DELAY', 30)
	CMD('MISE_FPMEM_CHECK', 1610612736, 4096)
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_FPMEM_CHECK', 1610616832, 4096)
	CMD('MISE_MAC_DELAY', 2)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro 77:  Set Bad Blocks
	# Not doing this in TVAC2
	# In order to keep a standard macro sequence, we may want to define this
	CMD('MISE_MAC_DEF', 77)
	CMD('MISE_CMD_NULL')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)

	# Macro  78: From P17868_setup.  Clear the cube storage and turn off detector.
	CMD('MISE_MAC_DEF', 78)
	CMD('MISE_NVSTORE_DELETE')
	CMD('MISE_MAC_DELAY', 90)
	CMD('MISE_DET_POWER', 'Off')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  79: From P17868_setup.  Save observations and scan profiles.
	CMD('MISE_MAC_DEF', 79)
	CMD('MISE_MAC_SAVE')
	CMD('MISE_SCAN_PRO_SAVE')
	CMD('MISE_OBS_SAVE')
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  80: From P17868_MISEMacroDefinitions_DITL.  Power off FPMC, FPIE, and FPA.
	CMD('MISE_MAC_DEF', 80)
	CMD('MISE_DET_POWER', 'Off')
	CMD('MISE_MAC_DELAY', 5)
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	
	# Macro  200: Full Instrument / Flight Config
	CMD('MISE_MAC_DEF', 200)
	#CMD('MISE_MEM_STR_LOAD', 1, 2, 84, 0x8EEB) # Disable Non-Connected PRTs
	CMD('MISE_PARAM_IFCTEMPENABLES', 36587) # Disable Non-Connected PRTs
	CMD('MISE_MAC_ENDDEF')
	oSeq.Sleep(1)
	

TSequencer('Define MISE DITL Macros', fDefineDITLMacros)