! EncZoomWMTest.scr ! Wand Move Calibration Test ! Measures wand move repeatability. ! Simulates wand zoom up and zoom down button presses. ! Each simulated wand button press has a random duration within a limited range. ! Measures interferogram to assess accuracy/repeatability of magnifications. ! Length of test is controlled by the Wand Move Test Iterations custom control. ! ! Set up a plano cavity. ! Set a circular acquisition mask to be just inside fringe pattern boundary at zoom lower limit. ! Perform lateral calibration. ! Adjust tilt for lots of fringes - at zoom lower limit the PV should measure about 150 fringes. ! ----------------------------------------------------------------------------------------------- loadsub "EncZoomGlob.scr" loadsub "EncZoomSdoGlob.scr" ! ----------------------------------------------------------------------------------------------- gosub GET_QUIET_FLAG ! Sets var quietFlag% ! ----------------------------------------------------------------------------------------------- gosub CLR_STATUS_MSG_ALL gosub SET_SCRIPT_STATUS_FAIL ! ----------------------------------------------------------------------------------------------- if quietFlag% = 0 then msg$ = "" msg$ = msg$ & " Wand Move Test \n\n" msg$ = msg$ & " This will test the calibration of wand moves. \n\n" msg$ = msg$ & " Requires the following: \n" msg$ = msg$ & " Plano interference cavity \n" msg$ = msg$ & " Tilt between " & val$(CalMinTiltPv) & " and " & val$(CalMaxTiltPv) & " fringes at lowest zoom mag \n\n" msg$ = msg$ & " The following controls must be set: \n" msg$ = msg$ & " Apert Diam \n" msg$ = msg$ & " Wand Move Test Iterations (recommended >= 100) \n\n" msg$ = msg$ & " If this is an MST app, the 2S Cav Length Scan control must be Off. \n\n" msg$ = msg$ & " This will take about 15 to 25 minutes per 100 iterations. \n\n" msg$ = msg$ & " Do you want to continue? " msgtype% = 6 gosub SHOW_DIALOG ! Uses vars msg$ and msgtype%, sets var ok% if ok% = 0 then stop endif endif ! ----------------------------------------------------------------------------------------------- msg$ = "Wand Move Test" gosub SET_STATUS_MSG_1 gosub LOG_DATE_TIME_MSG ! ----------------------------------------------------------------------------------------------- gosub GET_APERT_DIAM ! Gets control value into var ApertDiam in millimeters if ApertDiam <= 0 then msg$ = " The Apert Diam control value must be >= 0 " gosub SHOW_ERROR_DIALOG stop endif ! ----------------------------------------------------------------------------------------------- gosub GET_WAND_MOVE_TEST_ITERATIONS ! Gets control value into var TestIterations% if TestIterations% <= 0 then msg$ = " The Wand Move Test Iterations control value must be >= 1 " gosub SHOW_ERROR_DIALOG stop endif ! ----------------------------------------------------------------------------------------------- ! If this is an MST app, verify that the 2S Cav Length Scan control is Off. gosub VERIFY_MST_2S_CAV_LEN_SCAN_OFF ! ----------------------------------------------------------------------------------------------- ! Get lower and upper wand limit internal cal values gosub SDO_GET_LOWER_SOFT_LIMIT ! Sets var LowerSoftLimit% gosub SDO_GET_UPPER_SOFT_LIMIT ! Sets var UpperSoftLimit% LowerWandLimit = LowerSoftLimit% UpperWandLimit = UpperSoftLimit% if LowerWandLimit >= UpperWandLimit then msg$ = " Incorrect Lower Wand Limit and/or Upper Wand Limit internal cal values. " gosub SHOW_ERROR_DIALOG stop endif ! ----------------------------------------------------------------------------------------------- ! Get prog limit values LowerProgLimit = getgpizoommin(0) UpperProgLimit = getgpizoommax(0) ! ----------------------------------------------------------------------------------------------- SettlingTimeWait = 1.0 ! seconds ! ----------------------------------------------------------------------------------------------- dim OutputFn$[999] OutputFn$ = DataFolder$ & "\\" & "WandMoveTest.csv" if WarnBeforeOverwritingFiles% = 1 then fn$ = OutputFn$ gosub DOES_FILE_EXIST ! Uses var fn$, sets var fileExists% if fileExists% <> 0 then msg$ = " Overwrite file " & fn$ & " ? " on error goto DIALOG_ESCAPED ok% = dialog(msg$, 6) off error if ok% = 0 then stop endif endif endif ! ----------------------------------------------------------------------------------------------- assign @OutputFp to OutputFn$ "w" line$ = "Wand Move Calibration Test" output @OutputFp; line$ line$ = "" output @OutputFp; line$ ofmtr("%.0f") line$ = "Lower Wand Limit = " & val$(LowerWandLimit) output @OutputFp; line$ line$ = "Upper Wand Limit = " & val$(UpperWandLimit) output @OutputFp; line$ line$ = "Lower Prog Limit = " & val$(LowerProgLimit) output @OutputFp; line$ line$ = "Upper Prog Limit = " & val$(UpperProgLimit) output @OutputFp; line$ line$ = "" output @OutputFp; line$ ! ----------------------------------------------------------------------------------------------- ! Delete any masks, and if this is an MST app, make a cal marker gosub DELETE_MASKS_AND_MAKE_CAL_MARKER_FOR_MST ! ----------------------------------------------------------------------------------------------- msg$ = "Moving to lower wand limit" gosub SET_STATUS_MSG_2 TargPos = LowerWandLimit gosub MOVE_AND_CHECK_POS_ERROR ! Uses vars TargPos and PosErrorTol, sets vars CurPos and PosError ! ----------------------------------------------------------------------------------------------- VALIDATE_CAVITY_SETUP: msg$ = "Measuring to validate cavity setup" gosub SET_STATUS_MSG_2 gosub MEASURE_WITH_RETRY gosub CLR_STATUS_MSG_2 gosub GET_DATA_PV_TR ! Gets result value into var DataPv (in fringes) if (DataPv < CalMinTiltPv) or (DataPv > CalMaxTiltPv) then msg$ = " Adjust tilt to obtain PV between " ofmtr("%.0f") msg$ = msg$ & val$(CalMinTiltPv) & " and " & val$(CalMaxTiltPv) msg$ = msg$ & " fringes at lowest zoom mag. \n" msg$ = msg$ & " Click YES to retry or NO to stop. \n" msgtype% = 5 gosub SHOW_DIALOG ! Uses vars msg$ and msgtype%, sets var ok% if ok% = 1 then goto VALIDATE_CAVITY_SETUP else stop endif endif ! ----------------------------------------------------------------------------------------------- ! Set camera resolution gosub GET_DATA_OUTER_DIAM ! Gets result value into var DataOuterDiam in pixels GenCamRes = ApertDiam / DataOuterDiam setcamres(GenCamRes, "mm") ! ----------------------------------------------------------------------------------------------- ! Get starting zoom pos and mag gosub GET_CUR_POS_AVG ! Sets var CurPos ZoomPos = CurPos gosub GET_DATA_ZOOM_MAG ! Geta attribute value into var DataZoomMag ZoomMag = DataZoomMag ! ----------------------------------------------------------------------------------------------- ! Set circular acquisition mask to fit data runscript(0, "EncZoomSetMask.scr") gosub VERIFY_SCRIPT_STATUS_PASS gosub SET_SCRIPT_STATUS_FAIL ! ----------------------------------------------------------------------------------------------- ! Column Headings ! Column values will come from these vars: ! MoveIndex%, Date$, Time%, ElapsedTime, ! DeltaZoomPos, ZoomPos, DeltaZoomMag, ZoomMag, ! TiltMag, DataPv, ScaledPv line$ = "" line$ = line$ & "Move Index" line$ = line$ & ", Date" line$ = line$ & ", Time" line$ = line$ & ", ET (sec)" line$ = line$ & ", Delta Zoom Pos" line$ = line$ & ", Zoom Pos" line$ = line$ & ", Delta Zoom Mag" line$ = line$ & ", Zoom Mag" line$ = line$ & ", Tilt Mag (urad)" line$ = line$ & ", PV (fr)" line$ = line$ & ", Scaled PV (fr)" output @OutputFp; line$ ! ----------------------------------------------------------------------------------------------- MeasureCount% = 0 TiltMagSum = 0 TiltMagMax = -99999 TiltMagMin = 99999 ScaledPvSum = 0 ScaledPvMax = -99999 ScaledPvMin = 99999 ! ----------------------------------------------------------------------------------------------- ! Set controls to support fitting a zernike plane to current data, then generating that plane gosub SET_ZERNIKE_PLANE_CONTROLS ! Uses var GenCamRes ! ----------------------------------------------------------------------------------------------- StartTime = timedate MoveIndex% = 0 NumMovesBelowLowerProgLimit% = 0 NumMovesAboveUpperProgLimit% = 0 ! ----------------------------------------------------------------------------------------------- !gosub LIMIT_MOVE_TEST ! ----------------------------------------------------------------------------------------------- gosub RANDOM_MOVE_TEST ! ----------------------------------------------------------------------------------------------- line$ = "" output @OutputFp; line$ ofmti("%d") line$ = "Number of wand moves = " & val$(MoveIndex%) output @OutputFp; line$ line$ = "Number of moves below Lower Prog Limit = " & val$(NumMovesBelowLowerProgLimit%) output @OutputFp; line$ line$ = "Number of moves above Upper Prog Limit = " & val$(NumMovesAboveUpperProgLimit%) output @OutputFp; line$ ! ----------------------------------------------------------------------------------------------- if MeasureCount% = 0 then line$ = "MeasureCount% = 0, cannot calculate stats" output @OutputFp; line$ assign @OutputFp to "" msg$ = "MeasureCount% = 0" gosub LOG_DATE_TIME_MSG msg$ = " " & msg$ & " " gosub SHOW_ERROR_DIALOG stop endif ! ----------------------------------------------------------------------------------------------- TiltMagMean = TiltMagSum / MeasureCount% TiltMagRange = TiltMagMax - TiltMagMin TiltMagError = 100.0 * TiltMagRange / TiltMagMean line$ = "" output @OutputFp; line$ ofmtr("%9.3f") line$ = "" line$ = line$ & "TiltMagMean = " & val$(TiltMagMean) & " urad\n" line$ = line$ & "TiltMagMax = " & val$(TiltMagMax) & " urad\n" line$ = line$ & "TiltMagMin = " & val$(TiltMagMin) & " urad\n" line$ = line$ & "TiltMagRange = " & val$(TiltMagRange) & " urad\n" line$ = line$ & "TiltMagError = " & val$(TiltMagError) & "%\n" output @OutputFp; line$ ! ----------------------------------------------------------------------------------------------- ScaledPvMean = ScaledPvSum / MeasureCount% ScaledPvRange = ScaledPvMax - ScaledPvMin ScaledPvError = 100.0 * ScaledPvRange / ScaledPvMean ofmtr("%9.3f") line$ = "" line$ = line$ & "ScaledPvMean = " & val$(ScaledPvMean) & " fr\n" line$ = line$ & "ScaledPvMax = " & val$(ScaledPvMax) & " fr\n" line$ = line$ & "ScaledPvMin = " & val$(ScaledPvMin) & " fr\n" line$ = line$ & "ScaledPvRange = " & val$(ScaledPvRange) & " fr\n" line$ = line$ & "ScaledPvError = " & val$(ScaledPvError) & "%\n" output @OutputFp; line$ ! ----------------------------------------------------------------------------------------------- assign @OutputFp to "" ! ----------------------------------------------------------------------------------------------- ofmtr("%.2f") msg$ = "Wand Move Test done, R = " & val$(TiltMagError) & "%, see " & OutputFn$ gosub SET_STATUS_MSG_2 ! ----------------------------------------------------------------------------------------------- msg$ = "Wand Move Test done" gosub LOG_DATE_TIME_MSG ofmtr("%.2f") msg$ = "R = " & val$(TiltMagError) & "%" gosub LOG_MSG ofmti("%d") msg$ = "Number of wand moves = " & val$(MoveIndex%) gosub LOG_MSG msg$ = "Number of moves below Lower Prog Limit = " & val$(NumMovesBelowLowerProgLimit%) gosub LOG_MSG msg$ = "Number of moves above Upper Prog Limit = " & val$(NumMovesAboveUpperProgLimit%) gosub LOG_MSG msg$ = "Results in file " & OutputFn$ gosub LOG_MSG ! ----------------------------------------------------------------------------------------------- if quietFlag% = 0 then msg$ = " Wand Move Test Result \n" ofmtr("%.2f") msg$ = msg$ & " R = " & val$(TiltMagError) & "% \n" msg$ = msg$ & " Details in file " & OutputFn$ & " " gosub SHOW_MESSAGE_DIALOG endif ! ----------------------------------------------------------------------------------------------- gosub SET_SCRIPT_STATUS_PASS ! ----------------------------------------------------------------------------------------------- end ! ----------------------------------------------------------------------------------------------- LIMIT_MOVE_TEST: Direction$ = "UP" ! First move will be upward LIMIT_MOVE_TEST_LOOP: MoveIndex% = MoveIndex% + 1 gosub GET_CUR_POS_AVG ! Sets CurPos ofmti("%d") msg$ = "Move " & val$(MoveIndex%) & " of " & val$(TestIterations%) msg$ = msg$ & ", " & Direction$ & " to limit" gosub SET_STATUS_MSG_2 if Direction$ = "UP" then gosub SDO_WAND_ZOOM_UP_TO_LIMIT Direction$ = "DOWN" else gosub SDO_WAND_ZOOM_DOWN_TO_LIMIT Direction$ = "UP" endif gosub MEASURE_AND_LOG_RESULTS if MoveIndex% < TestIterations% then goto LIMIT_MOVE_TEST_LOOP endif return ! ----------------------------------------------------------------------------------------------- RANDOM_MOVE_TEST: SdoWandZoomRandomWaitMin = 0.2 SdoWandZoomRandomWaitMax = 5.2 RANDOM_MOVE_TEST_LOOP: MoveIndex% = MoveIndex% + 1 gosub GET_CUR_POS_AVG ! Sets CurPos ofmti("%d") msg$ = "Move " & val$(MoveIndex%) & " of " & val$(TestIterations%) msg$ = msg$ & ", Random" gosub SET_STATUS_MSG_2 ! If at or near upper limit if CurPos >= UpperWandLimit then ! Zoom down a random distance gosub SDO_WAND_ZOOM_DOWN_RANDOM else ! Else if at or near lower limit if CurPos <= LowerWandLimit then ! Zoom up a random distance gosub SDO_WAND_ZOOM_UP_RANDOM else ! Else choose random direction if rnd >= 0.5 then gosub SDO_WAND_ZOOM_UP_RANDOM else gosub SDO_WAND_ZOOM_DOWN_RANDOM endif endif endif gosub MEASURE_AND_LOG_RESULTS if MoveIndex% < TestIterations% then goto RANDOM_MOVE_TEST_LOOP endif return ! ----------------------------------------------------------------------------------------------- MEASURE_AND_LOG_RESULTS: t = timedate Date$ = date$(t) Time$ = time$(t) ElapsedTime = (t - StartTime) / 60 ofmti("%d") msg$ = "Move " & val$(MoveIndex%) & " of " & val$(TestIterations%) ofmtr("%.3f") msg$ = msg$ & ", Zoom Mag = " & val$(getgpizoom(1)) gosub SET_STATUS_MSG_2 if SettlingTimeWait > 0 then wait SettlingTimeWait endif gosub GET_CUR_POS_AVG ! Sets var CurPos DeltaZoomPos = CurPos - ZoomPos ZoomPos = CurPos WithinProgLimits% = 1 if (LowerProgLimit > 0) and (ZoomPos < (LowerProgLimit - PosLimitEpsilon)) then NumMovesBelowLowerProgLimit% = NumMovesBelowLowerProgLimit% + 1 WithinProgLimits% = 0 endif if (UpperProgLimit > 0) and (ZoomPos > (UpperProgLimit + PosLimitEpsilon)) then NumMovesAboveUpperProgLimit% = NumMovesAboveUpperProgLimit% + 1 WithinProgLimits% = 0 endif if WithinProgLimits% = 1 then gosub MEASURE_WITH_RETRY gosub GET_DATA_ZOOM_MAG ! Gets attribute value into var DataZoomMag DeltaZoomMag = DataZoomMag - ZoomMag ZoomMag = DataZoomMag ! Get TltMag result from Test+Ref Map gosub GET_DATA_TILT_MAG_TR ! Gets result value into var DataTiltMag (in urad) TiltMag = DataTiltMag gosub GENERATE_ZERNIKE_PLANE ! Get PV result from Test+Ref Map gosub GET_DATA_PV_TR ! Gets result value into var DataPv (in fr) ScaledPv = ZoomMag * DataPv else ! NOT within prog limits DeltaZoomMag = 0 ZoomMag = 0 TiltMag = 0 DataPv = 0 ScaledPv = 0 endif line$ = "" ofmti("%06d") line$ = line$ & val$(MoveIndex%) line$ = line$ & ", " & Date$ line$ = line$ & ", " & Time$ ofmtr("%6.0f") line$ = line$ & ", " & val$(60 * ElapsedTime) ofmtr("%9.1f") line$ = line$ & ", " & val$(DeltaZoomPos) line$ = line$ & ", " & val$(ZoomPos) ofmtr("%9.6f") line$ = line$ & ", " & val$(DeltaZoomMag) line$ = line$ & ", " & val$(ZoomMag) ofmtr("%9.3f") line$ = line$ & ", " & val$(TiltMag) line$ = line$ & ", " & val$(DataPv) line$ = line$ & ", " & val$(ScaledPv) output @OutputFp; line$ if WithinProgLimits% = 1 then MeasureCount% = MeasureCount% + 1 TiltMagSum = TiltMagSum + TiltMag if TiltMag > TiltMagMax then TiltMagMax = TiltMag endif if TiltMag < TiltMagMin then TiltMagMin = TiltMag endif ScaledPvSum = ScaledPvSum + ScaledPv if ScaledPv > ScaledPvMax then ScaledPvMax = ScaledPv endif if ScaledPv < ScaledPvMin then ScaledPvMin = ScaledPv endif endif return ! ----------------------------------------------------------------------------------------------- loadsub "EncZoomSubs.scr" loadsub "EncZoomSdoSubs.scr" ! -----------------------------------------------------------------------------------------------