FANUC Series 30i/300i/300is-MODEL A. Machining Center System. User's manual - page 69

 

  Index      Manuals     FANUC Series 30i/300i/300is-MODEL A. Machining Center System. User's manual (B-63944EN/03)

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     67      68      69      70     ..

 

 

 

FANUC Series 30i/300i/300is-MODEL A. Machining Center System. User's manual - page 69

 

 

16.CUSTOM MACRO

 PROGRAMMING 

B-63944EN/03

 

 

- 508 - 

Example: 
 

When an attempt is made to assign the following values to variables #1 
and #2:   

  

#1=9876543210123.456 

  

#2=9876543277777.777 

 

the values of the variables become: 

  

#1=9876543200000.000 

  

#2=9876543300000.000 

 

In this case, when #3=#2-#1; is calculated, #3=100000.000 results.  (The 
actual result of this calculation is slightly different because it is performed 
in binary.) 

 Also be aware of errors that can result from conditional 

expressions using EQ, NE, GE, GT, LE, and LT. 

Example: 
 

IF[#1 EQ #2] is effected by errors in both #1 and #2, possibly resulting in 
an incorrect decision. 

  Therefore, instead find the difference between the two variables with 

IF[ABS[#1-#2]LT0.001]. 

  Then, assume that the values of the two variables are equal when the 

difference does not exceed an allowable limit (0.001 in this case). 

  Also, be careful when rounding down a value. 

Example: 
 

When #2=#1*1000; is calculated where #1=0.002;, the resulting value of 
variable #2 is not exactly 2 but 1.99999997.     

 

Here, when #3=FIX[#2]; is specified, the resulting value of variable #3 is 
not 2.0 but 1.0.     

 

In this case, round down the value after correcting the error so that the 
result is greater than the expected number, or round it off as follows: 

  

#3=FIX[#2+0.001] 

  

#3=ROUND[#2] 

 

 - Brackets 

Brackets ([ ]) are used to enclose an expression.     
Note that parentheses ( ) are used for comments. 
 

 - Divisor 

When a divisor of zero is specified in a division, an alarm PS0112 
occurs. 
 

B-63944EN/03

 PROGRAMMING 

16.CUSTOM MACRO

 

 

- 509 - 

16.4 

INDIRECT AXIS ADDRESS SPECIFICATION 

 

Overview 

When the custom macro function is enabled, you can use 
AX[(axis-number)] in an axis address specification to indirectly 
specify an axis with its axis number and not to directly specify it with 
its axis name. 
You can also use AXNUM[(axis-name)] to obtain the axis number for 
an axis name. 
 

Explanation 
  - Indirect axis address 

You can use indirect axis address AX[ ] to specify an axis with its axis 
number.    (An equal sign (=) is always required following AX[ ].) 
 

AX[(axis-number)] = (numeric-value) ; 
 
(axis-number): 1 to the number of controlled axes (number of 

controlled axes for each path in a multipath system) 

(numeric-value): 

Value specified for the axis specified with its axis 
number 

 
If an invalid axis number is specified, an alarm PS0331 occurs.    If a 
value is put in a decimal place, the number is rounded off to an integer 
and the result is treated as the axis number. 
You can also specify a variable (local, common, or system variable) 
for (axis-number).    To specify an operation using a variable name in 
(axis-number), however, enclose the variable name with brackets ([ ]). 
 

1. AX[1]=100.0;

Specifies a value of 100.000 for the first axis.

2. AX[#500]=200.0;

Specifies a value of 200.000 for the axis having the axis number
indicated by the value stored in #500.

3. AX[#500+1]=300.0;

Specifies a value of 300.000 for the axis having the axis number
obtained by adding 1 to the value stored in #500.

4. SETVN 500 [ABC];

AX[#ABC]=400.0;

Specifies a value of 400.000 for the axis having the axis number
indicated by the value stored in #ABC (#500).

5. SETVN 500 [ABC];

AX[[#ABC]+1]=500.0;

Specifies a value of 400.000 for the axis having the axis number
obtained by adding 1 to the value stored in #ABC (#500).

6. SETVN 500 [ABC];

AX[#ABC+1]=500.0;

Alarm PS0331 occurs.

 

 

16.CUSTOM MACRO

 PROGRAMMING 

B-63944EN/03

 

 

- 510 - 

 - AXNUM function 

You can use AXNUM[ ] to obtain an axis number. 
 

AXNUM[(axis-name)]; 

 
If an invalid axis name is specified, an alarm PS0332 occurs. 
 

 
When the number of controlled axes is 3, the name of the first axis 

is X, that of the second axis is Y, and that of the third axis is Z 

 
1. #500=AXNUM[X]; 

 

A value of 1 is stored in #500. 

2. #501=AXNUM[Y]; 

 

A value of 2 is stored in #501. 

3. #502=AXNUM[Z]; 

 

A value of 3 is stored in #502. 

4. #503=AXNUM[A]; 

 

Alarm PS0332 occurs. 

 

 

 

Example 

Examples when the name of the first axis is X, that of the second axis 
is Y, and that of the third axis is Z1 
 
N10 SETVN 500[AXIS1,AXIS2,AXIS3] ; 
N20 [#AXIS1]=AXNUM[X] ; 
N30 [#AXIS2]=AXNUM[Y] ; 
N40 [#AXIS3]=AXNUM[Z1] ; 
N50 G92 AX[#AXIS1]=0 AX[#AXIS2]=0 AX[#AXIS3]=0 ; 
N60 G90G01F1000. ; 
N70 AX[#AXIS1]=100.0 AX[#AXIS2]=100.0 AX[#AXIS3]=100.0 ; 
N80 G02 AX[#AXIS1]=100. 0 AX[#AXIS2]= 0.0 R50.0 ; 
N90 M02; 
 

Limitation 

When the custom macro function is enabled, AX and AXN cannot be 
used as an extended axis name.  AX is assumed to be AX[ ] and 
AXN is assumed to be AXNUM[ ]. 
 

B-63944EN/03

 PROGRAMMING 

16.CUSTOM MACRO

 

 

- 511 - 

16.5 

MACRO STATEMENTS AND NC STATEMENTS 

 
The following blocks are referred to as macro statements: 

  Blocks containing an arithmetic or logic operation (=)   

  Blocks containing a control statement (such as GOTO, DO, END) 

  Blocks containing a macro call command (such as macro calls by 

G65, G66, G66.1, G67, or other G codes, or by M codes)   

 
Any block other than a macro statement is referred to as an NC 
statement. 
 

Explanation 
  - Differences from NC statements 

  Even when single block mode is on, the machine does not stop.  

Note, however, that the machine stops in the single block mode 
when bit 5 of parameter SBM No. 6000 is 1. 

  Macro blocks are not regarded as blocks that involve no movement 

in the cutter compensation mode. 

 

  - NC statements that have the same property as macro statements 

  NC statements that include a subprogram call command (such as 

subprogram calls by M98 or other M codes, or by T codes) and not 
include other command addresses except an O, file name, N, P, or 
L address have the same property as macro statements. 

  NC statements that include M99 and those do not include other 

command addresses except an O, file name, N, P, or L address 
have the same property as macro statements. 

 

16.CUSTOM MACRO

 PROGRAMMING 

B-63944EN/03

 

 

- 512 - 

16.6 

BRANCH AND REPETITION 

 
In a program, the flow of control can be changed using the GOTO 
statement and IF statement.  Three types of branch and repetition 
operations are used:   
 

Branch and 

GOTO 

(unconditional branch) 

repetition 

IF   

(conditional branch: if ..., then...) 

 

WHILE 

(repetition while ...) 

 

16.6.1 

Unconditional Branch (GOTO Statement) 

 
A branch to sequence number n occurs.  When a sequence number 
outside of the range 1 to 99999999 is specified, an alarm PS1128 
occurs.  A sequence number can also be specified using an 
expression. 
 

GOTOn ;

 

n:    Sequence number (1 to 99999999) 

 

Example:  
 GOTO 

1; 

 GOTO 

#10; 

 

 WARNING 

  Do not specify multiple blocks with the same 

sequence number in a single program.  It is very 
dangerous to specify such blocks because the 
destination of a branch from the GOTO statement is 
undefined. 

 

NOTE 

1 A backward branch takes more time as compared 

with a forward branch. 

2  In the destination of GOTOn, that is, the block with 

sequence number n, the sequence number must 
appear at the beginning of the block.  If the 
sequence number is not at the beginning of the 
block, a branch cannot be made. 

 

B-63944EN/03

 PROGRAMMING 

16.CUSTOM MACRO

 

 

- 513 - 

16.6.2 

GOTO Statement Using Stored Sequence Numbers 

 
When the GOTO statement is executed in a custom macro control 
command, a sequence number search is made for sequence numbers 
stored at previous execution of the corresponding blocks at a high 
speed. 
As a "sequence number stored at previous execution of the 
corresponding block", a unique sequence number within the same 
program or the sequence number of a subprogram call with which the 
block was executed is stored. 
The storage type differs depending on the values of the following 
parameters. 
(1)  When bit 1 (MGO) of parameter No. 6000 is set to 1 

  Fixed type:  Up to 20 sequence numbers stored at execution 

of the corresponding blocks from the start of 
operation 

(2)  When bit 4 (HGO) of parameter No. 6000 is set to 1 

  Variable type: Up to 30 sequence numbers stored at execution 

of the corresponding blocks before execution of 
the GOTO statement 

 History type: Up to 10 sequence numbers stored by a 

sequence number search previously made using 
the GOTO statement 

The stored sequence numbers are canceled in the following cases: 

  Immediately after power-on 

  After a reset 

  Operation after program registration or editing (including 

background editing and MDI program editing) 

 

16.CUSTOM MACRO

 PROGRAMMING 

B-63944EN/03

 

 

- 514 - 

A branch to 
N10 before 
the GOTO 
statement 
occurs. 

A branch to 
N10 after the 
GOTO 
statement 
occurs. 

 

 WARNING 

Do not specify multiple blocks with the same 

sequence number in a single program. 

It is very dangerous to specify the sequence number 

of the branch destination before and after the GOTO 
statement and execute the GOTO statement because 
the branch destination changes according to the 
values of the parameters as shown below: 

When bit 1 (MGO) or 4 (HGO) of 

parameter No. 6000 is set to 1 

When both bits 1 (MGO) and 4 
(HGO) of parameter No. 6000 
are set to 0 

 
 
 

 

                : 
          N10;     
                :                       
 GOTO10;    
                : 
          N10; 

            : 
      N10;     
            :             
GOTO10;    
            :   
      N10;   

 
 

When bit 1 (MGO) or 4 (HGO) of parameter No. 6000 
is set to 1 and the GOTO statement is executed, the 
sequence number of the branch destination may not be 
contained in the sequence numbers stored at previous 
execution of the corresponding blocks.    In this case, a 
branch to the sequence number in a block following the 
GOTO statement occurs (the destination is the same 
as when both bits are set to 0). 

 

NOTE 

When an external program is read and executed by 

DNC operation, the executed sequence numbers are 
not stored. 

When a program registered in memory is executed by 

a subprogram call, the sequence numbers are stored. 

 

 CAUTION 

According to the restrictions on the GOTO statement, 

no branch to a sequence number within a DO-END 
loop cannot be made.  If a program in which a 
branch to a sequence number within a loop occurs is 
executed, operation may differ depending on whether 
the GOTO statement using stored sequence numbers 
is used. 

 

B-63944EN/03

 PROGRAMMING 

16.CUSTOM MACRO

 

 

- 515 - 

16.6.3 

Conditional Branch (IF Statement) 

 
Specify a <conditional expression> after IF. 
 

IF[<conditional expression>]GOTOn 

If the specified <conditional expression> is satisfied (true), a branch to 
sequence number n occurs.    If the specified condition is not satisfied, 
the next block is executed. 
 

If the value of variable #1 is greater than 10, a branch to sequence number 

N2 occurs. 

 
 
 
 
 

 

IF[<conditional expression>]THEN 

If the specified <conditional expression> is satisfied (true), a macro 
statement specified after THEN is executed.   
Only a single macro statement is executed. 
 

If the values of #1 and #2 are the same, 0 is assigned to #3. 

IF[#1 EQ #2] THEN#3=0 ; 

 

 

If the values of #1 and #2 are the same and those of #3 and #4 are also 

the same, 0 is assigned to #5. 

IF[[#1 EQ #2] AND [#3 EQ #4]] THEN#5=0 ; 

 

 

If the values of #1 and #2 are the same or those of #3 and #4 are the 

same, 0 is assigned to #5. 

IF[[#1 EQ #2] OR [#3 EQ #4]] THEN#5=0 ; 

 

 

Explanation 
 - <Conditional expression> 

<Conditional expressions> are divided into <simple conditional 
expressions> and <complex conditional expressions>.    In a <simple 
conditional expression>, a relational operator described in Table 16.6 
(a)

 

is specified between two variables or between a variable and 

constant to be compared.    An <expression> can be used instead of a 
variable.  With a <complex conditional expression>, an AND 
(logical AND), OR (logical OR), or XOR (exclusive OR) operation is 
performed for the results (true or false) of multiple <simple 
conditional expressions>. 

If the condition 

is not satisfied 

IF [#1 GT 10] GOTO 2 ; 

N2 G00 G91 X10.0    ;

Processing

If the condition is satisfied

 

 

 

 

 

 

 

Content      ..     67      68      69      70     ..