Statements for influencing NC program flow
A complete list of G functions is contained in the overview of commands in the Appendix under Control block statements ($..).
The syntax for control block statements is: |
$<statement> |
<statement> | Control block strings as described in Section Conditional jumps. Note that between $ and <statement> no blank characters are permissible. |
Statements for influencing program flow (control blocks) permit the implementation of:
- Conditional jumps, e.g. to trigger optional machining steps depending on a measured value
- Incremental digital loops to simplify the programming of several repetitive machining steps, e.g. for line milling or for drilling hole circles
- Loops with running condition to allow the repetition of several machining steps until the abort condition is fulfilled. For example, if the infeed of the tool and a machining operation are to be carried out until a definite coordinate value is reached. Loops may be programmed as endless loops if a running condition is missing or not fulfilled.
The following rules apply for the use of control blocks:
- Only one control block may be present in one NC block.
- Control block statements may be nested. The nesting depth is fixed.
- Only the block number and "/" may be programmed in front of the control block.
- In the invalid branch of a control block statement, a syntax check is performed for block numbers and other (nested) control block statements (see examples of IF-ELSE branching).
Programing Example
Syntax check in an invalid branch:
N10 $IF 0
N20 XY (Here no syntax check takes place)
N30 $ENDIF
N10 $IF 0
N20 ...
N30 $IF XY (Syntax check due to nested control block statement;)
(error message due to unknown term)
N40 ...
N50 $ENDIF
N60 $ENDIF
N10 $IF 0
NXY (Syntax check of block number;)
(error message due to unknown term)
N30 $ENDIF
Due to inaccuracies in the calculation and the internal representation of parameters, comparative operations (see Section Arithmetical expressions <expr>) in control block statements may lead to an erroneous result. Therefore in cases of doubt, check for a tolerance range instead of for precise values.
Programing Example
WRONG:
N10 $FOR P1 = 0, 10, 1
N20 P2 = P2 + 0.01
N30 $ENDFOR
N40 $IF P2 == 0.1 (Due to inaccuracies of calculation P2)
N50 ... (may be unequal to 0.1 so that the $ELSE)
N60 $ELSE (branch is executed)
N70 G04 X20
N80 $ENDIF
RIGHT:
N10 $FOR P1 = 0, 10, 1
N20 P2 = P2 + 0.01
N30 $ENDFOR
N40 $IF ABS[P1 – 0.1] <= .000001 (Check a tolerance range for)
N50 G04 X5 (unproblematic NC machining)
N60 $ELSE ($IF branch is)
N70 ... (executed)
N80 $ENDIF