Looks like I made an error copying the above code. I've posted the correct code below.
The code is supposed to automatically zero the XYZ axis by first probing down to the top of the plate, then jogs over to find the X, then the Y. I can get it to work by manually touching the plate to the probe, but any time the plate is resting on the wood or aluminum material a grounding error occurs. I think it's because I can quickly pull the plate away and some sort of double signal is not sent that causes the error.
Here is the code that causes the error:
Rem Auto corner finding X-Y-Z-(button3) With tool diameter Input
CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) 'Get the current G0/G1 state
CurrentToolDiameter = GetOemDRO(43) 'gets the current tool diameter
If GetOemLed (825)<>0 Then 'Check to see if the probe is already grounded or faulty
Call ProbeGrounded()
Exit Sub
Else
DoOEMButton (1010) 'zero the Z axis so the probe move will start from here
Code "G4 P2" ' two second delay
Code "G90 G31 Z-1.0 F5" 'Z goes down a max of 1.0 at 5IPM
While IsMoving() 'wait while it happens
Wend
ZProbePos = GetVar(2002) 'get the axact point the probe was hit
Code "G0 Z" &ZProbePos 'go back to that point, always a very small amount of overrun
While IsMoving ()
Wend
Call SetDro (2,0.000)
Code "G4 P0.25" 'Pause for Dro to update.
Code "G90 G0 Z.500" 'retract Z to .500 inch
Code "G91 G0 Y-.100 X1.0"
Code "G90 G0 Z-.200"
Code "F" &CurrentFeed 'Returns to prior feed rate
End If
Rem VBScript For probing In the x- direction
If GetOemLed (825)<>0 Then 'May need to use =0 if it errors
Call ProbeGrounded() 'Check to see if the probe is already grounded or faulty
Exit Sub
Else
Code "G4 P1" 'Pause 1 second to give time to position probe plate
CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
Code "F4"
Rem Probe Left
XNew = GetDro(0) - 3 'probe to current position - 3 inches
Code "G31 X" &XNew
While IsMoving() 'wait for prob move to complete
Wend
XNew = GetVar(2000) 'read the touch point
Rem move back To the hit point incase there was an overshoot
Code "G90 G0 Z.500"
Code "G90 G0 X" &XNew
Code "G91 X-" &CurrentToolDiameter/2 'moves the probe half the tool diameter to center on edge
While IsMoving ()
Wend
Call SetDro (0,0.000)
Code "G4 P0.25"
Code "G91 G0 X-.200 Y1.0"
Code "G90 G0 Z-.200"
Code "F" &CurrentFeed 'restore original feed rate
End If
Rem VBScript For probing In the Y- direction
If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty
Call ProbeGrounded()
Exit Sub
Else
Code "G4 P1" 'Pause 1 second to give time to position probe plate
CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
Code "F4" 'Slow feedrate to 4 ipm
Rem Probe up
YNew = GetDro(1) - 3 'move to current y position + 3 inches
Code "G31 Y" &YNew
While IsMoving() 'wait for the move to finish
Wend
YNew = GetVar(2001) 'read the touch point
Rem move back To the hit point incase there was an overshoot
Code "G90 G0 Z.500"
Code "G90 G0 Y" &YNew
Code "G91 Y-" &CurrentToolDiameter/2 'moves the probe half the tool diameter to center on edge
While IsMoving ()
Wend
Call SetDro (1,0.000)
Code "G4 P0.25"
Code "G90 G0 X0.0"
Code "F" &CurrentFeed 'restore original feed rate
Code "(X, Y, and Z axis' are now zeroed)"
Call ReturnG90G91State()
Exit Sub
End If
Sub ProbeGrounded()
Code "(Probe plate is grounded, check connection and try again)"
Call ReturnG90G91State()
End Sub
Sub ReturnG90G91State()
If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If
If CurrentGMode = 0 Then 'if G0 was in effect before then return to it
Code "G0"
End If
End Sub