zultron
Plastic
- Joined
- Dec 14, 2011
- Location
- Austin, TX
I'm adding new features to the rs274ngc G-code interpreter to make it more compatible with Fanuc and other controllers. One such feature is numbering the main or sub-program with e.g. O1, and adding the M98 and M99 codes. (By contrast, rs274ngc-flavored code allows no main program number, and sub-programs are defined with O1 sub...O1 endsub and called with O1 call.)
Smid 3rd Ed. offhandedly mentions on p. 384, "Subprogram Functions" section, para. 2:
On p. 488, Smid mentions the use case of a machine warm-up program where the program runs endlessly until the operator toggles block skipping, which enables a / M30 block. Another use case is in bar cutting.
My question for you experienced machine operators out there is, how is a main program distinguished from a subprogram? Consider the following example:
The G-Wizard guy explores endless loops at length in a tutorial; look about 40% down the page for the section "The G-Wizard CNC Editor Can Help You Debug Macros and Identify Infinite Loops". He says Mach3 prohibits endless loops, and
This seems to make sense in the tutorial's examples, where there is no O-word indicating the main program number. But those examples and others I can find (e.g. a Haas lathe manual) don't treat the case of the numbered main program.
I can see two ways to handle this:
1) Simply pick the first numbered program (O1 in the above example) as the main program. The Fanuc examples all seem to have subprograms following the main program. However, I don't know if this is a requirement, and the rs274ngc case isn't instructive, since O sub-style subroutines may come either before or (now that I unbroke a several-year-old regression) after.
2) Prohibit M99 terminating numbered programs. The controller would raise an error for the above example, and the example could be fixed by removing the O1 block.
Any suggestions?
Smid 3rd Ed. offhandedly mentions on p. 384, "Subprogram Functions" section, para. 2:
Although M99 is mostly used to end a subprogram, it may also
be rarely used in the main program, replacing the M30 function.
In this case, the program will run 'forever', or until the _Reset_
key is pressed.
On p. 488, Smid mentions the use case of a machine warm-up program where the program runs endlessly until the operator toggles block skipping, which enables a / M30 block. Another use case is in bar cutting.
My question for you experienced machine operators out there is, how is a main program distinguished from a subprogram? Consider the following example:
Code:
O1 (Main program)
(print, Main program 1: calling subprogram 2)
M98 P2
M99
O2 (Subprogram)
(print, Subprogram 2: returning to main program 1)
M99
%
The G-Wizard guy explores endless loops at length in a tutorial; look about 40% down the page for the section "The G-Wizard CNC Editor Can Help You Debug Macros and Identify Infinite Loops". He says Mach3 prohibits endless loops, and
Most g-code dialects, when faced with an M99 and no M98 having
called will simply start executing the very first line of g-code
at the top of the program again.
This seems to make sense in the tutorial's examples, where there is no O-word indicating the main program number. But those examples and others I can find (e.g. a Haas lathe manual) don't treat the case of the numbered main program.
I can see two ways to handle this:
1) Simply pick the first numbered program (O1 in the above example) as the main program. The Fanuc examples all seem to have subprograms following the main program. However, I don't know if this is a requirement, and the rs274ngc case isn't instructive, since O sub-style subroutines may come either before or (now that I unbroke a several-year-old regression) after.
2) Prohibit M99 terminating numbered programs. The controller would raise an error for the above example, and the example could be fixed by removing the O1 block.
Any suggestions?