585,759 active members*
3,910 visitors online*
Register for free
Login
IndustryArena Forum > MetalWorking Machines > Tormach Personal CNC Mill > Conditional gcode execution in Mach3
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2006
    Posts
    134

    Conditional gcode execution in Mach3

    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:
    http://www.cnczone.com/forums/showthread.php?t=94727

    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

  2. #2
    Join Date
    Feb 2006
    Posts
    1072
    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

  3. #3
    Join Date
    Mar 2005
    Posts
    140
    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.

  4. #4
    Join Date
    Feb 2009
    Posts
    87
    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

  5. #5
    Join Date
    Mar 2005
    Posts
    140
    Quote Originally Posted by banctecbobn View Post
    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
    For me the best use is if I'm making a batch of 20-50 items in one run and want some of them to be slightly different. For example if I want a third to have one company logo and the other 2 thirds to have no logo.

  6. #6
    Join Date
    Feb 2006
    Posts
    1072
    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. :cheers:

    Randy

Similar Threads

  1. Condition gcode execution is possible in Mach3
    By bobeson in forum G-Code Programing
    Replies: 2
    Last Post: 12-05-2009, 08:20 PM
  2. Conditional loop problem
    By eagle73 in forum Controller & Computer Solutions
    Replies: 0
    Last Post: 12-19-2008, 11:14 PM
  3. Replies: 7
    Last Post: 12-14-2006, 07:33 PM
  4. Shoptask CNC Lathe and Mach3: Gcode delima
    By KaptainKarst in forum Shopmaster/Shoptask
    Replies: 20
    Last Post: 08-05-2006, 11:55 PM
  5. Does Mach3 tool diameter override gcode setting?
    By WarrenW in forum Mach Software (ArtSoft software)
    Replies: 1
    Last Post: 04-27-2006, 02:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •