S and NO represent
S and NO represent
DRILL THE HOLE
TRUE and FALSE
conditions respectively
Copyright 2005, Industrial Press Inc, New York, NY –
FANUC CNC Custom Macros
BRANCHES AND LOOPS
179
WHILE Loop Structure
In Fanuc type macro pro gram ming, the WHILE func tion is used to pro gram loops The for mat
of the loop ing func tion WHILE con sists of the func tion, con di tion and ac tion:
WHILE [condition] DOn
In a plain lan guage terms, think of the WHILE func tion as the ‘as-long-as’ func tion The loop –
ing func tion WHILE [con di tion[ DOn in a Fanuc macro lan guage means ‘pro cess the body of
the loop as long as the spec i fied con di tion is true’ The DOn ac tion es tab lishes the con nec tion with the end of the loop, where the n is re placed with a num ber of the match ing ENDn state ment The
loop is pro grammed with the ENDn func tion that cor re sponds to the DOn call, for ex am ple, DO1
with END1, DO2 with END2, and DO3 with END3 Only three loop depths can be pro grammed
The three al lowed loop depths – of ten known in pro gram ming as the lev els of nest ing – have
three sim i lar forms:
o
Single level nesting
o
Double level nesting
o
Triple level nesting
As the num ber of nest ing lev els in creases, so does the pro gram ming com plex ity The ma jor ity
of loops for most macro ap pli ca Dished Head Punching Machine tions are sin gle level, dou ble lev els are angle shearing machine not too un usual ei ther Tri –
ple level has a lot of power, but it does need a suit able ap pli ca tion to em ploy it
Single Level Nesting Loop
Pro gram ming only a single WHILE loop func tion be tween the WHILE-DOn loop call and its
matching ENDn, de fines the punching machine sin gle level loop This is the sim plest and most com monly used loop –
ing func tion used in macro pro grams The sin gle level loop pro cesses and con trols one event at the
time – Fig ure 22:
WHILE [ Condition 1 is true ] DO1
Start of WHILE loop 1
< Body of a single level loop >
END1
End of WHILE loop 1
Figure 22
Single level of macro looping – controls one event at the ti