Some controls let you do an IF THEN, but I don't think you can do ELSE.
I get around it with a load of goto statements. Not elegant but it works.
Is it possible to do a statement such as an "IF THEN ELSE" in a main CNC Program to see if a subprogram already exists in the memory prior to doing a G65Pxxxx or M98 call. I want to skip past the subroutine program call if the subprogram doesn't exist - that then ensures the main program doesn't alarm out?
Some controls let you do an IF THEN, but I don't think you can do ELSE.
I get around it with a load of goto statements. Not elegant but it works.
G-Code is a rote (no intelligence) language. It has no decision making capability on it's own. It seems the only way this could be accomplished would be to build an interface to the specific controller that somehow would "receive" the neccesary feedback to trigger the software "exception" that it would need to handle. The major object to get past in this problem is the entity that is the "if" that you are concerned about testing. In another words, if you had a way of providing 2 way communications with applicable test
conditions, you could theoretically, do it by writing the code to issue the G-Code subroutines necessary to drive the CNC controller.![]()
Assuming your control will allow you to do IF THEN statements, all you need to do is find which variables are assigned to the program numbers (they do exist, you have to consult your machine's manuals to find out which variable is which).
Interested to know if you find a way to make this work - The variable the current program number is stored in is #4115, but I can't find any variables that tell you which program numbers are stored in the control (i.e. subprogs)
BTW, not all controls support IF THEN, but they might just support IF.
Fanuc 10/11/15 does, but Fanuc 0/16/18 doesn't.
Weird, but if not it means you'll need to do an IF THEN like this:
IF [#1NE2] GOTO 3
N2 (whatever you want to happen if #1 is 3)
N3 CARRY ON
The "Holy Grail" is the feedback mechanism whether it be a "software" variable or hardware "switch (typically binary {on or off}) that produces the trigger for some event to occur. Those lightbulbs will last a million years if nobody throws the "on" switch. I've seen some controllers that "assume" an event has occurred, and then base the program decision on that. To me, that is a dangerous assumption to make. You need to be absolutely positive in the actual versus expected results. IMHO.
Seems to me that you might run into a dangerous situation if you're arbitrarily running programs with or without some of the sub-programs..... But, some machines have parameters to control how sub calls are treated if the the program is not in the directory. Not sure on Mazaks or Mits....
It's just a part..... cutter still goes round and round....