Home   Products   Custom   Document   Download   Partners   Service   Contact
   
 
CAD/CAM Development
Customizing
 
 
Download Software
Download Video
Download PDF
     
Payment
Support
Ordering
   
 
FANUC macroprogram programming


1. variable
general workpiece program appoints G code and ship distance with numerical value directly; for example, GO1 and X100.0. When user macro is used, numerical value can be appointed directly or by variable. When variable is used, variable value can be changed by program or operation in MDI panel.
#1 £½ #2 £« 100
G01 X# 1 F 300
illustration £º

variable expression
variable is permitted by computer, but user macro is not. Variable is appointed by variable number £¨ # £© and latter variable number.
for example £º #1
expression can be used to appoint variable number. Here, expression must be closed in bracket.
for example £º #[#1+#2-12]

variable type
variable can be divided into four types according to variable number .

variable number
variable type
function
#0 dummy variable the variable is always empty, no value is assigned to the variable.
#1-#33 local variable local variable is only used to store data in macroprogram, such as operation outcome When power is cut, local variable is initialized to empty. And when macroprogram is called, independent variable assign local variable.
#100-#199
#500-#999

common variable common variable has the same meaning in different macro program. when power is cut, variable #100-#199 are initialized to empty. Data of variable #500-#999 is stored even if power is cut.
#1000 system variable system variable is used to read and write transformation of all kinds of data when CNC is running, such as tool current position and compensation value.
variable value range
local variable and common variable can have value 0 or values as following shows:
-1047 to -10-29 or -10-2 to -1047
If output oversteps effective range, P/S warning NO.111 is issued.

decimal omission
when variable value is defined in program, decimal can be ignored.
for example £º When define #1 £½ 123 £» actual value of variable #1 is 123.000.

variable citation
to use variable value in program, variable number follows it after appointing. when using expression to specify variable, put expression in bracket.
for example £º G01X[#1+#2]F#3;
cited variable value is rounded automatically according to minimum setting unit.
for example £º
when G00X# is executed as 1/ 1000mm , CNC assign 123456 to #1, and actual instruction value is G00X12346.
to change the sign of cited variable, put negative sign before #.
for example £º G00X £­ #1
when you cite undefined variable, variable and address are all ignored.
for example £º When value of variable #1 is 0 and value of #2 is empty, the executing outcome of G00X#1 Y# 2 is G00X0.

common variable of double locus(double locus control)
for double locus control, system provides every locus individual macro variable. But, some common variables can use two locus at one time according to the setting of parameter N0.6036 and 6037.

undefined variable
when variable value is undefined, this variable becomes empty variable. Variable #0 is always empty. And it can not be written but only be read.
citation
when an undefined variable is cited, address itself is ignored.
when #1=< empty > when#1£½0
G90 X100 Y#1
G90 X100
G90 X100 Y#1
G90 X100 Y0

(b) operation
<empty> is the same with 0 except the condition that use <empty> to assign.

when #1=< empty >

when #1£½0

#2£½#1
#2£½<¿Õ>

#2£½#1
#2£½0

#2£½#*5
#2£½0

#2£½#*5
#2£½0

#2£½#1+#1
#2£½0

#2£½#1+#1
#2£½0

(c) condition expression
in EQ and NE < empty > is differ from 0.

when #1=< empty >

when #1£½0

#1EQ#0 true

#1EQ#0 false

#1 NE #0 true

#1 NE #0 false

#1 GE #0 true

#1 GE #0 false

#1 GT #0 false

#1 GT #0 false

limitation
program number, sequence number and optional segment jumping number can not use variable.
foe example £º variable can not be used in below conditions £º
0#1 £»
/# 2G 00X100.0;
N#3Y200.0;

2. arithmetic and logic operation

the operations listed below can be executed in variable. expression at the right of operator can include constant and variable composed with function or operator. Variable #j and #k can be assigned by constant. the left variable can be assigned by expression.

function format remark
definition #i=#j  

addition

subtraction

multiplication

division

#i=#j+#k;

#i=#j-#k;

#i=#j*#k;

#i=#j/#k ;

 

sin

arcsine

cos

arccosine

tangent

arc tangent

#i=sin[#j;

#i=asin[#j];

#i=cos[#j];

#i=acos[#j];

#i=tan[#j]

#i=atan[#j]/[#k]

angle is appointed with degree. 90o30' denote 90.5 degree.

square root

absolute value

rounding

up rounding

down rounding

natural logarithm

exponential function

#i=SQRT[#j];

#i=ABS[#j];

#i=ROUNG[#j];

#i=FIX[#j];

#i=FUP[#j];

#i=LN[#j];

#i=EXP[#j];

 

Or

Xor

and

#i=#jOR#k;

#i=#jXOR#k;

#i=#jAND#k;

logic operation is executed one bit by one bit according to binary number.

Change BCD to BIN

Change BIN to BCD

#i=BIN[#j];

#i=BCD[#j];

used for handshaking with PMC.


illustration £º

angle unit
angle unit of function SIN ,COS,ASIN,ACOS,TAN and ATAN is degree, for example 90¡ã 30' denote 90.5 degree.
ARCSIN # i= ASIN[#j]
£¨ 1 £© numeric area £º
when parameter £¨ NO.6004#0 £© NAT bit place is set to 0, 270¡ã ¡« 90¡ã
when parameter £¨ NO.6004#0 £© NAT bit place is set to 1, £­ 90¡ã ¡« 90¡ã
£¨ 2 £© when #j overstep the range of £­ 1 to 1, P/S warning NO.111 is issued.
£¨ 3 £© variable #j can be replaced by constant.

ARCCOS #i£½ACOS[#j] numeric area is from 180¡ã to 0¡ã . When #j overstep the range of £­ 1 to 1, P/S warning NO.111 is issued. Variable #j can be replaced by constant.

3. program example

mill ellipse £º

locus£º

program code for ellipse £º
N10 G54 G90 G0 S1500 M03
N12 X0 Y0 Z20.
N14 G0 Z1
N16 G1 Z-5. F150.
N18 G41 D1
N20 #1=0
N22 #2=34
N24 #3=24
N26 #4=#2*COS[#1]
N28 #5=#3*SIN[#1]
N30 #10=#4*COS[45]-#5*SIN[45]
N32 #11=#4*SIN[45]+#5*COS[45]
N34 G1 X#10 Y#11
N36 #1=#1+1
N38 IF [#1 LT 370] GOTO26
N40 G40 G1 X0 Y0
N42 G0 Z100
N44 M30

mill rectangular channel £º

Code for milling rectangular channel £º
#102=0.
N3#100=0.
#101=0.
#103=200.
#104=400.
G91G28Z0.
G0G90G54X0.Y0.
G43H1Z20.
M3S2000.
N4G0X#100Y#101
G01Z#102F200.
#102=#102-2.
IF[#102EQ-50.]GOTO1
GOTO2
N2
N4X#104F500.
Y#103
X#100
Y#101
#100=#100+10.
#101=#101+10.
#103=#103-10.
#104=#104-10.
IF[#100EQ100.]GOTO3
GOTO4
N3
N1
M5
M9
G91G28Z0.
G28Y0.
M30

Mill surface inclining to 3 degree £º

locus £º

code for milling surface inclining to 3 degree £º
O0001
#[#1+1*2]=1
G65P9012L1A0B0.1C4I100J3K0
M30

macro O9012 code :
G54 G90 G00 X[#3] Y0 Z100
S500 M3
G01 Z0 F300
WHILE[#1LE10]DO1
#7= #1/TAN[#5]+#3
G1Z-#1 X#7
#8=#6/2-ROUND[#6/2]
IF[#8EQ0]GOTO10
G1Y0
GOTO20
N10 Y#4
N20#1=#1+#2
#6=#6+1
END1
G0
Z100

mill semisphere £º

locus £º

code for milling semisphere £º
G90G0G54X-10.Y0M3S4500
G43Z50.H1M8
#1=0.5
WHILE[#1LE50.]DO1
#2=50.-#1
#3=SQRT[2500.-[#2*#2]]
G1Z-#1F20
X-#3F500
G2I#3
#1=#1+0.5
END1
G0Z50.M5
M30

mill trumpet £º

code for milling trumpet £º
M03 S500
M06 T01
#1=0
#2=0
G0 Z15
X150 Y0
N11
#2=30*SIN[#1]
#3=30+30*[1-COS[#1]]
G01 Z-#2 F40
G41 X#3 D01
G03 I-#3
G40 G01 X150 Y0
#1=#1+1
IF [#1 LE 90] GOTO 11
G0 Z30
M30

 
Copyright @2009 Nanjing Swansoft Technology Company.All rights reserved
Nanjing Swansoft Technology Company
Address: Junlin Guoji Building, 5 Guangzhou Road,Suite A 1306, Nanjing, Jiangsu 210008 CHINA
TEL:(86)025-51862150 FAX(TEL):(86)025-51860015 Mobile:15150565151 E-Mail:sales@swansc.com