You are on page 1of 9

FANUC macro program programming

1 . Variable General workpiece program appoints G code and ship distance with numerical value directly; for example, GO1 and X100.0. hen user macro is used, numerical value can !e appointed directly or !y varia!le. hen varia!le is used, varia!le value can !e changed !y program or operation in "#$ panel. %1%&100 G01 X%1 '(00 illustration
Variable expression

)aria!le is permitted !y computer, !ut user macro is not. )aria!le is appointed !y varia!le num!er % and latter varia!le num!er. 'or example %1 *xpression can !e used to appoint varia!le num!er. +ere, expression must !e closed in !racket. 'or example %,%1-%&.1&/
Variable type

)aria!le can !e divided into four types according to varia!le num!er . )aria!le 0O. )aria!le type 'unction %0 dummy varia!le 1he varia!le is always empty, no value is assigned to the varia!le.


2ocal varia!le is only used to store data in macroprogram, such as operation outcome hen power is cut, local varia!le is initiali3ed to local varia!le empty. 4nd when macroprogram is called, independent varia!le assign local varia!le. common varia!le system varia!le 7ommon varia!le has the same meaning in different macro program. when power is cut, varia!le %100.%155 are initiali3ed to empty. #ata of varia!le %600.%555 is stored even if power is cut. 8ystem varia!le is used to read and write transformation of all kinds of data when 707 is running, such as tool current position and compensation value.

%100.%155 %600.%555 %1000

variable value range

2ocal varia!le and common varia!le can have value 0 or values as following shows9 .10:; to .10.&5 or .10.& to .10:; $f output oversteps effective range, <=8 warning 0O.111 is issued.
Decimal omission

hen varia!le value is defined in program, decimal can !e ignored. 'or example hen define %1 1&( actual value of varia!le %1 is 1&(.000.
Variable citation

1o use varia!le value in program, varia!le num!er follows it after appointing. when using expression to specify varia!le, put expression in !racket. 'or example G01X,%1-%&/'%(; 7ited varia!le value is rounded automatically according to minimum setting unit. 'or example hen G00X% is executed as 1= 1000mm , 707 assign 1&(:6> to %1, and actual instruction value is G00X1&(:>. 1o change the sign of cited varia!le, put negative sign !efore %. 'or example G00X %1 hen you cite undefined varia!le, varia!le and address are all ignored. 'or example hen value of varia!le %1 is 0 and value of %& is empty, the executing outcome of G00X%1 ?% & is G00X0.
Common variable of double locus(double locus control

'or dou!le locus control, system provides every locus individual macro varia!le. @ut, some common varia!les can use two locus at one time according to the setting of parameter 00.>0(> and >0(;.
Undefined variable

hen varia!le value is undefined, this varia!le !ecomes empty varia!le. )aria!le %0 is always empty. 4nd it can not !e written !ut only !e read.

hen an undefined varia!le is cited, address itself is ignored. hen %1AB empty C G50 X100 ?%1 hen%10 G50 X100 ?%1

G50 X100 G50 X100 ?0 D!E Operation B empty C is the same with 0 except the condition that use B empty C to assign. when %1AB empty C %&%1 %&B empty C %&%F6 %&0 %&%1-%1 %&0 when %10 %&%1 %&0 %&%F6 %&0 %&%1-%1 %&0

DcE7ondition expression $n *G and 0* B empty C is differ from 0. when %1AB empty C %1*G%0 true %10*%0 true %1G*%0 true %1G1%0 false

hen%10 %1*G%0 false %10*%0 false %1G*%0 false %1G1%0 false

<rogram num!er, seHuence num!er and optional segment Iumping num!er can not use varia!le. 'or example varia!le can not !e used in !elow conditions 0%1 =%&G00X100.0; 0%(?&00.0; " . Arit#metic and logic operation 1he operations listed !elow can !e executed in varia!le. expression at the right of operator can include constant and varia!le composed with function or operator. )aria!le %I and %k can !e assigned !y constant. the left varia!le can !e assigned !y expression.

Function Definition Addition $ubtraction %ultiplication Division $in Arcsine Cos Arccosine &angent Arc tangent $'uare root

'ormat %iA%I %iA%I-%k; %iA%I.%k; %iA%IF%k; %iA%I=%k; %iAsin,%I; %iAasin,%I/; %iAcos,%I/;


4ngle is appointed with degree. 50o(0K denote 50.6 degree. %iAacos,%I/; %iAtan,%I/ %iAatan,%I/=,%k/ %iA8GJ1,%I/;

Absolute value (ounding Up rounding Do)n rounding Natural logarit#m *xponential function +r ,or And C#ange -CD to -.N C#ange -.N to -CD

%iA4@8,%I/; %iAJOL0G,%I/; %iA'$X,%I/; %iA'L<,%I/; %iA20,%I/; %iA*X<,%I/; %iA%IOJ%k; %iA%IXOJ%k; %iA%I40#%k; %iA@$0,%I/; Lsed for handshaking with <"7. %iA@7#,%I/;

2ogic operation is executed one !it !y one !it according to !inary num!er.

$llustration Angle unit 4ngle unit of function 8$0 ,7O8,48$0,47O8,140 and 4140 is degree, for example 50M (0K denote 50.6 degree. 4J78$0 % iA 48$0,%I/ 1 0umeric area hen parameter 0O.>00:%0 041 !it place is set to 0, &;0M 50M hen parameter 0O.>00:%0 041 !it place is set to 1, 50M 50M & hen %I overstep the range of 1 to 1, <=8 warning 0O.111 is issued. ( )aria!le %I can !e replaced !y constant. 4J77O8 %i47O8,%I/ numeric area is from 1N0M to 0M . hen %I overstep the range of 1 to 1, <=8 warning 0O.111 is issued. )aria!le %I can !e replaced !y constant. / . 0rogram example a %ill ellipse

&ool 0at# for mill ellipse

0rogram code for %ill ellipse

010 G6: G50 G0 81600 "0( 01& X0 ?0 O&0. 01: G0 O1 01> G1 O.6. '160. 01N G:1 #1 0&0 %1A0 0&& %&A(: 0&: %(A&: 0&> %:A%&F7O8,%1/ b %ill rectangular c#annel

0&N %6A%(F8$0,%1/ 0(0 %10A%:F7O8,:6/.%6F8$0,:6/ 0(& %11A%:F8$0,:6/-%6F7O8,:6/ 0(: G1 X%10 ?%11 0(> %1A%1-1 0(N $' ,%1 21 (;0/ GO1O&> 0:0 G:0 G1 X0 ?0 0:& G0 O100 0:: "(0

&ool 0at# for mill rectangular c#annel

Code for milling rectangular c#annel

%10&A0. 0(%100A0. %101A0. %10(A&00. %10:A:00. G51G&NO0. G0G50G6:X0.?0. G:(+1O&0. "(8&000. 0:G0X%100?%101 G01O%10&'&00. %10&A%10&.&. $',%10&*G.60./GO1O1 GO1O& 0& 0:X%10:'600. c %ill surface inclining to / degree

?%10( X%100 ?%101 %100A%100-10. %101A%101-10. %10(A%10(.10. %10:A%10:.10. $',%100*G100./GO1O( GO1O: 0( 01 "6 "5 G51G&NO0. G&N?0. "(0

&ool 0at# for mill surface inclining to / degree

Code for milling surface inclining to / degree

O0001 %,%1-1F&/A1 G>6<501&2140@0.17:$100P(Q0 "(0

%acro +121" code 3

G6: G50 G00 X,%(/ ?0 O100 8600 "( G01 O0 '(00 +$2*,%12*10/#O1 %;A %1=140,%6/-%( G1O.%1 X%; d %ill semisp#ere

%NA%>=&.JOL0#,%>=&/ $',%N*G0/GO1O10 G1?0 GO1O&0 010 ?%: 0&0%1A%1-%& %>A%>-1 *0#1 G0 O100

&ool 0at# for mill semisp#ere

Code for milling semisp#ere

G50G0G6:X.10.?0"(8:600 G:(O60.+1"N %1A0.6 +$2*,%12*60./#O1 %&A60..%1 %(A8GJ1,&600..,%&F%&// G1O.%1'&0 e %ill trumpet

X.%('600 G&$%( %1A%1-0.6 *0#1 G0O60."6 "(0

&ool 0at# for mill trumpet

Code for milling trumpet

"0( 8600 G01 O.%& ':0 "0> 101 G:1 X%( #01 %1A0 G0( $.%( %&A0 G:0 G01 X160 ?0 G0 O16 %1A%1-1 X160 ?0 $' ,%1 2* 50/ GO1O 11 011 G0 O(0 %&A(0F8$0,%1/ "(0 %(A(0-(0F,1.7O8,%1// f FANUC &ool compensation system parameter macro application

&ool 0at# for tool compensation

Code for tool compensation

O1&(: %1&00;A: G5&X0?0O0 01G50G1;G00G:1#0;X&6.0?66.0 0&G01?50.0'160 0(X:6.0 0:G0(X60.0?116.0J>6.0 06G0&X50.0J.&6.0

0>G0(X56.0?50.0J>6.0 0;G01X116.0 0N?66.0 05X;0.0?>6.0 010X&6.0?66.0 011G00G:0X0?0