Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
51 views24 pages

Macro Programming B PDF

The MACRO B function is designed for programming complex parts and includes features like arithmetic operations, conditional branches, and variable assignments. Variables are categorized into local, common, and system types, with specific ranges and operations defined for each. The document also outlines how to use G65 for macro calls, the differences between macro and subroutine calls, and various programming constructs such as GOTO, IF, and WHILE for control flow.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views24 pages

Macro Programming B PDF

The MACRO B function is designed for programming complex parts and includes features like arithmetic operations, conditional branches, and variable assignments. Variables are categorized into local, common, and system types, with specific ranges and operations defined for each. The document also outlines how to use G65 for macro calls, the differences between macro and subroutine calls, and various programming constructs such as GOTO, IF, and WHILE for control flow.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

11.

MACROB
11 - MACRO B

The MACRO B function is used when one wants to work on the programming of parts.
complex, 'families of parts' and other special functions such as: arithmetic operations,
conditional branches, counter, comparison commands, etc...

This type of programming is done by assigning values to variables.

A program can invoke a MACRO using the G65 command for the call
from a sub-program..
Example:

MACRO MACHINING PROGRAM

O0001 (MAIN PROGRAM) O9130 (MACRO PROGRAM)


G17 G21 G90 G94 :
: #1=#18/2
: G01 G42 X#1 Y#1 F300
G65 P9130 R50 L2 G02 X#1 Y#1 R#1 :
: :
: M99
M30

Explanation:

When we define a variable, we specify a symbol (#) followed by the number


from the variable. Example: #1

An expression can be used to specify the number of a variable, in this


in case, the expression must be expressed in brackets.
Example: # [#1+#2-12]

11.1 - TYPES OF VARIABLES

The variables are classified into 4 types:

a) #0 - Always null, that is, no value can be assigned to this variable;


#1 - #33 - Local variables. Can only be used in macros to load data.
as a result of operations. When the command is initialized, the local variables are
initialized without values (null).
When a macro is invoked, values can be assigned to the local variables;
#100 - #149 (#199) / #500 - #531 (#999) - Common variables. They may be partially
among different Macro programs. When the command is turned off, the variables #100 to
#531 retains the last value that was assigned to them. Within the range of common variables.
we still have the variables #150 to #199 and #532 to #999;
#1000 - System Variables. They are used to read a series of NC data such as:
current position, tool compensation values, etc...

T22182C Programming and Operation Manual - Line D - CNC FANUC 0i-Mc 65


11. MACROB

11.2 - RANGE OF VALUES FOR THE VARIABLES

Local and common variables can have a value of = 0 or a value in the following range

-1047-10-29
10-29a 1047
If the result of the calculation is invalid, that is, it is outside this range of values, the
alarm 111 will be shown.

11.3 - OMISSION OF THE DECIMAL POINT

When a variable value is defined in a program, the decimal point can be


omitted.
Example: When #1=123 is defined, the real value of variable #1 is 123.000

11.4 - REFERENCING VARIABLES

To reference the value of a variable in a program, specify the address.


followed by the variable number. When an expression is used to specify a
variable, include the expression in brackets.
Example:
G01 X[#1+#2] F#3

A variable value is automatically rounded according to the minimum.


increment of the address
Example:
When G0 X#1 is programmed and the value of #1 is 12.3456, if the CNC displays a value
minimum programming of 0.001 mm, the command to be executed will be G0 X12.346.

Toreversethesignofavariable'svalue,programtheminussign(-).
Example:
G0 X-#1

11.5 - ARITHMETIC OPERATIONS AND LOGICAL OPERATIONS

The operations listed in the following table can be performed with variables.
The expression on the right of the operation can contain constants and/or combined variables.
for a function or operation.
The variables #J and #K can be replaced by a constant.
The variables on the left can also be replaced by an expression.

66 Programming and Operation Manual - D Line - CNC FANUC 0i-Mc T22182C


11. MACROB

11.5.1 - Table of arithmetic operations and logical operations

FUNCTION FORMAT
DEFINITION #I=#J

SOMA #I=#J+#K

DIFFERENCE #I=#J-#K

PRODUCT #I=#J*#K

QUOTIENT #I=#J/#K

NIPPLE #I=SIN[#J]

COSINE #I=COS[#J]

TANGENT #I=TAN[#J]

ARCTANGENT #I=ATAN[#J]/[#K]

SQUARE ROOT #I=SQRT[#J]

ABSOLUTE VALUE #I=ABS[#J]

ROUNDING #I=ROUND[#J]

ROUNDING DOWN #I=FIX[#J]

ROUNDING UP #I=FUP[#J]

OR #I=#J OR #K

XOR #I=#J XOR #K

AND #I=#J AND #K

BCD TO BIN CONVERSION #I=BIN[#J]


CONVERSION FROM BIN TO BCD #I=BCD[#J]

NOTE: A logical operation is performed on binary numbers bit by bit.

T22182C Programming and Operation Manual - Line D - CNC FANUC 0i-Mc 67


11. MACROB

Explanation:

ANGLE UNITS - The units of angles used with the SIN, COS functions,
TAN and ATAN are in degrees.
Example: 90°30' = 90.5°.

ATAN FUNCTION - After the ATAN FUNCTION, specifying the length of two sides
separated by a slash, a result is obtained where 0 < result < 360.
Example: When #1=ATAN[1]/[1], the value of the variable #1 is 135.

ROUND FUNCTION - When a rounding function is included in


an arithmetic or logical operation, the ROUND function rounds the first decimal place.
Example: When executing #1=ROUND[#2] where the variable #2 contains the value 1.2345,
The value for variable #1 is 1.

The rounding function approximates the specified value according to the increment.
minimum entry.
Example: A hurricane program that performs movement according to the values of
variables #1 and #2 and then return to the initial position.

Assuming that the system presents minimum increments of 1/1000mm, the variable
#1 contains the stored value of 1.2347 and variable #2 contains the stored value of
2,3456.
Here we have:
G00 G91 X-#1 Movement of 1.235mm
G01 X-2 F300 Movement of 2.346mm
* G00 X[#1+#2]

Considering that 1.2347 + 2.3456 = 3.5803, the actual distance of displacement will be 3.580.
Thus, the tool does not return to the initial position.
To ensure this return occurs, it must be scheduled:
* G0 X[ROUND[#1]+ROUND[#2]]

Example about the FUP and FIX functions.


1.2
When the command #3 = FUP[#1] is executed, the value 2 is assigned to the variable.
3. When the command #3 = FIX[#1] is executed, the value 1 is assigned to variable 3.
When the command #3 = FUP[#2] is executed, the value -2 is assigned to variable 3.
When the command #3 = FIX[#2] is executed, the value -1 is assigned to variable 3.

11.6 - OPERATIONAL PRIORITIES

1 - Functions
2 - Operations such as multiplication and division (*,/,AND)
3 - Operations such as addition and subtraction (+,-,OR,XOR)

68 Programming and Operation Manual - Line D - CNC FANUC 0i-Mc T22182C


11. MACROB
Example:
#2 + #3 * SIN[#4]

First resolution SIN[#4].


Second resolution #3*SIN[#4].
Third resolution #2+#3*SIN[#4].

11.7 - LEVELS OF RAILINGS

To modify the order of operations, square brackets [] should be used.


Brackets can be used up to 5 levels, including the brackets used for
close the expression. When a level of 5 brackets is exceeded, an alarm 118
will occur.

Example:
#1=SIN[[[#2+#3]*#4+#5]*#6]

1st operation [#2+#3]


2nd operation [#2+#3]*#4
3rd operation [[#2+#3]*#4+#5]
4th operation [[#2+#3]*#4+#5]*#6
5th operation SIN[[[#2+#3]*#4+#5]*#6]

11.8 - DEVIATION AND REPETITION

In a program, the control flow can be modified using the GOTO statement and
the IF statement for deviation and repetitions.
Three types of operations are used:

1st GOTO - unconditional jump


2nd IF conditional deviation: IF, THEN.
3rd WHILE - repetition: WHILE.

11.8.1 - Unconditional Jump - GOTO

Make a jump to sequence number N.


When a sequence number not between 1 and 99999 is specified,
an alarm 128 will be displayed.
You can also specify a sequence number using an expression.

GOTO N N - sequence number (1 to 99999)

Example:
GOTO500; (redirects to block N500)

T22182C Programming and Operating Manual - D Series - CNC FANUC 0i-Mc 69


11. MACROB
11.8.2 - Conditional deviation - IF

Specify a conditional expression after 'If'. If the conditional expression is


the true executes a branch to the sequence number N. If the conditional expression
if false, the following block is executed.

Example:
Ifthevalueofvariable#1isgreaterthan10,adeviationtothesequencenumberisexecuted.
N2.

it is false a IF [#1GT10] GOTO 2


condition if true a
processing condition
N2 G00 G91 X10

Explanations:

Conditional expression - A conditional expression must include an operator placed


between the variables or between a variable and a constant and must be enclosed in brackets.
An expression can be used instead of a variable.

Operators - Operators are formed by two letters and are used for comparison.
two values with the purpose of determining if they are equal or if one value is less than or greater than the other

what other value.

OPERATOR MEANING
EQ Equal to
NE Different from
GT Greater than
GE Greater than or equal to

LT Less than
THE Less than or equal to

Example program: Determine the sum of the numbers from 1 to 10.

O9100
#2=1 Initial value of variable #2=1
N1 IF[#2 GT10] GOTO2 - Jump to N2 if #2 is greater than 10
#2=#2+1 Incrementing the variable
GOTO 1 Divert to N1
N2 M30 End of the program

The values of the variables #2 at each step.


#2=2,3,4,5,6,7,7,8,9,10,11.

70 Programming and Operation Manual - D Line - CNC FANUC 0i-Mc T22182C


11. MACROB
11.8.3 - Repetition - WHILE

Specify a conditional expression after WHILE. While the condition


specified as true, the program will run from the DO statement until
the END statement. If the specified condition is false, the program continues to execute
in the block that follows the END declaration.

WHILE [conditional expression] DO (m=1,2,3)


if true
Processing the condition
is false
the condition :
:
ENDm
:
:

Explanation:

As long as the condition specified after WHILE is true, the program continues
being executed from the declaration DO to the declaration END.
If the specified condition is false, the program continues to be executed from the
block that comes after END.
A number after DO and a number after END are identification numbers.
to specify an execution range.
You must use the numbers 1, 2, and 3. When a number different from 1, 2, and 3 is used
Alarm 126 will be displayed.

11.8.4 - Routine levels using the WHILE function

Identification numbers from 1 to 3 in a DO-END deviation can be used.


as many times as desired. Note, however, that when a program includes repetition routines
intertwined (overlapping intervals) an alarm 124 will occur.
a) The identification numbers (1 to 3) can be used several times as
desired.

WHILE [.....] DO1


:
execution
:
END1
:
WHILE [.....] DO1
:
execution
:
END1

T22182C Programming and Operation Manual - Line D - CNC FANUC 0i-Mc 71


11. MACROB
b) We cannot overlap the intervals OF

WHILE [.....] DO1


:
execution
:
WHILE [.....] DO
:
END 1
:
execution
:
END 2

c) DO routines can be interwoven up to a maximum of 3 levels.

WHILE [.....] DO1


:
WHILE [.....] DO
:
WHILE [.....] DO3
:
execution
:
END3
:
END2
:
END1

The command can be transferred to an external routine.

WHILE [.....] DO1


:
IF [.....] GOTO n
:
END1
:
Nn

Deviations cannot occur at a point within the routine.

IF [.....] GOTO n
:
WHILE [.....] DO1
:
Nn
:
END1

72 Programming and Operating Manual - Line D - CNC FANUC 0i-Mc T22182C


11. MACROB
11.9 - LIMITS

When DOm is specified without specifying the WHILE declaration, it executes a


infinite routine that goes from DO to END.
Processing time: When a deviation is executed on a sequence number
specific in a GOTO statement, it looks for a sequence number.
For this reason, processing in the reverse direction (backwards) takes longer than
the processing in the direct sense (forward).
Using the WHILE statement for repetition reduces processing time.

11.10 - UNDEFINED VARIABLE

In a conditional expression that uses EQ or NE, a null variable and zero have
different effects. In other types of conditional expressions, a null value is considered
zero.

11.11 - MACRO CALL

You can invoke a macro program using simple call methods (G65)
it is a modal call (G66).

11.11.1 - Differences between macro calls and subroutine calls

The macro call (G65) is different from the subprogram call (M98) as
described as follows:
a) With G65, you can specify an argument (data passed to a macro), M98
does not allow doing it.
b) When an M98 block contains another command - e.g.: G01 X100 M98 P___ -; if
call the subprogram after executing the command. On the other hand, G65 calls
unconditionally a macro.
c) When an M98 block contains another command - e.g.: G01 X100 M98 P__ -; the machine
stop in block mode, on the other hand the G65 does not stop the machine.
d) With G65, the level of local variables varies, with M98 the level of local variables
does not vary.

11.11.2 - Simple Call (G65)

When G65 is specified, a macro is called at address P. The data


(arguments) can be transferred to a macro program.

Syntax:

G65 P____ L_____

Where:

P ___ ; program number that contains the macro


L ___ ; number of repetitions (1=default)

T22182C Programming and Operation Manual - Line D - CNC FANUC 0i-Mc 73


11. MACROB

Example:
O0001 O1000
G65 P1000 A1 B2 #3=#1+#2
M30 IF[#3 GT360] GOTO9
G0 G91 X #3
N9 M99

Explanations:

After G65, specify the address P with the program number that contains the macro.
When the number of repetitions is necessary, specify the number from 1 to 9999. When
if the number is omitted, the repetition will be unique. Using a specification of the argument if
assign values to the corresponding local variables.

11.12 - ARGUMENT SPECIFICATIONS

There are two types of argument specifications. The argument specification


I use different letters from G, L, O, N and P.
The specification of arguments II uses the letters A, B, C and also I, J, K up to ten.
times.
The type of argument specification is automatically determined by the letters.
used.
Example:

O0001 (MAIN PROGRAM - ARG. TYPE I) O1000 (MACRO)


G65 P1000 I0 J0 K0 D100 E50 F-20 H2 G0 X[#4] Y[#5]
M30 Z[#6+2]
WHILE [#6 GT #9] DO1
OR G1 Z[#6] F500
X[#7]
O0001 (MAIN PROGRAM - ARG. TYPE II) Y[#8]
G65 P1000 I0 J0 K0 I100 J50 K-20 J2 X[#4]
M30 Y[#5]
#6-#11
END1
M99

74 Programming and Operation Manual - Line D - CNC FANUC 0i-Mc T22182C


11. MACROB
11.12.1 - Specification of arguments I

ADDRESS VARIABLE NUMBER


A #1
B #2
C #3
D #7
E #8
F #9
H #11
I #4
J #5
K #6
M #13
Q #17
R #18
#19
T #20
U #21
V #22
W #23
X #24
Y #25
Z #26

NOTE:Addresses G, L, N, O, and Pcannot be used as arguments.


the addresses that are not used can be omitted, the corresponding local variables
to an omitted address are configured as null.

T22182C Programming and Operation Manual - Line D - CNC FANUC 0i-Mc 75


11. MACROB
11.12.2 - Merging of specifications of arguments I and II

ADDRESS VARIABLE NUMBER


A #1
B #2
C #3
I1 #4
J1 #5
K1 #6
I2 #7
J2 #8
K2 #9
I3 #10
J3 #11
K3 #12
I4 #13
J4 #14
K4 #15
I5 #16
J5 #17
K5 #18
I6 #19
J6 #20
K6 #21
I7 #22
J7 #23
K7 #24
I8 #25
J8 #26
K8 #27
I9 #28
J9 #29
K9 #30
I10 #31
J10 #32
K10 #33

NOTE: The subscripts I, J, K, to indicate the order of specification of


arguments are not registered in the program.

76 Programming and Operation Manual - Line D - CNC FANUC 0i-Mc T22182C


11. MACROB

11.13 - LIMITATIONS

Format: before any argument, G65 must be specified

Mix of specifications of arguments I and II: if there is a mix of arguments I and II


thetypespecifiedlasttakespriority.

Call levels: you can program call forwarding to a maximum of 4


levels. This does not include calls from a subprogram (M98)

11.14 - LEVELS OF LOCAL VARIABLES.

There are local variables from level 0 to level 4 for deviation programming. The
the level of the main program and zero.
Each time a macro is called with G65 or G66, the level of the local variable increases.
1. The values of the local variables from the previous level are stored in the CNC.
When an M99 is executed in a macro program, the command returns to the
program where there was a deviation. At this moment, the level of the local variable is decremented
in one unit. The values of the local variables stored will be restored when
a macro for call.

Program
Macro Macro Macro Macro
Principal

Level 0 Level 1 Level 2 Level 3 Level 4

O0001 O0002 O0003 O0004 O0005


#1=1 : : : :
G65 P2 A20 G65 P3 A45 G65 P4 A0.2 G65 P5 A50 :
: : : : G0 X[#1]
G4 X[#1] G1 X[#1]F.15 G0 Z[-#1] G1 X32 F[#1] (#1 = 50)
(#1 = 1) (#1 = 20) (#1 = 45) (#1 = 0.2) :
: : : : :
M30 M99 M99 M99 M99

NOTE: For each subprogram level, 33 variables can be used.


locations, that is, from variable #1 to #33.

11.15 - COMMON VARIABLES

#100 - , #500 - Variables that can be read and written by macros in different
levels.

T22182C Programming and Operating Manual - Line D - CNC FANUC 0i-Mc 77


11. MACROB
11.16 - MODAL CALL (G66)

The G66 function makes the calling of a specific macro modal until
that it be canceled by function G67.

Syntax:

G66 P___ L____ ......

Where:

P - subprogram number
L - number of repetitions

Explanations:
After specifying G66, program the address P with the program number that contains
a macro. When you want the number of repetitions, address L can contain a number
from 1 to 9999. Just like used in the G65 function, the data is transferred to a program
of macro through arguments.
Cancellation: When a G67 code is specified, calls are no longer excluded.
modals in the subsequent blocks.
Call levels: Calls can be specified using redirects of up to 4
levels including the modal calls.
Levels of modal calls: A modal call can be activated within other modal calls.
specifying another G66 code.
Limitations: In a G66 block, macros cannot be activated. G66 must be specified.
before any argument.
Local variables (arguments) can only be defined in G66 blocks.

Example:
O0001 (MAIN PROGRAM) O7999 (HURRICANE MACRO)
: G0 Z[#18]
T03 (HURRICANE) G1 Z[#26] F[#9]
M6 G0 Z[#18]
G54 S1800 M3 M99
G0 X0 Y0 M8 (#18 = R)
G43 Z10 H03 (#26 = Z)
G66 Z-15 R2 F0.1 P7999 (#9 = F)
X0 Y0
X100
Y50
Y0
G67
G53 G0 Z0 G49 M9
M30

78 Programming and Operating Manual - Line D - CNC FANUC 0i-Mc T22182C


11. MACROB

11.17 - PROGRAMMING EXAMPLES:

Below are some examples of the application of parameterized programming.

Example 1: Parameterized program to create a family of parts, according to the


drawing below:

O0001 (FAMILY 1) N220 M6


N10 #1=60 (LENGTH 1) N230 G54 S3500 M3
N20 #2=100 (TOTAL LENGTH OF THE PIECE) N240 G0 X-[#9+#14] Y-[#9+#14] M8
N30 #3=30 (WIDTH 1) N250 G43 Z[#11+#15] H3 D3
N40 #4=60 (TOTAL WIDTH OF THE PIECE) N260 G0 Z[#20]
N50 #5=5 (LARGE. OF BEVEL x 45 DEGREES) N270 G42 G1 X0 Y0 F[#10]
N60 #6=25 (RADIUS 1) N280 X[#1] ,R[#8]
N70 #7=7 (RADIUS 2) N290 X[#2] Y[#3]
N80 #8=20 (RADIUS 3) N300 Y[#4] ,C[#5]
N90 #9=20 (DIAMETER OF THE TOOL) N310 X[#6]
N100 #10=400 (ADVANCE) N320 G2 X0 Y[#4-#6] R[#6], R[#7]
N110 #11=0 (INITIAL Z) N330 G1 Y0
N120 #12=-20 (FINAL Z) N340 G40 X-[#9+#14]Y-[#9+#14]
N130 #13=2 (CUTTING DEPTH) N350 #20=[#20-#13]
N140 #14=5 (CLEARANCE FOR APPROXIMATION IN X AND Y) N360 IF [#16 EQ 1] GOTO420
N150 #15=5 (CLEARANCE FOR APPROXIMATION IN Z) N370 IF [ #20 GT #12 ] GOTO260
N160 #16=0 (RECOGNIZES LAST PASS) N380 #16=1
N170 #9 = #9/2 (CALCULATION OF FERRULE RADIUS) N390 G0 Z[#12]
N180 #20 = #11 - #13 (COORD. 1A. PASSED) N400 GOTO270
N190 G17 G21 G90 G94 N410 G0 Z[#11]
N200 G53 G0 Z0 G49 N420 G53 G0 Z0 G49 M5
N210 T3 N430 M30

T22182C Programming and Operation Manual - D Series - CNC FANUC 0i-Mc 79


11. MACROB

Example 2: Parameterized program to create a subroutine without using the resource


of subprogram:

O0001 (PECA WITH SUBROUTINE) G1 X-50


G53 G0 Z0 G49 Y0
T15 G40 X-65 Y0 F5000
M06 #4=[#4- #3]
G54 S3600 M03 END1
G00 X-65 Y0 (***FINISH***)
G43 Z10 H15 D15 G0 Z[#2]
#1=0 (INITIAL Z) G41 G1 X-50 F1000
#2=-20 (Z FINAL) Y75
#3=2 (PROF.CORTE) X-30, R10
#4=[#1- #3] (VARIABLE CALCULATION) G2 X30 Y75 R30, R10
G0 Z[#1+2] G1 X50
WHILE [#4 GT #2] DO1 Y-75
G0 Z[#4] X30, R10
G41 G1 X-50 F1000 G2 X-30 Y-75 R30, R10
Y75 G1 X-50
X-30, R10 Y0
G40 X-65 Y0 F5000
G1 X50 G0 Z[#1+2]
Y-75 G53 G0 Z0 G49
X30, R10 M30
G2 X-30 Y-75 R30, R10

80 Programming and Operation Manual - Line D - CNC FANUC 0i-Mc T22182C


11. MACROB

Example 3: Parameterized program to create an arc (circle) of positions,


according to the drawing below:

#24

O0001 (MAIN PROGRAM) O1000 (SUBPROG. MACRO)


G17 G21 G90 G94 1
G53 G0 Z0 G49 N1
T1 (BROCA D8.5 MM) [#24+[ #18* COS[#1]]]
M6 #1+#2
G54 S1500 M3 #3=#3+1
G0 X0 Y0 M8 IF [#3 LE #11] GOTO1
G43 Z10 H1 D1 M99
G99 G81 Z-10 R2 F160 K0
G65 X80 Y50 R20 A45 B45 H3 P1000
G80
G53 G0 Z0 G49 M9 M5
M30

T22182C Programming and Operation Manual - Line D - CNC FANUC 0i-Mc 81


11. MACROB

Example 4: Parameterized program to create an inscribed hexagon in a given


circle

O0001 (HEXAGONAL MACRO) G0 X[[#1+#4]*COS[#3]] Y[[#1+#4]*SIN[#3]]


G17 G21 G90 G94 G43 Z2 H12
G53 G0 Z0 G49 G1 Z-5 F150
T12 N12 G1 X[#1*COS[#3]]Y[#1*SIN[#3]] F[#5]
M6 #3=#3+60
G54 S2700 M3 #6=#6+1
#1=50 (RADIUS OF THE CIRCLE) IF [#6 LE 6] GOTO12
#3=0 (INITIAL ANGLE) G1 X[[#1+#4]*COS[#10]]
#4=3 (LEAVE FOR APPROXIMATION) Y[[#1+#4]*SIN[#10]]
#5=200 (FEED RATE) G53 G0 Z0 G49
#6=0 (NUMBER OF SIDES COUNTER) M30
#10=#3 (DUPLICATES THE VARIABLE R3)

NOTE: In the example above, the tool's radius was not considered, that is,
The programmed path corresponds to the trajectory traveled by the center of the tool.

82 Programming and Operation Manual - Line D - CNC FANUC 0i-Mc T22182C


11. MACROB

Example 5: Parametrized program to execute arcs from 0.001 to 360 degrees


opening using the G01 function.

O0005 (MACRO CIRCULAR) 200 (FEED RATE)


G17 G21 G90 G94 #1=#1+#6 (REDEFINE. RADIUS OF THE ARC)
G53 G0 Z0 G49 G0 X[[#1+#7]*COS[#3]] Y[[#1+#7]*SIN[#3]]
T1 G43 Z2 H1
M6 G01 Z-5 F250
G54 S2500 M3 N11G1X[#1*COS[#3]]Y[#1*SIN[#3]]F[#10]
50 (RADIUS OF THE ARCH) #3=#3+#5
#20=10 (TOOL DIAMETER) IF [#4 GT #3] GOTO 11
#3=0 (INITIAL/CURRENT ANGLE) G1 X[#1*COS[#4]] Y[#1*SIN[#4]]
#4=360 (FINAL ANGLE) X[[#1+#7]*COS[#4]] Y[[#1+#7]*SIN[#4]]
#5=1 (ANGULAR INCREMENT) G53 G0 Z0 G49
#6=#20/2 (DEFINE. TOOL RADIUS) M30
#7=3 (LEAVE FOR APPROXIMATION)

T22182C Programming and Operation Manual - Line D - CNC FANUC 0i-Mc 83


11. MACROB

Example 6: Parameterized program to create a real ellipse of 360º.

O0010 (MAIN PROGRAM) O2000 (SUBPROG. MACRO)


N1 G17 G21 G90 G94 N1 #4=[#4/2]+#18
N2 G53 G0 Z0 G49 N2 #5=[#5/2]+#18
N3 T18 (STRAWBERRY D20 MM) N3 G00 X[[#4+#17]*COS[#1]] Y[[#5+#17]*SIN[#1]]
N4 M6 N4 WHILE [#1 LT 360] DO1
N5 G54 S3500 M3 N5 G01 X[#4*COS[#1]] Y[#5*SIN[#1]] F[#9]
N6 G0 X60 Y0 M8 N6 #1=#1+#2
N7 G43 Z10 H18 D18 N7 END1
N8 Z-2 N8 G01 X[#4*COS[360]] Y[#5*SIN[360]]
N9 G65 X0 Y0 I80 J50 A0 B1 Q5 N9 G00 X[[#4+#17]*COS[#1]] Y[[#5+#17]*SIN[#1]]
R10 F520 P2000 N10 M99
N10 G53 G0 Z0 G49 M9 M5
N11 M30

84 Programming and Operation Manual - Line D - CNC FANUC 0i-Mc T22182C


11. MACROB

Example 7: Parameterized program to execute an Archimedean spiral having:

Initial radius: 10mm


Final radius: 64 mm
N.espirais: 5
Initial position: 0 degrees

O0010 (SPIRAL MACRO) #9 = #8 * #5 (INC/TO RAD. P/ INC/TO ANG.)


G17 G21 G90 G94 #10=200 (FEED RATE)
G53 G0 Z0 G49 G0 X[#1*COS[#3]] Y[#1*SIN[#3]]
T12 G43 Z2 H12
M6 G1 Z-5 F200
G54 S2250 M3 N45 G1 X[#1*COS[#3]] Y[#1*SIN[#3]] F[#10]
#1=10 (INITIAL RADIUS) #3=#3+#5
#20=64 (FINAL RADIUS) #1+#9
#3=0 (INITIAL/CURRENT ANGLE) IF [#4 GT #3] GOTO45
#7=5 (NUMBER OF SPIRALS) G1 X[#20*COS[#4]] Y[#20*SIN[#4]]
#4 = #7 * 360 (FINAL ANGLE) G53 G0 Z0 G49
#5=1 (ANGULAR INCREMENT) M30
#8=[#20-#1]/#4 (INC/TO RADIAL X)

T22182C Programming and Operation Manual - D Line - CNC FANUC 0i-Mc 85


11. MACROB

Example 8: Parameterized program to execute a conjugateArchimedean spiral


with a descent in 'Z' having:

Initial radius: 10 mm
Final radius: 64 mm
N.espirais: 5
Initial position: 0 degrees
Initial "Z" position: 0
Final position 'Z': 25

O0011 (SPIRAL MACRO 2) #12=25 (FINAL HEIGHT)


G17 G21 G90 G94 #13 = #12 - #11 (DEPTH)
G53 G0 Z0 G49 #14=#13/#4 (INC/TO Z)
T1 #14 * #5 (INC. Z P/ INC. ANG.)
M6 G0 X[#1*COS[#3]] Y[#1*SIN[#3]]
G54 S3500 M3 G43 Z2 H1
#1=10 (INITIAL RADIUS) G1 Z[#11] F[#10]
#20=64 (FINAL RADIUS) N22 G1 X[#1*COS[#3]] Y[#1*SIN[#3]] Z[#11]
#3=0 (INITIAL ANGLE) #3=#3+#5
#7=5 (NUMBER OF SPIRALS) #1+#9
#4 = #7 * 360 (FINAL ANGLE) #11-#15
#5=1 (ANGULAR INCREMENT) IF [#4 GT #3] GOTO 22
#8=[#20-#1]/#4 (INC/TO RADIAL X) G1 X[#20*COS[#4]] Y[#20*SIN[#4]] Z[-#12]
#9=#8*#5 (INC. RAD. P/ INC. ANG.) G53 G0 Z0 G49
#10=200 (FEED RATE) M30
#11=0 (INITIAL Z HEIGHT)

86 Programming and Operation Manual - Line D - CNC FANUC 0i-Mc T22182C


11. MACROB

Example 9: Parameterized program to interpolate an internal conical thread using


an internal threading tool:

Initial diameter: 88.9 mm


Âng. da rosca: 1.783º (1º 47’)
Step: 3.175 mm (8 fpp)
Initial position 'Z': 0 (abs)
Pos 'Z' final: -28.98 (abs)
Position "X" from the center of the thread: 0 (abs)
Position 'Y' from the center of the thread: 0 (absolute)

Thread entry angle: 185º

Note: The values above refer to


a 3” NPT- 8 fpp thread.

O0001 (RIGHT/LEFT CONICAL RING MACRO)


G17 G21 G90 G94
G53 G0 Z0 G49
T01
M6
G54 S3500 M3
G43
#1=88.9 (INITIAL DIAMETER)
#2=1.783 (THREAD ANGLE)
#3=3.175 (THREAD PITCH)
#4=0 (INITIAL Z)
#5=-28.98 (Z FINAL)
#6=100 (COORD. CENTER IN X)
#7=75 (COORD. CENTER IN Y)
#8=185 (ANG. THREAD ENTRY)
#9=1 (INCR. ANG. - CIRCLE RESOLUTION)
#10=2 (DIAMETER OF THE FASTENING)

T22182C Programming and Operation Manual - Line D - CNC FANUC 0i-Mc 87


11. MACROB
#11=350 (ADVANCE FOR MILLING.)
0
(**** CALCULATION VARIABLES - DO NOT MODIFY ****)
#20=[#1-#10]/2 (CALCULATE INITIAL THREAD RADIUS)
#21=#4-#5 (CALC. PROF.TOTAL)
#22 = #9 * #3 / 360 (CALC. PROF. FOR INCR. ANG)
#23=TAN[#2]*#21 (CALC. RADIAL COTANGENT)
#24=TAN[#2]*#3 (CALC. INCR. RADIAL)
#25 = #9 * #24 / 360 (CALC. INCR. RAD. FOR INCR. ANGULAR)
#26=0 (ANGULAR COUNTER - ALWAYS 0)
#27 = #22 * #26 (CALC. PROF.PELO CONTADOR)
#28=#20-#23 (CALC. OF THE FINAL THREAD RADIUS)
#29 = #8 + [#21 * 360 / #3] (CALC. OF FINAL ANGLE)
IF [#12 EQ 0] GOTO1
IF [#12 EQ 1] GOTO2
#3000=1 (DEFINE THREAD TYPE - RIGHT/LEFT)
N1 #30=1 (RIGHT ROSCA)
GOTO3
N2 #30=-1 (LEFT ROTATION)
N3
(**** MACRO PROGRAM - DO NOT MODIFY ****)
G0 X[#6+[#20*COS[#8]]] Y[#7+[#20*SIN[#8]]]
Z[#4+2]
G1 Z[#4] F[#11]
WHILE [#27 LT #21] DO1
G1 X[#6+[[#20+[#30*#25*#26]]*COS[#8]]] Y[#7+[[#20+[#30*#25*#26]]*SIN[#8]]] Z[#4-#27]
#26=#26-[#30*#9]
#8-[#30*#9]
#27=#27+#22
END1
G1X [#6+[#28*COS[#29]]] Y[#7+[#28*SIN[#29]]] Z[#4-#21]
X[#6] Y[#7]
Move to Z at the value of [#4+2]

G53 G0 Z0 G49
M30

88 Programming and Operation Manual - Line D - CNC FANUC 0i-Mc T22182C

You might also like