I've been using tensaiteki's touchoff routine with retry's for some time with great success. One problem i've been having is if the probe switch sticks on complicated part nests with hundreds of starts, G38.2 will stop the program if the probe is closed when its called. Its difficult to jump back in to a nest like this....
I've added an additional M66 and if statement that checks if the probe is contacted before G38.2 is called. This allows the opportunity to service the issue before G38.2 aborts the program. Important to know, add a hal connection linking the probe input to digital input 1. (Ex "net probe-in <= motion.digital-in-01 <= parport.0.pin-10-in-not")
Code:
o<touchoff> sub
(#1 pierce height, #2 pierce delay, #3 cut height)
#<arc-fails> = 0
F20
o100 do
M66 P1 L0 Q0 (Wait 1 second to see if probe is already closed)
o400 if [#5399 EQ 1]
(MSG, Contact already closed before calling G38.2!)
G0 Z2.0000
M0
o400 endif
G38.2 Z-1.250 (Probe to find the surface)
G91
G1 Z0.020 (Raise up to Z0)
G90
G92 Z0 (Set Z0)
G1 Z#1 (Raise to pierce height)
M3 S1 (Fire torch)
M66 P0 L1 Q2 (Wait 2 seconds for Arc OK from Torch)
o200 if [#5399 EQ -1] (Check to see if torch failed to fire)
M5
#<arc-fails> = [#<arc-fails> + 1]
o300 if [#<arc-fails> GT 3.0000] (Check if torch has failed 4 times in a row)
Z2.0000 (raise torch high enough to change consumables)
(MSG, Change Consumables!)
#<arc-fails> = 0 (reset arc failure counter)
M0 (pause)
o300 endif
o200 endif
o100 while [[#5399 EQ -1]]
G4 P#2 (Pause for pierce delay)
F25
Z#3 (goto cut height)
o<touchoff> endsub
M2