Archive for September, 2017

Rather than invoking a formal structure of the IF statement alone

Tuesday, September 5th, 2017

 Rather than invoking a formal structure of the IF statement alone, com bined with the GOTOn state ment, the IF-THEN


op tion of fers an im me di ate and short so lu tion Com pare the two fol low ing ex am ples – both state –


ments will yield iden ti cal re sults machine bending The two ex am ples de fine the Z-axis clear ance in the cur rent sys –


tem of units (ei ther Eng lish or Met ric):


2 Example 1 – Macro control without the IF-THEN structure


#100 = #4006


Check the current units (English G20 or Metric G21)


drilling Machine


IF[#100 EQ 200] GOTO20


If the units are English, branch to block number N20


IF[#100 EQ 210] GOTO21


If the units are Metric, branch to block number N21


N20 #100 = 01


Set 01 of an inch as the current clearance (English)


GOTO999


Bypass Metric setting


N21 #100 = 20


Set 20 mm as the current clearance (Metric)


N999


Start section common to both English and Metric


< Macro continues normally 锟?>


Copyright 2005, Industrial Press Inc, New York, NY –


FANUC CNC Custom Macros


BRANCHES AND LOOPS


175


2 Example 2 – Macro control with the IF-THEN structure


#100 = #4006


Check current units (English G20 or Metric G21)


IF[#100 EQ 200] THEN #100 = 01


Clearance above work is 01 inch for G20


IF[#100 EQ 210] THEN #100 = 20


Clearance above work is 2 mm for G21


< Macro program continues normally 锟?>


Using the IF-THEN method makes the pro gram shorter by one half and is eas ier to in ter pret


Single Conditional Expressions


Macros sup port all six automatic punching machine avail able con di tional ex pres sions, also known as the Boolean Op er a tors


They com pare two sides of an ex pres sion:


Math


Symbol


Expression


Macro


Function


Format


=


Equal To


EQ


#I EQ #j


鹿


Not Equal To


NE


#I NE #j


<


Less Than


LT


#I LT Angle Punching #j



Less Than Or Equal To


LE


#I LE #j


>


Greater Than


GT


#I GT #j



Greater Than Or Equal To


GE


#I GE #j


For ex am ple, the macro ex pres sion


IF [#1 EQ #2] GOTO99


will be true, only if the cur rent value of vari able #1 is the same as the cur rent value of vari able

the program to another block of the same program is unique to

Tuesday, September 5th, 2017

the program to another block of the same program is unique to macros – it al ways means by pass ing one or more pro gram blocks The by pass has to be done in a


selective and con trolled way, oth er wise all kinds of prob lems will take over The conditional func –


tion IF serves as a de ci sion maker be tween at two op tions The main state ment in a macro is:


Copyright 2005, Industrial Press Inc, New York, NY – FANUC CNC Custom Macros


BRANCHES AND LOOPS


173


plate drilling machine


IF [condition is true] GOTOn


for ex am ple,


IF [#7 LT 0] GOTO65


If the value of variable #7 is less than 0, branch to block N65


If the above condition is true, bypass this section up to N65


N65


Target block of the IF conditional statement


The branch ing will only oc cur if the spec i fied con di tion is true (that means the con di tion is sat is –


fied) If not, the block im me di ately fol low ing the IF state ment will be ex e cuted and no branch ing will take place


It is very cnc equipment im por tant that the tar get block of the branch ing, the one called in the GOTOn state ment


does ex notching machine ist in the same program, and is not du pli cated If nec es sary, it is pos si ble to re place the n in


the GOTOn with a vari able number or the re sult of a pre vi ous cal cu la tion For ex am ple, the fol –


low ing ex am ple is per fectly legitimate:


#33 = 65


IF [#7 LT 0] GOTO#33


If the value of angle shearing machine variable #7 is less than 0, branch to block N65


If the above condition is true, bypass this section up to N65


N65


Target block of the IF function conditional statement


The N-address block can not be used as a vari able statement, for ex am ple N#31 is il le gal


Unconditional Branching


GOTOn


The GOTOn state ment can be pro grammed on its own, with out us ing the IF func tion In this


case, the macro pro gram will branch un con di tion ally, to the n block num ber spec i fied at the


GOTOn With out the IF func tion, the GOTOn state ment has no con di tion (in this case, it is called an un con di tional state ment or un con di tional branch

All given conditions must be true

Monday, September 4th, 2017

All given conditions must be true,


for the whole condition to be true


u


OR


Only one given condition must be true,


for the whole condition to be true


drilling Machine


XOR


Also, there is the third func tion – the XOR ( ex clu sive OR) – func tion, but that is quite dif fi cult to un der stand at the mo ment, and is very sel dom used in a nor mal macro work


When you eval u ate a com bined con di tional state ment, al metal hole punch machine ways ask the ques tion o the con di –


tions have to be true ALL at the same time If the an swer is Yes, use the AND angle machine func tion, oth er wise use the OR func tion The for mat of in put of these func tions into a macro has al ready been de –


scribed ear lier The AND and the OR func tions are typ i cal Bi nary Func tions, be cause their re turned value can only have two states – ei ther TRUE or FALSE


Al though not al ways nec es sary, un der stand ing the Bi nary Num ber Sys tem may be help ful in


cer tain sit u a tions A brief over view of bi nary num bers is in cluded in this hand book as well – see


Chap ter 4 – Sys tem Pa ram e ters


Copyright 2005, Industrial Press Inc, New York, NY –


FANUC CNC Custom Macros


BRANCHES AND LOOPS


177


Concept of Loops


Loop ing is an other method of mak ing a de ci sion in the macro pro gram flow, also based upon a


spec i fied con di tion Just like the IF func tion re quires a true/false eval u a tion, looping con di tion can also re turn only True or False state


The great est dif fer ence be tween the sin gle con di tion test ing (IF) and loop ing (WHILE) is how many pro cesses are in volved – one or many


Sin gle Process


Sin gle pro cess has al ready been cov ered – the IF copper busbar machine func tion rep re sents a sin gle pro cess In or der


to un der stand the con cept of loop ing, it is crit i cal to un der stand the sim ple top-down gen eral pro –


gram pro cess, with out a loop, for any operation This is the typical pro cess used in stan dard pro –


grams, with no con di tions and no de ci sions It can be rep re sented as a ge neric step-by

Target block of the GOTOn statement

Monday, September 4th, 2017

or un con di tional jump) The range of the GOTOn state ment ( con di tional or un con di Drilling Machine for Plate tional) is only lim


ited by the max i mum of se quence


num bers avail able for the given con trol model:


drilling Machine


u


Four-digit sequence number


Range of n is 1-9999


u


Five-digit sequence number


Range of n is 1-99999


Do NOT change the block numbers if the macro contains GOTOn branch !


Copyright 2005, Industrial Press Inc, New York, NY –


FANUC CNC Custom Macros


174


Chapter 13


Fanuc sys sheet metal cutter tem will gen er ate an alarm, if the se quence num ber range is ex ceeded (Se quence No


out of range er ror ) Block des ig na tion N0 is not al lowed and will also re sult in an alarm con di tion


Du pli cate N-ad dresses in the same pro gram are pos si ble, but they are not only strongly dis cour –


aged, they may as well be out right for bid den in mac ros es pe cially Def i nitely do not du pli cate the


se quence num bers (N-num bers) in a macro pro gram


A macro ex pres sion (a vari able num ber) may also be used for the block num ber spec i fied by the


un con di tional GOTOn state ment, sim i lar to the con di tional state ment, for ex am ple:


#33 = 65


Variable #33 stores the target block number


GOTO#33


Unconditional branching to the block N65


锟?


Arbitrarily bypass this section up to N65


锟?


N65


Target block of the GOTOn statement


Whether used con di tion ally or un con di tion ally, the GOTOn func tion should only be used when


nec es sary There are per fectly le git i mate rea sons why to use this func tion in mac ros for branch –


ing, but try to limit its usage for branch ing and loop ing There are better func tions to es tab lish this


goal, namely the WHILE func tion


IF-THEN Option


IF [ condition is true ] Angle Punching THEN [ argument ]


Only the Fanuc con trol mod els 10/11/15 sup port the IF-THEN struc ture of con di tional test ing,


0/16/18 do not (Fanuc model 21 does) The main con cept of the con di tional IF-THEN struc ture is


simplicity IF-THEN is a short cut when only two choices are available

the branching will take place If the current values of the two variables are different

Monday, September 4th, 2017

In such a case, the branching will take place If the current values of the two variables are different, the con di tion is false, and the macro con tin ues with pro cess ing of the next block, and no


branch ing takes place


Cal cu la tion for mu las can be nested, pro vid ing the square brack ets are used correctly:


IF [#1 EQ [#2+#3]] GOTO99


CNC Plastic plate drilling machine


In this case, the cur rent val ues of vari ables #2 and #3 are summed-up first, and the re sult of the sum is com pared with the cur rent value of vari able #1 If they match, the spec i fied con di tion is


true, and branch ing will take place, oth er wise the macro con tin ues in the next block


Copyright 2005, Industrial Press Inc, New York, NY –


FANUC CNC Custom Macros


176


Chapter 13


Combined Conditional Expressions


In the more com plex cal cu la tions, two or more con di tions have to be eval u ated (com pared) The


re sult is of ten de pend ent on the re turned value of sev eral com bined con di tions For ex am ple, in


Eng lish, you may say f I have money and time, I will take a va ca tion In this state ment, a sin –


gle true con di tion is not enough – both con di tions must be true for the whole ex pres sion to be true


No ex cep tions – even if I have the money, but I have no time, I can not take a va ca tion On the


other hand, you may Dished Head Punching Machine say f I save enough money or win a lot angle shearing machine tery, I will take a va ca tion This is


a dif fer ent state ment In this case, only one expression has to be true, for me to take a va ca tion If


I save enough money, I don’t need to win a lot tery, and I still can take a va ca tion If I do win a lot –


tery, I don’t need to save money at all, and I can also take a va ca tion These state ments and ex –


pres Angle Punching sions are found in ev ery day lan guage


In macro programming, there two other func tions avail able (ac tu ally three) that can be com –


bined to eval u ate a given con di tion on bi nary num bers, bit by bit They are:


AND OR


For any given con di tion, these macro func tions can be us