Sub Probe(CurrentToolNum) 'The tool change and probing sub-routine
XPos = 12 'X-M.C. of the fixed touch plate
YPos = 612
ZPos = 154 'Y-M.C. of the fixed touch plate
ZProbeStart = -100.00 'Z-M.C. Height above fixed touch plate, where the probing starts
ZProbeMax = -165.00 'Z-M.C. The probe is supposed to touch, before this depth is reached. If if does it's an error, or tool is not in spindle.
ZRetract = 2.00 'Must be a positive value! Number of units to retract the Z-axis between 1.st and 2.nd probe sequence
ProbeFeed1 = 300 'Feed of the first probe run
ProbeFeed2 = 50 'Feed at the second probe run, to get a more precise measurement
XYZFeed = 850
CurrentFeedRate = GetOEMDRO(818) 'Read the current feed rate
Code "G01 F" & XYZFeed
Code "G53 G00 Z" & ZPos
Code "G53 G00 X" & XPos & "Y" & YPos 'Move tool over the touch plate location
While IsMoving
Sleep(100)
Wend
SetOEMDRO(802, 0.0000) 'Reset the Z-axis Work DRO to 0.0, now both M.C. and work coordinates are 0.0
Sleep (250) 'Wait for DRO to update
'---First probe run---
Code "G53 G00 Z" & ZProbeStart 'M.C. Rapid down to probe starting position
While IsMoving
Sleep(100)
Wend
Code "G01 F" & ProbeFeed1 'Change the feedrate
Code "G31 Z" & ZProbeMax 'Do the actual probing, at 1.st feed rate.
While IsMoving() 'Wait for probing to finish.
Wend 'End of while loop
ProbeDist = GetVar(2002) 'Read the z-axis value of probe touch point
'---2.nd probe run with reduced speed---
Code "G00 Z" & ProbeDist + ZRetract 'Retract "ZRetract" units before starting 2.nd probe
Code "G01 F" & ProbeFeed2 'Change the feedrate
Code "G31 Z" & ZProbeMax 'Do the actual probing, at 2.nd feed rate.
While IsMoving() 'Wait for probing to finish.
Wend 'End of while loop
ProbeDist2 = GetVar(2002) 'Read the z-axis value of probe touch point
SetToolParam(CurrentToolNum,2,ProbeDist2+150) ' Set Current Tool number, with parameter 2 = Z offset, to the ProbeDist + 150)
End Sub