(Part A) Machinerys Handbook 31st Edition Pages 1-1484

Machinery's Handbook, 31st Edition

1380 CNC SUBROUTINES AND MACROS Functions and Constants are also an important part of macros. Functions calculate something—they solve a mathematical calculation or a formula. For example, a “+” (plus) function will sum two or more values together. In addition to functions, constants can be defined in a macro as well, for example the pi ( π ) with the value of 3.14159265359 Logical Functions are used for branching and looping purposes. Looping and branching provide a change in the program flow that is based on a certain condition that has been pre­ viously defined. The given condition may be tested (evaluated), using the comparison functions, such as ‘greater than’ (), ‘equal to’, ‘less than or equal to’, and several others, used together with the IF function. They are called Boolean or logical operators. The given condition can be tested only once, using the IF checking function or it may be evaluated repeatedly, using the loop function WHILE—while the given condition is true, the loop is repeated. The result of the evaluation will determine further flow of the program. Macro Definition and Call.— Macros are defined in a similar way as subprograms, but they are called or invoked by the G65 command: O7001 (MACRO) Variable Definition (G65).— The G65 macro command accepts variable definitions, called arguments. Arguments are actual program values required for a particular macro only. They are passed to the macro. Variable data in the macro is then replaced with the supplied arguments. A typical program sample of a G65 macro using three arguments may have the following format: G65 P7001 A6.0 B8.5 F10.0 G65… Macro call command P7001… Program number containing the macro—stored as O7001 A6.0… Assignment of local variable A (#1) argument to be passed to macro B8.5… Assignment of local variable B (#2) argument to be passed to macro F10.0… Assignment of a local variable F (#9) argument to be passed to macro The illustration Fig. 31 shows graphically the flow between the main program and a macro, as well as the definition and use of the three variables (defined as arguments). In the example, a macro linear motion command will be replaced with the defined amounts: G01 X#1 Y#2 F#9 = G01 X6.0 Y8.5 F10.0 ... ... M99 %

START

(MAIN PROGRAM)

O7001 (MACRO)

G01 X#1 Y#2 F#9

G65 P7001 A6.0 B8.5 F10.0

% M30

M99 %

END

Fig. 31. Macro Call From Main Program. Assignment of macro variables as arguments is one of the most important parts of devel­ oping any macro. Macro B has an arbitrary list of variables (called Argument List 1 ) and their meaning, shown in the following table:

Copyright 2020, Industrial Press, Inc.

ebooks.industrialpress.com

Made with FlippingBook - Share PDF online