Professional Documents
Culture Documents
com
A machining program can call a custom macro with a simple command, just like a
subprogram, the only difference being; we can now pass information into the sub
program and manipulate it as we want.
An ordinary machining program specifies a G code and the travel distance directly
with a numeric value; examples are G01 X100.0
With a custom macro, numeric values can be specified directly or using a variable
number e.g. #1 or #2
When a variable number is used, the variable value can be changed by a program or
using operations on the MDI panel.
Local Variables
Any other information on the G65 line is passed into the macro program as a
Local Variable
Argument specification 1
G G code
L Number Of Repeats
N Sequence Number
O Main Program Number
P Macro Program Number
Mathematical Functions
Definition - #i=#j
This is what’s used to transfer data from one variable to another.
Example:
#1=10 and #2=12
#1= #2
Both variables now equal 12.
Sum - #i=#j+#k
This is what’s used to add variables and values.
Example:
#2=12
#1=#2+10
The value of #1 is now 22.
Difference - #i=#j-#k
This is what’s used to subtract variables and values
Example:
#2=12
#1=#2-10
The value of #1 is now 2.
Multiply - #i=#j*#k
This is what’s used to multiply variables and values
Example:
#2=12
#1=#2*10
The value of #1 is now 120.
Divide - #i=#j/#k
This is what’s used to divide variables and values
Example:
#2=20
#1=#2/10
The value of #1 is now 2.
All of the above can be put together using brackets to perform larger calculations.
Example:
#1=2 and #2=5
#100=#1*[#2-3]
The value of #100 is now 4, because 2 x (5 – 3) = 4
A Fanuc control uses the BODMAS system to order how the calculations are made.
5 Hughes Armstrong Middle East
FANUC CUSTOM MACRO B PROGRAMMING MANUAL www.ha-mideast.com
Formatting Functions
Rounding Up #i=FUP[#j]
When the absolute value of the integer produced by an operation on a number is
greater than the absolute value of the original number, such an operation is referred
to as rounding up to an integer.
Examples:
#1=1.2
#3=FUP[#1]
The value of #3 is now 2.0
#2=–1.2.
#3=FUP[#2]
The value of #3 is now -2.0
Examples:
#1=1.2
#3=FIX[#1]
The value of #3 is now 1.0
#2=-1.2
#3=FIX[#2]
The value of #3 is now -1.0
Trigonometry Functions
In Macro B programming Sine, Cosine and Tangent are applied in the same format
Sine #i=SIN[#j];
Cosine #i=COS[#j];
Tangent #i=TAN[#j];
Arcsine #i=ASIN[#j]/[#k];
Arccosine #i=ACOS[#j]/[#k];
Arctangent #i=ATAN[#j]/[#k];
#4
#1
#2
90°
#5
#3
Known Variables Formulas For Variables To Be Found
#3=SQRT[[#1*#1]-[#2*#2]]
#1 & #2 #5=ASIN[[#2]/[#1]]
#4=90- #5
#2=SQRT[[#1*#1]-[#3*#3]]
#1 & #3 #4=ASIN[[#3]/[#1]]
#5=90- #4
#1=SQRT[[#2*#2]-[#3*#3]]
#2 & #3 #5=ATAN[[#2]/[#3]]
#4=90- #5
#2=#1*SIN[#5]
#1 & #5 #3=#1*COS[#5]
#4=90- #5
#2=#1*COS[#4]
#1 & #4 #3=#1*SIN[#5]
#5=90- #4
#1=#2/SIN[#5]
#2 & #5 #3=#2/TAN[#5]
#4=90 - #5
#1=#2/COS[#4]
#2 & #4 #3=#2*TAN[#4]
#5=90- #4
#1=#3/COS[#5]
#3 & #5 #2=#3*TAN[#5]
#4=90- #5
#1=#3/SIN[#4]
#3 & #4 #2=#3/COS[#4]
#5=90- #4
3.142 * Diameter
A local variable to pass over the CSS into the macro (S)
Conditional Expressions
In a program, the flow of control can be changed using the GOTO statement and
IF statement.
Operators
Operators each consist of two letters that are used to compare two values to
determine whether they are equal or one value is smaller or greater than the other
value. Note that the inequality sign cannot be used.
Operator Meaning
EQ Equal to (=)
NE Not Equal to (≠)
LT Less Than (<)
LE Less Than or Equal to (< & =)
GT Greater Than (>)
GE Greater than or Equal To (> & =)
IF[<conditionalexpression>]GOTOn
If the value of variable #100 is not equal to 20, a branch to sequence number
N5 occurs.
IF[<conditionalexpression>]THEN
WHILE […….] DO 1;
WHILE […….] DO 1;
PROCESSING
WHILE […….] DO 2;
END 1;
WHILE […….] DO 3;
END 2;
PROCESSING
END1
END 1;
After a G65, a P (program number) must be specified; this program is the macro
program to be called. When repetitions are required, an L can be specified.
Any other information on a G65 line is passed into the macro program using local
variables.
Once G66 is issued to specify a modal call, the macro program is called after a block
specifying axis movement is completed. This continues until G67 is issued to cancel
the modal macro call.
The following table shows the correspondence between program number and
parameter. If for example your macro program is O9010, enter the value of the G
code you want in parameter 6050. I.E if you want G125 to open O9010 then 6050
must be 125.
NOTE:
Because a P value is no longer required using this method the local variable #13
becomes available and information can be passed to it by using P
The following table shows the correspondence between program number and
parameter. If for example your macro program is O9020, enter the value of the M
code you want in parameter 6080. I.E if you want M125 to open O9020 then 6080
must be 125.
NOTE:
Because a P value is no longer required using this method the local variable #13
becomes available and information can be passed to it by using P
Create a G-Code to enable to drill holes on various PCD’s. The depths and the
amount of holes vary.
Process
1. Move the tool to the centre point
2. Using Trigonometry calculate hole position 1
3. Drill the hole
4. Using a WHILE statement repeat steps 2 & 3 until all holes are drilled.
System Variables
System variables can be used to read and write internal NC data such as tool
compensation values and current position data.
Note however, that some system variables can only be read. System variables are
essential for automation and general–purpose program development.
A full list off all the system variables for the Fanuc T & M systems can be
found at the back of this manual
Modal Information
Example:
When #1=#4001; is executed, the resulting value in #1 is 0, 1, 2, 3, or 33.
If the specified system variable for reading modal information corresponds to a G
code group that cannot be used, a P/S alarm is issued.
Example:
When #1=#4001; is executed, the resulting value in #1 is 0, 1, 2, 3, or 33.
If the specified system variable for reading modal information corresponds to a G
code group that cannot be used, a P/S alarm is issued.
Positioning Information
Position information can be read but not written.
Example:
Example:
#3001=0;
M98 P1000 (CONTOURING CYCLE);
#500=#3001;
#500=#500/1000;
Creating Alarms
Using system variables we can make the machine stop instantly and display a
custom message.
When a value from 0 to 200 is assigned to variable #3000, the CNC stops with an
alarm. An alarm message not longer than 26 characters can be described. The CRT
screen displays alarm numbers by adding 3000 to the value in variable #3000 along
with an alarm message.
Example:
#3000=1(TOOL LIFE EXPIRED)
Creating Messages
Operator messages are a good way of letting the operator know what is going on in
the program and also any checks or inspections they need to make.
When #3006=1 (MESSAGE); is commanded in the macro, the program executes
blocks up to the immediately previous one and then stops.
A message of up to 26 characters can be displayed. The message can be cleared
with #3006=0.
Example:
#3006=1(CHECK COMPONENT SEATED)
#0 is always null or empty, therefore we can say that if a variable is equal to #0 then
the operator has missed passing a local variable into the macro. We can then also
generate an alarm to notify the operator.
Example:
Before exiting the macro it is extremely important that the machine is in the same
position it was when it entered the macro. Also all the modal information needs to be
the same too.
Example:
M99
Automatic operation
Time
Number of Parts
Position Information
#100001 - #100050 Note: numbers to the left can be used for Axis
number 1 - 50
#5021 - #5040 Specified current position (machine coordinate
system) Axis number 1 – 20
#100051 - #100100 Note: numbers to the left can be used for Axis
number 1 - 50
#5041 - #5060 Specified current position (work piece
coordinate system) Axis number 1 – 20
#100101 - #100150 Note: numbers to the left can be used for Axis
number 1 - 50
#5061 - #5080 Skip position (work piece coordinate system)
Axis number 1 – 20
#100151 - #100200 Note: numbers to the left can be used for Axis
number 1 - 50
#100201 - #100250 Note: numbers to the left can be used for Axis
number 1 - 50
#100251 - #100300 Note: numbers to the left can be used for Axis
number 1 - 50
#100651 - #100700 Note: numbers to the left can be used for Axis
number 1 - 50
Distance To Go
#100801 - #100850 Note: numbers to the left can be used for Axis
number 1 - 50
#100701 - #100750 Note: numbers to the left can be used for Axis
number 1 - 50
#117001 - #117050 Note: numbers to the left can be used for Axis
number 1 – 50
#5521 - #5540 Standard fixture offset value (1st set)
Axis number 1 – 20
System Constant