'####### Auto Probing Button 1 front Left corner Z, X,Y  05/2016#######

'##########    VBScript For probing In the Z- direction

CurrentFeed = GetOEMDRO(818) 'Get the current feedrate to return to later
tool = GetCurrentTool
TipDia = GetOEMDRO(43)
PFR = GetUserDRO(1118)
	
'######### Check Tool Offsets########
If GetOEMLED (28) <> 0 Then 'Check to see if Tool Offsets are on
DoOEMButton (136) 'Remove tool Offsets
Code "(Tool Offsets turned off when probing)" 'this goes in the status bar if aplicable
Else

End If
'######## Check Probe#########

If GetOEMLED (825) <> 0 Then 'Check to see if the probe is already grounded or faulty
	Code "(Probe is grounded, check connection and try again)" 'this goes in the status bar if aplicable
Else
'############ Zero Z axis###########
DoOEMButton (1010) 'zero the Z axis so the probe move will start from here
Code "G4 P0.025" ' One second delay
Code "G31 Z-1.0 F" &PFR  'Z goes down a max of 1.0 at User defined feed rate
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
Code "G43 H" &tool
While IsMoving ()
Wend
Call SetDRO (2,0.000) 
Code "G4 P0.025" 'Pause for Dro to update.
Code "G90 G0 Z.500" 'retract Z to .500 inch
Code "G91 G0 X-1.0 Y" &TipDia/2
Code "G90 G0 Z-.200"

End If

'##########	VBScript For probing In the x- direction

If GetOEMLED (825) = 0 Then 		'Check to see if the probe is already grounded or faulty
	Code "(Probe is grounded, check connection and try again)" 'this goes in the status bar if aplicable
Else
	Code "G4 P0.025"			'Pause 1 second to give time to position probe plate
	Code "F" &PFR ' User defined feed rate

'########	Probe X Left side

	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

	Code "G90 G0 X" &XNew '	move back To the hit point incase there was an overshoot
	Code "G90 G0 Z.500"
	Code "G91 X" &TipDia/2
        
	While IsMoving ()
	Wend
        Call SetDRO (0,0.000)
        Code "G4 P0.025" 
        Code "G91 G0 Y-1.0 X" &TipDia
        Code "G90 G0 Z-.200"
End If 

'########	VBScript For probing In the Y direction

If GetOEMLED (825) <> 0 Then 		'Check to see if the probe is already grounded or faulty
	Code "(Probe is grounded, check connection and try again)"
Else
	Code "G4 P0.025"			'Pause 1 second to give time to position probe plate
	Code "F" &PFR 'User defined feed rate
'####### 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
	
	Code "G90 G0 Y" &YNew '	move back To the hit point incase there was an overshoot
	Code "G90 G0 Z.500"
   Code "G91 Y" &TipDia/2

	While IsMoving ()
	Wend
        Call SetDRO (1,0.000)
        Code "G4 P0.025"
        Code "G90 G0 X0.0"
	Code "F" &CurrentFeed 		'restore original feed rate
        Code "(X, Y, and Z axis' are now zeroed)"
        DoOEMButton (136) 'Remove tool Offsets
End If

Exit Sub
         

