GRBL Plasma w THC, Torch Touchoff, and Rotary

update version 25.7

25.1 prologue comments fixup
25.3 change default THC dynamic on/off cmd to allow continuous XY motion during state changes.
25.4 remove LdcAdcOFF flag and instead reset LdcAbsCutHeight, adj OnNewEntity() header comments.
25.5 added two machine pause cmds in Bench Test gcode so I don’t use it to cut by mistake!
25.6 changed per-cut torch probe cycle from 2 probes to 1, 1/2 the time,
while maintaining same probe accuracy of +/- 0.025mm or accuracy of Z axis
25.7 added LdcPauseOnNewPart boolean option

A few versions prior I had made changes to the dynamic THC on/off gcode, moving it to Path Rules. However, 2 of the gcodes (M7 and M9) for my THC Anti-Dive Circuit (ADC) (which has the side effect of also managing the effective THC on/off state) will cause the XY motion to pause/stop during a cut, albeit just a 0.1ms of a pause/stop, the reason being that grbl is synchronizing the M7/M9 with the exact XY position in which it was placed by Path Rules. This can cause a dimple in the cut edges of the kerf, not good. I had forgotten about this motion pausing side effect.

So to fix it and have continuous XY motion while also changing THC on/off state, I changed to a similar method that I used a few versions back and cleaned up the logic a bit. This method uses spindle speed (S0 for OFF, and S1000 for ON) as the dynamic THC on/off during XY motion, in Path Rules at anytime and when Z arrives at cutHeight during a pierce. This works in a continuous motion due to grbl laser mode $32=1, and when using M4 (spindle enable signal from MCU) to fire the torch, then spindle speed (S-PWM signal from MCU) is proportionally varied automatically by grbl to the realtime XY motion speed, accounting for acceleration and deceleration. My Z THC ADC uses S-PWM to dynamically block or pass the THC Z motion signals, so below 85% of feedrate due to deceleration, the circuit blocks the THC trying to adjust Z to the plasma arc voltage deviation, and then passes the THC signals to Z when later accelerating and feedrate is > 95%. So to ‘manually’ or programmatically manage this circuit, I can force S-PWM to zero (S0) to always block the THC signals, or full on (S1000) to allow the circuit to function automatically again. Grbl’s laser mode operation is that IF spindle speed is changed while ALSO processing a motion gcode XYZorA (called a motion block), then motion will remain continuous while spindle speed changes immediately. Lasers can respond to this instantaneous S-PWM signal change, but mechanical spindles cannot, so in $32=0 (non laser mode), then motion will pause for a spindle speed change, but again only for 0.1ms to process the Snnnn stmt, same as it does for M7/M9 stmts. If an actual mechanical spindle were being used, you’d want to insert a G04 P5 or so also to allow the spindle time to change speed. The final condition that makes the scheme work in plasma cutting with a THC and my Z ADC, is that my Proma THC SD unit is configured to delay Z motion control for 2.5 seconds, that’s enough time for the pierce to occur and for grbl to move Z from PH to CH. That is why I pierce with a M4 S1000 cmd.

here’s a link to the THC Z Anti-Dive Circuit schematic: bC THC Z Anti-Dive circuit.jpeg - Google Drive
and grbl laser mode explained: Grbl v1.1 Laser Mode · gnea/grbl Wiki · GitHub
GRBL plasma LDC w Rotary.scpost (41.9 KB)
LDC SC tools and rules.tools.txt (9.62 KB)