! EncZoomSetPL.scr ! Set Program Limits ! ----------------------------------------------------------------------------------------------- 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$ & " Set Prog Limits \n\n" msg$ = msg$ & " This will set limits for program moves. \n\n" msg$ = msg$ & " No interference cavity is required. \n\n" msg$ = msg$ & " The following controls will be set: \n" msg$ = msg$ & " Lower Prog Limit \n" msg$ = msg$ & " Upper Prog Limit \n\n" msg$ = msg$ & " This will take about 2 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$ = "Set Prog Limits" gosub SET_STATUS_MSG_1 gosub LOG_DATE_TIME_MSG ! ----------------------------------------------------------------------------------------------- StartTime = timedate ! ----------------------------------------------------------------------------------------------- msg$ = "Setting program move limits" gosub SET_STATUS_MSG_2 ! ----------------------------------------------------------------------------------------------- NumMovesToTestLimit% = 10 ! ----------------------------------------------------------------------------------------------- dim OutputFn$[999] OutputFn$ = DataFolder$ & "\\" & "ProgLimits.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$ = "Program Move Limits" output @OutputFp; line$ ! ----------------------------------------------------------------------------------------------- ! Save old control values gosub GET_LOWER_PROG_LIMIT ! Gets control value into var LowerProgLimit gosub GET_UPPER_PROG_LIMIT ! Gets control value into var UpperProgLimit OldLowerProgLimit = LowerProgLimit OldUpperProgLimit = UpperProgLimit ! Reset the controls to zero LowerProgLimit = 0 UpperProgLimit = 0 gosub SET_LOWER_PROG_LIMIT ! Sets control using var LowerProgLimit gosub SET_UPPER_PROG_LIMIT ! Sets control using var UpperProgLimit ! ----------------------------------------------------------------------------------------------- ! 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 ! ----------------------------------------------------------------------------------------------- ! Find lower prog limit ! Column headings line$ = "LowerProgLimit, ActualPos" output @OutputFp; line$ LimitDir% = -1 gosub FIND_LIMIT_POS ! Uses var LimitDir%, sets var LimitPos LowerProgLimit = LimitPos ! ----------------------------------------------------------------------------------------------- ! Find upper prog limit ! Column headings line$ = "UpperProgLimit, ActualPos" output @OutputFp; line$ LimitDir% = 1 gosub FIND_LIMIT_POS ! Uses var LimitDir%, sets var LimitPos UpperProgLimit = LimitPos ! ----------------------------------------------------------------------------------------------- ElapsedTime = timedate - StartTime ofmtr("%.1f") line$ = " Elapsed time = " & val$(ElapsedTime/60) & " min " output @OutputFp; line$ ! ----------------------------------------------------------------------------------------------- assign @OutputFp to "" ! ----------------------------------------------------------------------------------------------- ! Set the custom controls gosub SET_LOWER_PROG_LIMIT ! Sets control using var LowerProgLimit gosub SET_UPPER_PROG_LIMIT ! Sets control using var UpperProgLimit ! ----------------------------------------------------------------------------------------------- msg$ = "Set Prog Limits done" ofmtr("%.0f") msg$ = msg$ & ", old = [" & val$(OldLowerProgLimit) & "," & val$(OldUpperProgLimit) & "]" msg$ = msg$ & ", new = [" & val$(LowerProgLimit) & "," & val$(UpperProgLimit) & "]" gosub SET_STATUS_MSG_2 gosub LOG_DATE_TIME_MSG ! ----------------------------------------------------------------------------------------------- if quietFlag% = 0 then msg$ = " Set Prog Limits done \n" ofmtr("%5.0f") msg$ = msg$ & " Old = [" & val$(OldLowerProgLimit) & "," & val$(OldUpperProgLimit) & "] \n" msg$ = msg$ & " New = [" & val$(LowerProgLimit) & "," & val$(UpperProgLimit) & "] \n" ofmtr("%.1f") msg$ = msg$ & " Elapsed time = " & val$(ElapsedTime/60) & " min " gosub SHOW_MESSAGE_DIALOG endif ! ----------------------------------------------------------------------------------------------- gosub SET_SCRIPT_STATUS_PASS ! ----------------------------------------------------------------------------------------------- end ! ----------------------------------------------------------------------------------------------- FIND_LIMIT_POS: ! Finds a limit position that will be reachable without actually hitting the limit switch. ! Assumes that backlash compensation and soft limits are disabled. ! Uses var LimitDir%. ! Set LimitDir% = -1 to find LOWER limit. ! Set LimitDir% = +1 to find UPPER limit. ! Sets var LimitPos. ! Start near the middle TargPos = MidPos gosub SET_ZOOM_POS_AND_IGNORE_ERRORS ! Uses var TargPos if LimitDir% = -1 then ! Move to LOWER limit switch. TargPos = 0 else ! Move to UPPER limit switch. TargPos = 60000 endif gosub SET_ZOOM_POS_AND_IGNORE_ERRORS ! Uses var TargPos LimitPos = TargPos FIND_LIMIT_POS_LOOP: gosub GET_CUR_POS_AVG ! Sets var CurPos ofmtr("%.0f") line$ = val$(LimitPos) & ", " & val$(CurPos) output @OutputFp; line$ TinyStep = 25 ofmtr("%.0f") if LimitDir% = -1 then LimitPos = CurPos + TinyStep BigStepAway = 5000 msg$ = "Finding lower prog limit, current value = " & val$(LimitPos) else LimitPos = CurPos - TinyStep BigStepAway = -5000 msg$ = "Finding upper prog limit, current value = " & val$(LimitPos) endif gosub SET_STATUS_MSG_2 ! Test if we can move to LimitPos without error. gosub TEST_LIMIT_POS ! Uses vars LimitPos and BigStepAway, sets var ok% if ok% <> 1 then goto FIND_LIMIT_POS_LOOP endif ofmtr("%.0f") line$ = val$(LimitPos) & ", " output @OutputFp; line$ return ! ----------------------------------------------------------------------------------------------- TEST_LIMIT_POS: ! Tests a limit position to determine if we can move there repeatedly without errors. ! Uses vars LimitPos and BigStepAway. ! If testing a LOWER limit, then BigStepAway should be positive. ! If testing an UPPER limit, then BigStepAway should be negative. ! Sets var ok% to indicate success or failure. ok% = 0 for _i% = 1 to NumMovesToTestLimit% ! Start away from the limit position TargPos = LimitPos + BigStepAway gosub SET_ZOOM_POS_AND_IGNORE_ERRORS ! Uses var TargPos ! Move to limit position and detect any errors TargPos = LimitPos gosub SET_ZOOM_POS_AND_DETECT_ERRORS ! Uses var TargPos, sets var ErrorBits% if ErrorBits% <> 0 then ! Fail ok% = 0 return endif next _i% ! Success ok% = 1 return ! ----------------------------------------------------------------------------------------------- loadsub "EncZoomSubs.scr" loadsub "EncZoomSdoSubs.scr" ! -----------------------------------------------------------------------------------------------