'M500 Tool Platform Zero Find
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
LIFT = GetOemDRO(1093)
CLEARANCE = GetUserDRO(1094)
PROBEFEED = GetUserDRO(1095)
MOVEFEED = GetUserDRO(1096)
Call SetOemDRO(800,0)
Call SetOemDRO(801,0)

Code "F" & PROBEFEED 'Sets Feed speed
While IsMoving ()
Sleep 200
Wend
Code "G91 G31 Z" & GetUserDRO(1109) 'probing move, can set the feed rate here as well as how far to move
While IsMoving ()
Sleep 100
Wend
Code "G4 P0.5"
ToolPalletZZero = GetVar(2002) 'get the axact point the probe was hit
Code "G90 G0 Z" &ToolPalletZZero 'go back to that point, always a very small amount of overrun
While IsMoving ()
Sleep 200
Wend	
Call SetUserDRO(1100,GetOemDRO(85)-GetUserDRO(1220))
Code "G0 Z" & ToolPalletZZero - GetUserDRO(1109)'retracts the Z above Tool Pallet Zero
While IsMoving ()
Sleep 200
Wend
Code "(TOOL PALLET ZERO ESTABLISHED)" 'puts this message in the status bar
Code "F" &CurrentFeed 'Returns to prior feed rate
Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if aplicable
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
Exit Sub      
