Very nice, bobeson. It is a powerful tool, and I might have an immediate application for it, one I was just thinking about this afternoon. Thank you for this!
Randy
Hi Folks, I just posted an article in the gcode forum describing how I am using conditional code execution in Mach with my Tormach for complex multi-part fixturing, among other uses.
You can read the long-winded posting here:
Condition gcode execution is possible in Mach3
The abbreviated version is this:
Set a binary flag (0 or 1) depending on your condition, then multiply this flag by the intended subroutine label on the M98 line to either execute the subroutine or to execute subroutine 0, which is coded to return immediately. This is an example of an if-then clause. An if-then-else clause can be constructed by adding the flag to a base label number. If the flag is clear, the base subroutine is called, if it is set then a different subroutine label is called (base+1).
Example:
Code:#5 = 0 (this enable flag must be 0 or 1) M98 P[ #5 * 20 ] ( if( #5 is 1 ) then call sub 20, else nothing ) M98 P[ #5 + 21 ] ( if( #5 is 1 ) then call sub 22, else call sub 21 ) M30 O0 (do nothing subroutine) M99 O20 (operation subroutine) ... (do stuff) M99 O21 (flag clear subroutine) ... M99 O22 (flag set subroutine) ... M99
Very nice, bobeson. It is a powerful tool, and I might have an immediate application for it, one I was just thinking about this afternoon. Thank you for this!
Randy
I've always wondered about doing something like this. Thanks for the great info, I know I can use it to clean up some of my current files.
What kind of application would one ever use a conditional statement in the CNC world? I'm new to the CNC stuff and I'm sure this question shows it. lol
I realized my change could actually be done in the postprocessor.
My primary spindle tools 1-99, Proxxon tools are 100 and up. At the toolchange, I normally have M998 to raise the head to toolchange position. As this is excessive for Proxxon toolbits, I have been hand-replacing M998 with G00 Z3.0000 in the gcode when I'm using the Proxxon (separate thread for TTS-type operation with the Proxxon).
But now in the Sheetcam postprocessor, I have a test for the tool number, and write the appropriate line to the file.
Still credit to bobeson for the inspiration.
Randy