! EncZoomFind1X.scr ! Find the 1X magnification position ! ----------------------------------------------------------------------------------------------- loadsub "EncZoomGlob.scr" loadsub "EncZoomSdoGlob.scr" ! ----------------------------------------------------------------------------------------------- gosub GET_QUIET_FLAG ! Sets var quietFlag% ! ----------------------------------------------------------------------------------------------- gosub CLR_STATUS_MSG_ALL gosub SET_SCRIPT_STATUS_FAIL ! ----------------------------------------------------------------------------------------------- ! Maximum tilt in fringes Find1XMaxTiltPv = 10 ! ----------------------------------------------------------------------------------------------- if quietFlag% = 0 then msg$ = "" msg$ = msg$ & " Find 1X Position \n\n" msg$ = msg$ & " This will find the 1X magnification position. \n\n" msg$ = msg$ & " Requires the following: \n" msg$ = msg$ & " Plano interference cavity \n" msg$ = msg$ & " Unobscured image of a TF (RF larger than TF) \n" ofmtr("%.0f") msg$ = msg$ & " Tilt less than " & val$(Find1XMaxTiltPv) & " fringes at lowest zoom mag \n" msg$ = msg$ & " Good focus \n\n" msg$ = msg$ & " The following controls must be set correctly: \n" msg$ = msg$ & " Lower Prog Limit \n" msg$ = msg$ & " 1X Fill Pct \n\n" msg$ = msg$ & " The 1X Pos control will be set. \n\n" msg$ = msg$ & " This will take about 5 minutes. \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$ = "Find 1X Position" gosub SET_STATUS_MSG_1 gosub LOG_DATE_TIME_MSG ! ----------------------------------------------------------------------------------------------- StartTime = timedate ! ----------------------------------------------------------------------------------------------- msg$ = "Finding 1X magnification position" gosub SET_STATUS_MSG_2 ! ----------------------------------------------------------------------------------------------- gosub GET_CAM_SIZE_Y ! Sets var CamSizeY ! ----------------------------------------------------------------------------------------------- ! Epsilon values used to compare data size and diameter results (in pixels) CircularEpsilon = 0.006 * CamSizeY OneXDiamEpsilon = 0.001 * CamSizeY ! ----------------------------------------------------------------------------------------------- ! Position steps used in search MinStep = 10 BigStep = 400 ! ----------------------------------------------------------------------------------------------- SettlingTimeWait = 1.0 ! seconds ! ----------------------------------------------------------------------------------------------- gosub GET_1X_FILL_PCT ! Gets 1X Fill Pct control value, sets var OneXFillPct if (OneXFillPct < MinOneXFillPct) or (OneXFillPct > MaxOneXFillPct) then ofmtr("%.0f") msg$ = " The 1X Fill Pct control value " & val$(OneXFillPct) & " is out of range" msg$ = msg$ & " [" & val$(MinOneXFillPct) & "," & val$(MaxOneXFillPct) & "] " gosub SHOW_ERROR_DIALOG stop endif ! ----------------------------------------------------------------------------------------------- ! Caculate the required outer diameter 1X magnification OneXDiam = OneXFillPct * CamSizeY / 100 ! ----------------------------------------------------------------------------------------------- ofmtr("%.2f") msg$ = "1X diameter = " & val$(OneXDiam) gosub LOG_MSG ! ----------------------------------------------------------------------------------------------- gosub GET_LOWER_PROG_LIMIT ! Gets control value into var LowerProgLimit if LowerProgLimit <= 0 then msg$ = " The Lower Prog Limit control is not set. " gosub SHOW_ERROR_DIALOG stop endif ! ----------------------------------------------------------------------------------------------- dim OutputFn$[999] OutputFn$ = DataFolder$ & "\\" & "Find1X.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" ! ----------------------------------------------------------------------------------------------- ! Save the old control value gosub GET_1X_POS ! Gets control value into var OneXPos OldOneXPos = OneXPos ! Reset the 1X Pos control to zero OneXPos = 0 gosub SET_1X_POS ! Sets control using var OneXPos ! ----------------------------------------------------------------------------------------------- ! Disable firmware backlash compensation gosub SDO_DISABLE_BACKLASH_COMP ! ----------------------------------------------------------------------------------------------- ! Disable internal program move limits gosub CLEAR_PROG_LIMITS_CALINFO ! ----------------------------------------------------------------------------------------------- ! Disable firmware soft limits gosub SDO_DISABLE_SOFT_LIMITS ! ----------------------------------------------------------------------------------------------- ! 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 limit" gosub SET_STATUS_MSG_2 TargPos = 0 gosub SET_ZOOM_POS_AND_IGNORE_ERRORS ! Uses var TargPos if SettlingTimeWait > 0 then wait SettlingTimeWait endif gosub GET_CUR_POS_AVG ! Sets var CurPos ! ----------------------------------------------------------------------------------------------- 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 >= Find1XMaxTiltPv then msg$ = " Adjust tilt to obtain PV less than " ofmtr("%.0f") msg$ = msg$ & val$(Find1XMaxTiltPv) msg$ = msg$ & " fringes at lowest zoom mag. \n" msg$ = msg$ & " Click YES to retry or NO to stop. " 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 ! ----------------------------------------------------------------------------------------------- gosub GET_LATERAL_RESULTS ! Gets result values into vars DataSizeX, DataSizeY, DataOuterDiam, DataCentroidX, DataCentroidY gosub VERIFY_DATA_CIRCULAR ! Uses vars DataSizeX, DataSizeY, DataOuterDiam ! ----------------------------------------------------------------------------------------------- ofmtr("%.2f") msg$ = "Data diameter at lower limit = " & val$(DataOuterDiam) gosub LOG_MSG if DataOuterDiam > (OneXDiam + OneXDiamEpsilon) then ofmtr("%.2f") msg$ = "Data diameter at lower limit is greater than the 1X diameter" gosub LOG_DATE_TIME_MSG msg$ = " Data diameter at lower limit = " & val$(DataOuterDiam) & " \n" msg$ = msg$ & " This is greater than the target 1X diameter = " & val$(OneXDiam) & " \n" msg$ = " The 1X magnification position is below the lower limit " gosub SHOW_ERROR_DIALOG stop endif ! ----------------------------------------------------------------------------------------------- line$ = "Find 1X Position" output @OutputFp; line$ ofmtr("%.0f") line$ = "CamSizeY = " & val$(CamSizeY) output @OutputFp; line$ ofmtr("%.3f") line$ = "1X Fill Pct = " & val$(OneXFillPct) output @OutputFp; line$ line$ = "Target diameter = " & val$(OneXDiam) & " pix" output @OutputFp; line$ line$ = "Diameter epsilon = " & val$(OneXDiamEpsilon) & " pix" output @OutputFp; line$ ! Column headings line$ = "Position, Diameter (pix)" output @OutputFp; line$ ofmtr("%.0f") line$ = val$(CurPos) ofmtr("%.3f") line$ = line$ & ", " & val$(DataOuterDiam) output @OutputFp; line$ ! ----------------------------------------------------------------------------------------------- BelowOneXPos = CurPos BelowOneXDiam = DataOuterDiam ! Start with big steps PosStep = BigStep ! ----------------------------------------------------------------------------------------------- gosub FIND_1X_ZOOM_POS ! Sets var OneXPos ! ----------------------------------------------------------------------------------------------- assign @OutputFp to "" ! ----------------------------------------------------------------------------------------------- if OneXPos < LowerProgLimit then ofmtr("%.0f") msg$ = " 1X magnification position (" & val$(OneXPos) & ")" msg$ = msg$ & " is less than Lower Prog Limit (" & val$(LowerProgLimit) & ") " gosub LOG_DATE_TIME_MSG gosub SHOW_ERROR_DIALOG stop endif ! ----------------------------------------------------------------------------------------------- ! Set the 1X Pos control gosub SET_1X_POS ! Sets control using var OneXPos ! ----------------------------------------------------------------------------------------------- msg$ = "Find 1X Position done" ofmtr("%.0f") msg$ = msg$ & ", old = " & val$(OldOneXPos) & ", new = " & val$(OneXPos) gosub SET_STATUS_MSG_2 gosub LOG_DATE_TIME_MSG ! ----------------------------------------------------------------------------------------------- ElapsedTime = timedate - StartTime ! ----------------------------------------------------------------------------------------------- if quietFlag% = 0 then msg$ = " Find 1X Position done \n" ofmtr("%.0f") msg$ = msg$ & " Old = " & val$(OldOneXPos) & " \n" msg$ = msg$ & " New = " & val$(OneXPos) & " \n" ofmtr("%.1f") msg$ = msg$ & " Elapsed time = " & val$(ElapsedTime/60) & " min " gosub SHOW_MESSAGE_DIALOG endif ! ----------------------------------------------------------------------------------------------- gosub SET_SCRIPT_STATUS_PASS ! ----------------------------------------------------------------------------------------------- end ! ----------------------------------------------------------------------------------------------- FIND_1X_ZOOM_POS: ! Uses vars OneXDiam and PosStep ! Increase zoom up to or past 1X gosub INCREASE_ZOOM_TO_1X ! Uses vars OneXDiam and PosStep ! Sets vars FoundOneX%, BelowOneXPos, BelowOneXDiam, AboveOneXPos and AboveOneXDiam if FoundOneX% = 1 then OneXPos = CurPos return endif ! Interpolate to predict the 1X position A = OneXDiam - BelowOneXDiam B = AboveOneXPos - BelowOneXPos C = AboveOneXDiam - BelowOneXDiam OneXPos = BelowOneXPos + (A * B / C) ! Reduce the step size PosStep = PosStep / 2 if PosStep < MinStep then msg$ = "Finding 1X position could not converge" gosub LOG_DATE_TIME_MSG msg$ = " Finding 1X magnification position could not converge. " gosub SHOW_ERROR_DIALOG stop endif ! Move down past any backlash, but not below prog limit TargPos = OneXPos - BacklashCompMax - PosStep if TargPos < LowerProgLimit then TargPos = LowerProgLimit endif ofmtr("%.0f") msg$ = "Moving below 1X position, TargPos = " & val$(TargPos) gosub SET_STATUS_MSG_2 gosub MOVE_AND_CHECK_POS_ERROR ! Uses vars TargPos and PosErrorTol, sets vars CurPos and PosError goto FIND_1X_ZOOM_POS ! ----------------------------------------------------------------------------------------------- INCREASE_ZOOM_TO_1X: ! Uses vars OneXDiam and PosStep ! Sets vars FoundOneX%, BelowOneXPos, AboveOneXPos, BelowOneXDiam and AboveOneXDiam FoundOneX% = 0 AdjustmentIndex% = 0 INCREASE_ZOOM_TO_1X_LOOP: AdjustmentIndex% = AdjustmentIndex% + 1 ofmti("%d") ofmtr("%.1f") msg$ = "Increasing zoom until Outer Diam >= " & val$(OneXDiam) ofmtr("%.0f") msg$ = msg$ & ", step = " & val$(PosStep) ofmti("%d") msg$ = msg$ & ", adjustment " & val$(AdjustmentIndex%) gosub SET_STATUS_MSG_2 TargPos = CurPos + PosStep gosub MOVE_AND_CHECK_POS_ERROR ! Uses vars TargPos and PosErrorTol, sets vars CurPos and PosError if SettlingTimeWait > 0 then wait SettlingTimeWait endif gosub GET_CUR_POS_AVG ! Sets var CurPos gosub MEASURE_WITH_RETRY gosub GET_LATERAL_RESULTS ! Gets result values into vars DataSizeX, DataSizeY, DataOuterDiam, DataCentroidX, DataCentroidY ofmtr("%.0f") line$ = val$(CurPos) ofmtr("%.3f") line$ = line$ & ", " & val$(DataOuterDiam) output @OutputFp; line$ ! If data diam close enough to target OneXDiam, then we are done if abs(DataOuterDiam - OneXDiam) <= OneXDiamEpsilon then FoundOneX% = 1 return endif ! Else if data diam < target OneXDiam, if DataOuterDiam < OneXDiam then ! Record the "below" position and diameter and loop to increase zoom BelowOneXPos = CurPos BelowOneXDiam = DataOuterDiam goto INCREASE_ZOOM_TO_1X_LOOP endif ! Else data diam > target OneXDiam ! Record the "above" position and diameter and return AboveOneXPos = CurPos AboveOneXDiam = DataOuterDiam return ! ----------------------------------------------------------------------------------------------- VERIFY_DATA_CIRCULAR: ! Uses vars DataSizeX, DataSizeY, DataOuterDiam if abs(DataSizeX - DataSizeY) > CircularEpsilon then goto VERIFY_DATA_CIRCULAR_NOT endif if abs(DataSizeX - DataOuterDiam) > CircularEpsilon then goto VERIFY_DATA_CIRCULAR_NOT endif return VERIFY_DATA_CIRCULAR_NOT: ofmtr("%.2f") msg$ = "Data is not circular: Size X = " & val$(DataSizeX) msg$ = msg$ & ", Size Y = " & val$(DataSizeY) msg$ = msg$ & ", Outer Diam = " & val$(DataOuterDiam) gosub LOG_DATE_TIME_MSG msg$ = " Data is not circular. \n" msg$ = msg$ & " The Size X, Size Y and Outer Diam results should match" ofmtr("%.1f") msg$ = msg$ & " to within " & val$(CircularEpsilon) & " pixels " gosub SHOW_ERROR_DIALOG stop ! ----------------------------------------------------------------------------------------------- loadsub "EncZoomSubs.scr" loadsub "EncZoomSdoSubs.scr" ! -----------------------------------------------------------------------------------------------