'Z Zero Probe Script 20180215 KOU
'Place the Z Probe on top of the stock
'Z = 0 will be set on top of the stock after the routine finishes successfully
Option Explicit
Dim ZProbeThickness As Double
Dim ZProbePos As Double
Dim MaxMove As Double
Dim ZRetract As Double
ZProbeThickness = 19.1 'Init Z Probe thickness in mm
MaxMove = -30.0 'Init the maximum distance the Z Axis will move
during G31
ZRetract = 30.0 'Init Z Retract Height in mm. OBS: must be
lager than Probe Thickness
If GetOemLed(825)=0 And ZRetract > ZProbeThickness + 5.0 Then 'If the Z Probe is
grounded then skip the Z Zero routine
DoOEMButton(1010) 'Zero Z Axis. The Z axis will start to move
from this position
Code "G4 P0.5" 'Wait 0.5 sec before routine continues
Code "F100"
Code "G31 Z" &MaxMove 'Straight Probe Move, Z Axis will start to
move MaxMove down or
'until it touches Z Zero Probe at Speed F*********
While IsMoving() = 1 'Wait until Z Axis touches the Z Zero Probe
Sleep(50) 'Sleep in 50ms to let the Z Axis advance
Wend
ZProbePos = GetVar(2002) 'Set ZProbePos = the exact Z position where
the Z Probe was hit
'Message "ZProbePos = " &ZProbePos 'Check and display ZProbePos
'Code "G4 P5" 'Wait so I can read the value
If ZProbePos > MaxMove + 0.5 Then 'Safety margin of 0.5mm so that Zero
Probe is within proper reach
Code "G01 Z" &ZProbePos 'Step back to this point as there might be
a slight overrun
While IsMoving() = 1 'Wait until Z Axis is at the exact Zero point
Sleep(50) 'Sleep in 50ms to let the Z Axis advance
Wend
SetOEMDRO(802, ZProbeThickness) 'Set the Z Axis DRO to the exact Z
Probe Thickness
'Message "ZProbeThickness = " &GetOEMDRO(802) 'Check and display
ZProbePos
'Code "G4 P5" 'Wait so I can read the value
Code "G4 P0.25" 'Wait for DRO to update
Code "F1000"
Code "G01 Z" &ZRetract 'Move the Z Axis up to ZRetract mm above
the Stock at Speed F*********
Message "Z Axis is zeroed at Stock Top" 'Write message in the status bar
Else
Speak "Error"
Code "G4 P1"
Code "F1000"
Code "G01 Z" &ZRetract 'Move the Z Axis up to ZRetract mm above
the Stock at Speed F*********
Message "Error: Router Bit started too high above the Z Probe!"
End If
Else
Speak "Error"
Message "Error: Z Probe is activated, Z Zero routine aborted!" 'Display error
message in Status Bar
End If