I modified the macro that's been updated a few times in this thread to be a little more robust.
It does a few more checks like "Is the spindle running" and forces the probe to be touched to the tool before it will start (to verify the probe is working). I like this better because I can take my time getting to the table (up to a set amount) after I hit the button and the probe starts shortly after I verify it.
I hope someone finds this useful.
Code:
' Program to automatically zero the Z-axis using a contact plate of known thickness positioned
' on top of the X-Y plane at the Z zero position. Cutting tool acts as a probe.
' Operation steps:
' 1. Get current state (Feedrate, G90/G91, G0/G1, Plate Thickness, and Starting Point)
' 2. Check if probe is grounded. Restore state and exit if it is.
' 3. Check if spindle is running. Give option to abort if it is.
' 4. Wait for probe to be manually touched to the tool.
' This verifies the probe connection and the tool moves after the number of seconds set in "DelayTime".
' If the probe is not activated within the number of seconds set in "VerifyTimeout" the program restores the state and exits.
' 5. Move probe down at a rate of "ProbeFeed" until "ProbeDist" is reached, set Z-DRO and retract the distance set in "Retract"
' If "ProbeDist" is reached before the probe is contacted, the state is restored and the Z-DRO is left unset
' Last updated: 12/20/09
' Author: Christopher Esser (Smokingman). Based on the work done by Greolt
' Define fixed parameters (Currently in Inches. Set to Metric if needed)
ProbeDist = "-1.0" 'Set the maximum distance to move the Z-axis before probe touches contact plate.
ProbeFeed = "10" 'Set the plunge speed for the probe
DelayTime = "1" 'Set the delay time in seconds from probe verify to start of Z-motion
VerifyTimeout = "10" 'Set timeout to wait for probe verify in seconds
Retract = "1" 'Set distance to retract after probe
' Declare Global Variables
Dim CurrentFeed
Dim CurrentAbsInc
Dim CurrentGmode
Dim PlateThickness
Dim StartingPoint
' Begin the Program
Call GetState
Call doProbe
Call RestoreState
' Get the Starting states
Sub GetState()
CurrentFeed = GetOemDRO(818) ' Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) ' Get the current G90/G91 state (Abs Coordinate Mode)
CurrentGmode = GetOemDRO(819) ' Get the current G0/G1 state
PlateThickness = GetUserDRO(1151) ' Read contact plate thickness DRO
StartingPoint = GetOemDRO(85) - GetOemDRO(832) ' Get starting Z position in work coordinates (Z Machine Coord DRO - Z Fixture Orig Off DRO)
End Sub
' Restore the states
Sub RestoreState()
Code "F" &CurrentFeed ' Returns to prior feed rate
If CurrentAbsInc = 0 Then Code "G91" ' If G91 was in effect before then return to it
If CurrentGMode = 0 Then Code "G0" ' If G0 was in effect before then return to it
End Sub
' Probe routine
Sub doProbe()
' Check to see if the probe is already grounded or faulty
If isActive(DIGITIZE) Then
MsgBox "Ground fault in probe detected. Fix probe and try again. "
Exit Sub
End If
' Check to see if the spindle is running
If GetOemLED(11) Then
Begin Dialog SindleOn 16,32,180,96,"Spindle Running!"
OKButton 132,8,40,14
CancelButton 132,28,40,14
Text 12,8,120,40,"It appears the spindle is running! Select 'OK' to continue anyway or 'Cancel' to exit."
End Dialog
Dim Dlg1 As SindleOn
Button = Dialog (Dlg1)
If Button=0 Then
Code "(Auto Tool Zero Aborted!)"
Exit Sub
End If
End If
' Verify probe connection and signal start of Z-Motion
StartTime=Timer
ProbeVerified=0
Code "(Touch probe to tool to verify connection)"
Do Until (Timer-StartTime >= Val(VerifyTimeout))
If isActive(DIGITIZE) Then
ProbeVerified=1
Beep ' Signal probe verify
Exit Do
End If
Loop
If (ProbeVerified=0) Then
Code "(Probe Timeout)"
MsgBox "Probe verify timed out. Fix Probe and try again"
Exit Sub
End If
'Start the actual probe
Code "G4 P" &DelayTime ' This delay gives me time to get from computer to hold probe in place
Code "F" &ProbeFeed ' Set the probe plunge speed
Beep ' Signal start of Z movement
Code "G91 G31Z" &ProbeDist ' Probing move using incremental move mode.
While IsMoving() ' Wait while it happens
Wend
ZProbePos = GetVar(2002) ' Get the axact point the probe was hit
If (ProbeDist+StartingPoint = ZProbePos) Then ' No contact was made during plunge
Code "(Probe failed!)"
Exit Sub
End If
Code "G90 G0 Z" &ZProbePos ' Go back to that point. Always a very small amount of overrun.
While IsMoving ()
Wend
Call SetOEMDRO (802, PlateThickness) ' Set the Z axis DRO to whatever is set as plate thickness
Code "G0 Z" & Retract ' Retract
While IsMoving ()
Wend
Code "(Z axis is now zeroed)" ' Success!
End Sub