Rem HiddenScriptMetric_test.m1s Rem VBScript To center probe inside the edge-finder hole, And On Any edge rem Vancura Innovations 2006/10/30 creation Date; rem 9010 33rd ST W rem Rock Island, IL 61201 rem (309) 235-1069 rem edgefinder@vancura.biz rem revisions: rem 2018/09/05B: Fcn 1,2,3,4,5,6,&7 fixup rem 2018/09/04: fcn 1, 6, & 7 fixup rem 2018/08/31: minor code fixup, documentation, changes to fcn-7 rem 2018/08/25: FeedFast added to replace G00 with G01 rem 2018/08/11: fcn 6: Z goes to safeZ at end. rem 2018/07/12: fixed tool_x sizes, allowed for different X & Y thicknesses for edgefinder rem 2017/06/14: For Metric/English use rem 2015/11/11: minor update, some notes rem 2010/10/30: udates rem user must enter a number before CNC will move. rem entering zero will Exit doing Nothing (abort) rem Probe continuity should be tested before running program rem Will Not run If probe is shorted ' Option Explicit ' this forces programmer to list all variables Dim tool_1 ' 3/32" = 2.38mm Favorite tool #1 size Dim tool_2 ' 1/8" = 3.175mm Favorite tool #2 size Dim tool_3 ' 1/4" = 6.350mm Favorite tool #3 size Dim SIDE_X ' 0.300" = 7.72mm finder side width X Dim SIDE_Y ' 0.300" = 7.72mm finder side width Y Dim BigMove ' about 1" (25.4mm) move probe this distance looking for edge Dim SmallMove ' about 0.100" (2.54mm) clearance over material Dim FeedSlow ' 4in/min or 100mm/min; Faster sacrifices accuracy, slower increases boredom Dim FeedFast ' 10 x FeedSlow Faster sacrifices accuracy, slower increases boredom Dim safeZ ' === change safe Z height; should clear work-piece ' ==================================================== Dim toolsize ' tool diameter Dim touchoffsetX ' tool + side thickness Dim touchoffsetY ' tool + side thickness Dim mymode As Integer ' selection: for action; answer to question Dim FeedCurrent ' feed speed being used Dim Xoffset ' position information Dim Yoffset ' position information Dim mytoolsize As Integer ' answer to question Dim XCurrent ' position information Dim YCurrent ' position information Dim ZCurrent ' position information Dim XCenter ' calculated center Dim YCenter ' calculated center Dim XNew ' destination of next move Dim YNew ' destination of next move Dim ZNew ' destination of next move Dim XPos1 ' saved temp position Dim YPos1 ' saved temp position Dim XPos2 ' saved temp position Dim YPos2 ' saved temp position Dim ZPos2 ' saved temp position ' ==================================================== ' ===== CHANGE HERE for METRIC or ENGLISH ============ ' ==================================================== tool_1 = 2.380 ' 3/32" = 2.380mm Favorite tool #1 size tool_2 = 3.175 ' 1/8" = 3.175mm Favorite tool #2 size tool_3 = 6.35 ' 1/4" = 6.350mm Favorite tool #3 size SIDE_X = 7.720 ' 0.300" = 7.720mm finder side width both X SIDE_Y = 7.720 ' 0.300" = 7.720mm finder side width both Y BigMove = 25.4 ' 1.000" = 25.400mm move probe this distance looking for edge SmallMove = 2.54 ' 0.100" = 2.540mm clearance over material FeedSlow = 100 ' 4in/min or 100mm/min Faster sacrifices accuracy, slower FeedFast = FeedSlow * 10 ' Faster sacrifices accuracy, slower increases boredom ' ==================================================== safeZ = SmallMove ' === change safe Z height; should clear work-piece ' ================================================================= ' ================================================================= ' ===== CODE STARTS HERE ========================================= ' ================================================================= rem === program will Not run If probe is shorted === If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty Code "(Probe is grounded, check clearance and try again)" Else ' === module works in only one mode === If GetOemLed (16) <> 0 Then 'Warning Wrong Coordinate system DoOEMButton(107) Code "(Changing to Normal DRO Mode)" Code "G4 P0.25" ' === Pause 1/4 sec === End If DoSpinStop ' === double check motor is not running === Xoffset = SmallMove Yoffset = SmallMove toolsize = (tool_2)/2 ' === 1/8" tool default tool size === ' === ask user to select an operation to perform. === mymode = Question ("0=Q; 1=Cntr, 2=-X; 3=-Y; 4=+X; 5=+Y; 6=Z; 7=XYZ") ' If mymode = 0 Then ' === zero quits without doing anything === Code "(0 = Quit)" Exit Sub End If ' === ask more questions if not finding center or z=0 === If ((mymode > 1) And (mymode < 8) And (mymode <> 6)) Then If (FeedSlow < 25) Then mytoolsize = Question ("Probe Size inch 1=3/32; 2=1/8; 3=1/4") Else mytoolsize = Question ("Probe Size mm 1=2.38; 2=3.175; 3=6.35") End If If (mytoolsize = 1) Then toolsize = (tool_1) /2 ElseIf (mytoolsize = 2) Then toolsize = (tool_2) /2 Elseif (mytoolsize = 3) Then toolsize = (tool_3) /2 End If ' mytoolsize = Question ("Edge Compensation: 0=Finder-Offset; 1=WorkPiece") If mytoolsize = 1 Then touchoffsetX = toolsize ' Touch to work_piece touchoffsetY = toolsize ' Touch to work_piece Else touchoffsetX = toolsize + SIDE_X ' Touch to edgefinder touchoffsetY = toolsize + SIDE_Y ' Touch to edgefinder End If End If ' mymode = mymode -1 ' === normalize (we don't do this)=== ' FeedCurrent = GetOemDRO(818) 'Get the current settings XCurrent = GetDro(0) ' location of tool X position YCurrent = GetDro(1) ' location of tool Y position ZCurrent = GetDro(2) ' location of tool Z position Code "G4 P1" 'Pause 1 second to give time to position probe plate '======================================== If mymode = 1 Then ' === FIND CENTER) === '======================================== Code "(Mode 1: Find Center )" Rem Move Probe X Minus XNew = Xcurrent - BigMove 'Move probe (1 inch) to left Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 X" &XNew While IsMoving() 'wait for the move to finish Wend XPos1 = GetVar(2000) 'get the probe touch location Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 X" &XCurrent 'rapid move back to start point Rem Move Probe X Plus XNew = XCurrent + BigMove 'move probe 25mm (1 inch) to right Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 X" &XNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend XPos2 = GetVar(2000) 'get the probe touch location ' Rem === calculate hole X center === XCenter = (XPos1 + XPos2) / 2 'center is midway between XPos1 and XPos2 Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 X" &XCenter 'rapid move to the x center location While IsMoving () 'Wait for stop signal Wend Call SetDro (0,0.000) 'Zero out the location X Code "G4 P0.25" 'Pause 1/4 sec Rem Move Probe Y Minus YNew = YCurrent - BigMove 'move probe 25mm (1 inch) to left Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Y" &YNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend YPos1 = GetVar(2001) 'get the probe touch location Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 Y" &YCurrent Rem Move Probe Y Plus YNew = YCurrent + BigMove 'move probe 25mm (1 inch) to right Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Y" &YNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend YPos2 = GetVar(2001) 'get the probe touch location ' === Calculate hole Y center === YCenter = (YPos1 + YPos2) / 2 'center is midway between XPos1 and XPos2 Rem move To the center Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 Y" &YCenter While IsMoving () 'Wait for stop signal Wend Call SetDro (1,0.000) While IsMoving () Wend Code "G4 P0.25" 'Pause 1/4 sec Rem ================================================== Rem === Do X center find a Second Time For better accuracy. === Rem Again Move Probe X Minus XCurrent = GetDro(0) XNew = Xcurrent - BigMove 'move probe 1 inches to left Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 X" &XNew While IsMoving() 'wait for the move to finish Wend XPos1 = GetVar(2000) 'get the probe touch location Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 X" &XCurrent 'rapid move back to start point Rem Again Move Probe X Plus XNew = XCurrent + BigMove 'move probe 1 inches to right Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 X" &XNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend XPos2 = GetVar(2000) 'get the probe touch location XCenter = (XPos1 + XPos2) / 2 'center is midway between XPos1 and XPos2 Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 X" &XCenter 'rapid move to the x center location While IsMoving () 'Wait for stop signal Wend Call SetDro (0,0.000) Code "G4 P0.25" 'Pause 1/4 sec Rem Move Probe Y Minus (Second Time) YNew = YCurrent - BigMove 'move probe 25mm (1 inch) to left Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Y" &YNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend YPos1 = GetVar(2001) 'get the probe touch location Code "G4 P0.25" 'Pause 1/4 sec Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 Y" &YCurrent Rem Move Probe Y Plus (Second Time) YNew = YCurrent + BigMove 'move probe 25mm (1 inch) to right Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Y" &YNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend YPos2 = GetVar(2001) 'get the probe touch location ' === Calculate hole Y center === YCenter = (YPos1 + YPos2) / 2 'center is midway between XPos1 and XPos2 Rem move To the center Code "G4 P0.25" 'Pause 1/4 sec Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 Y" &YCenter While IsMoving () 'Wait for stop signal Wend Call SetDro (1,0.000) While IsMoving () Wend Code "G4 P0.25" 'Pause 1/4 sec Rem ================================================== Rem Call SetUserDro (1152,YPos1 - YPos2 + .200) Rem Code "G4 P0.25" 'Pause 1/4 sec '=================================== ElseIf mymode = 2 Then '=================================== Rem === find the outside edge To minus X === Code "(Mode 2: Find -X )" Rem Move Probe X Plus XNew = XCurrent + BigMove 'move probe 1 inch to right Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 X" &XNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend XPos2 = GetVar(2000) ' Get the X location ' XCenter = (XPos2) + touchoffsetX 'compensate for tool & finder edge Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 X" &(XPos2-safeZ) 'rapid move to the x center location While IsMoving() 'Wait for stop signal Wend Code "G01 Z" &safeZ 'rapid move to the x center location While IsMoving() 'Wait for stop signal Wend Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 X" &XCenter 'rapid move to the x center location While IsMoving () 'Wait for stop signal Wend Call SetDro (0,0.000) 'Zero the X DRO location Code "G4 P0.25" 'Pause 1/4 sec ' ===== '=================================== ElseIf mymode = 3 Then '=================================== Rem === find the outside edge To minus Y === Code "(Mode 3: Find -Y )" Rem Move Probe Y Plus YNew = YCurrent + BigMove 'move probe 1 inch to right Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Y" &YNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend YPos2 = GetVar(2001) 'Get the Y location ' YCenter = (YPos2) + touchoffsetY Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 Y" &(YPos2-safeZ) 'rapid move to the x center location While IsMoving() 'Wait for stop signal Wend Code "G01 Z" &safeZ 'rapid move to the x center location While IsMoving() 'Wait for stop signal Wend Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 Y" &YCenter 'rapid move to the x center location While IsMoving () 'Wait for stop signal Wend Call SetDro (1,0.000) 'Zero the Y DRO position Code "G4 P0.25" 'Pause 1/4 sec ' ===== '=================================== ElseIf mymode = 4 Then '=================================== Rem === find the outside edge To plus X === Code "(Mode 4: Find +X )" Rem Move Probe X Minus (Move the probe in the X minus direction until touch) XNew = XCurrent - BigMove 'set destination 1 inch minus X Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 X" &XNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend XPos2 = GetVar(2000) 'get the touch X location ' XCenter = (XPos2) - touchoffsetX 'Calculate the actual work_piece edge location Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 X" &(XPos2+safeZ) 'rapid move to the x center location While IsMoving() 'Wait for stop signal Wend Code "G01 Z" &safeZ 'Raise tool to safe height While IsMoving() 'Wait for stop signal Wend Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 X" &XCenter 'move to the work_piece X edge location While IsMoving () 'Wait for stop signal Wend Call SetDro (0,0.000) 'Zero the X-DRO to the work_piece edge Code "G4 P0.25" 'Pause 1/4 sec ' ===== '=================================== ElseIf mymode = 5 Then '=================================== Rem === find the outside edge To plus Y === Code "(Mode 5: Find +Y )" Rem Move Probe Y Minus 'Move the probe in the Y minus direction until touch of workPiece YNew = YCurrent - BigMove 'set destination 1 inch minus Y Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Y" &YNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend YPos2 = GetVar(2001) 'Get the Y touch location ' YCenter = (YPos2) - touchoffsetY 'Calculate the actual work_piece edge location Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 Y" &(YPos2+safeZ) 'rapid move to the x center location While IsMoving() 'Wait for stop signal Wend Code "G01 Z" &safeZ 'rapid move to safe height While IsMoving() 'Wait for stop signal Wend Code "F" &FeedFast 'Feed rate speed for seeking touch Code "G01 Y" &YCenter 'move to the workpiece Y edge location While IsMoving () 'Wait for stop signal Wend Call SetDro (1,0.000) 'Zero the Y-DRO to the work_piece edge Code "G4 P0.25" 'Pause 1/4 sec ' ===== '=========================================== ElseIf mymode = 6 Then '==== Z TOP ==== '=========================================== Rem === find the top surface Z = Zero === Code "(Mode 6: Find Z Top )" Rem Move Probe Z Minus ZNew = ZCurrent - BigMove 'set destination 1" minus (down) Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Z" &ZNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend ZPos2 = GetVar(2002) Call SetDro (2,0.000) ' Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &safeZ 'rapid move to the Z+ 0.1" location While IsMoving() 'Wait for stop signal Wend Rem ========================== Rem === Move Probe Z Minus === Rem ========================== ' === Second time === ZNew = ZCurrent - BigMove 'set destination 1" minus (down) Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Z" &ZNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend Code "G4 P0.500" 'Pause 0.5 sec ZPos2 = GetVar(2002) Call SetDro (2,0.000) ' Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &safeZ 'rapid move to the Z+ 0.1" location While IsMoving() 'Wait for stop signal Wend ' '=========================================== ElseIf mymode = 7 Then '==== X Y Z ==== '=========================================== Rem === find the outside edge minus X, minus Y, And Z = 0 === Code "(Mode 7: Find -X0, -Y0, &Z0 )" ' Must be within 1 inch of the corner over the work Call SetDro (0,0.000) ' Call SetDro (1,0.000) Call SetDro (2,0.000) ' ======================== ' ===== First find Z ===== ' ======================== ZNew = ZCurrent - (3 * BigMove) 'set destination 3" minus (down) Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Z" &ZNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend ZPos2 = GetVar(2002) 'The Z EDGE location Call SetDro (2,0.000) 'Zero the Z edge DRO ' Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &safeZ 'rapid move to safe height While IsMoving() 'Wait for stop signal Wend Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &0 'rapid move to the Z surface While IsMoving () 'Wait for stop signal Wend ' Code "G4 P0.50" 'Pause 1/2 sec ' Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &safeZ 'rapid move to safe height While IsMoving() 'Wait for stop signal Wend ' ======================= ' ===== Then find X ===== ' ======================= Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &safeZ 'rapid move to safeZ location While IsMoving() 'Wait for stop signal Wend ' XNew = XCurrent - BigMove *1.0 'back off 1.5 inch Code "F" &FeedFast 'fast Feed rate speed Code "G01 X" &XNew 'rapid move to the x starting location While IsMoving() 'Wait for stop signal Wend Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &(-SmallMove) 'move to starting height ' XNew = XCurrent + 1.75*BigMove 'probe 1.5 inches to X+ Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 X" &XNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend XPos2 = GetVar(2000) 'Get X location ' XCenter = (XPos2) + touchoffsetX 'Calculate The workpiece actual X edge position Code "F" &FeedFast 'fast Feed rate speed Code "G01 X" &(XPos2 -(SmallMove)) 'back off from work. don't scratch it. While IsMoving() 'Wait for stop signal Wend Code "G01 Z" &safeZ 'rapid move to the safeZ location While IsMoving() 'Wait for stop signal Wend Code "F" &FeedFast 'fast Feed rate speed Code "G01 X" &XCenter 'rapid move to the workpiece X Edge location While IsMoving () 'Wait for stop signal Wend Call SetDro (0,0.000) 'Set workpiece X edge to DRO zero Code "G4 P0.25" 'Pause 1/4 sec ' ======================= ' ===== Then find Y ===== '======================== Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &safeZ 'rapid move to safeZ location While IsMoving() 'Wait for stop signal Wend ' Code "F" &FeedFast 'fast Feed rate speed Code "G01 X" &(SIDE_X) 'rapid move to the x starting location While IsMoving() 'Wait for stop signal Wend ' Code "F" &FeedFast 'fast Feed rate speed Code "G01 Y" &(-BigMove) 'rapid move to the y starting location While IsMoving() 'Wait for stop signal Wend Code "G31 Z" &(-(SmallMove)) 'move Z down to starting height While IsMoving() 'Wait for stop signal Wend If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty Code "G01 Z" &(SafeZ) 'move Z up to clear material While IsMoving() 'Wait for stop signal Wend Code "G01 Y" &(-BigMove * 1.5)'rapid move to the y starting location While IsMoving() 'Wait for stop signal Wend Code "G31 Z" &(-(SmallMove)) 'move Z down to starting height While IsMoving() 'Wait for stop signal Wend End If ' YNew = YCurrent + (BigMove) Code "F" &FeedSlow 'Feed rate speed for seeking touch Code "G31 Y" &YNew 'Start hunt for edge While IsMoving() 'Wait for stop signal Wend YPos2 = GetVar(2001) 'Get Y location ' YCenter = (YPos2) + touchoffsetY 'Calculate workpiece Edge position Code "F" &FeedFast 'fast Feed rate speed Code "G01 Y" &(YPos2 -(SmallMove)) 'back off from work While IsMoving() 'Wait for stop signal Wend Code "G01 Z" &safeZ 'rapid move to the safeZ location While IsMoving() 'Wait for stop signal Wend Code "F" &FeedFast 'fast Feed rate speed Code "G01 Y" &YCenter 'rapid move to the workpiece Y location While IsMoving () 'Wait for stop signal Wend Call SetDro (1,0.000) 'Set Y DRO to zero for workpiece edge Code "G4 P0.25" 'Pause 1/4 sec ' ========================== ' ===== Go to x0,y0,z0 ===== ' ========================== Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &safeZ 'rapid move to the safeZ location While IsMoving () 'Wait for stop signal Wend Code "F" &FeedFast 'fast Feed rate speed Code "G01 X" &(0.000) 'rapid move to the x corner location Code "G01 Y" &(0.000) 'rapid move to the y corner location While IsMoving () 'Wait for stop signal Wend Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &(0.000) 'rapid move to the z corner location While IsMoving () 'Wait for stop signal Wend ' Code "G4 P0.500" 'Pause 1/2 sec Code "F" &FeedFast 'fast Feed rate speed Code "G01 Z" &safeZ 'rapid move to the safeZ location While IsMoving () 'Wait for stop signal Wend ' ===== Function 7 Done ===== '=================================== ElseIf mymode = 8 Then ' === Dummy routine === toolsize = (tool_1) /2 '=================================== ElseIf mymode = 9 Then ' === Dummy routine === toolsize = (tool_2) /2 '=================================== End If '=================================== Rem: === Restore original feedrate === Code "F" &FeedCurrent 'restore starting feed rate End If