CNC Programming Workshop
CNC Programming Workshop
Safety
Every effort has been made to verify the information presented here is correct, however you should assume it is not and exercise caution when putting any of the examples presented here to use.
Safety
Macro programs can affect the motions of the machine tool. They can also be used to change coordinate data and parameter settings. Any of these changes can cause unexpected motion, crashes, and other machine malfunctions. Always exercise caution and follow safe procedures for proving out new programs or edits to existing programs.
Since Macro programming can be used to change parameters, offsets, and work coordinate data, make sure you have recently backed up your parameters, settings, work shifts, and offsets.
Introduction
This Seminar is meant to be an introduction to Custom Macro Programming. There is no way to cover all the material you should be aware of in such a short time period. Be sure to read the Custom Macro section of the manual for your particular control
Introduction
This program concerns the application and use of Custom Macro B on Fanuc controls. Particularly the Fanuc Oi
The general concepts apply to almost any CNC control that has parametric programming capabilities.
Fanuc USA offers a course called Programming Level II that cover Macro B
Call - 888-FANUC-US (888-326-8287)
Introduction
Use variables to adjust dimensions that offsets alone cant change Smart programs
Introduction
Machine status
Check that offset data and work shifts are within range Check other conditions
Repetitive operations
Similar to using a sub program, but a macro will allow you to change conditions without having to edit multiple lines of code. Example: Milling a pocket taking a number of passes. Using variables will allow you to change the DOC and number of passes without having to rewrite the sub routine.
Variables
Variables are expressed in the program by a numerical value preceded by the pound sign
#100, #500
The numerical value corresponds to a register on the macro page of the CNC display
1st Press the Offset Key on Main Panel 2nd Press the right softkey that has the + symbol.
Values can be input manually into a variable register Values can also be assigned via the NC program
#510 = 1.5 #100 = #100 + 1 #510 = 12345678 #510 = 1234.5678 #510 = 12345.6789 will generate TOO MANY DIGITS alarm
Decimal points are not considered digits however leading zeros are
Variables
Variables Can Only be Mathematical Quantities (numbers) Can not have values of Yes or No Cant be True or False Cant be letters
Expressions
Mathematical Statement - #107 = #106 - #105 Subtract variable number 105 from variable number 106 and place the result in variable number 107
Expressions
Expressions
All NC words can have a variable as their value, except O (program number) and N (sequence number)
Coordinate word examples: #100 = 1.2; G00 X#100; (same as G00 X1.2) S-codes #100 = 2500; G97 M03 S#100; (same as M03 S2500) F-codes #100 = .003; G99 G01 X.5 F#100; (same as F0.003) G-codes #10 = 00 G#10 X1.2 (same as G00) O#100 (Illegal) N#100 (Illegal)
Using variables with G-codes is not good practice Whenever variables are used in place of coordinate values and/or NC words, unexpected machine movement can result
Understand how real numbers and integers are treated by the CNC control
Real numbers include integers 1.25, -.3765, 5, -10 are all real numbers
2500, 3, 20 Numbers with decimals are not integers i.e. 1.25 S-commands: M03 S2000 is ok, M03 S2000.5 is not
Understand how real numbers and integers are treated by the CNC control Some NC words only allow integers
Use of brackets can in some cases round to nearest integer In some cases variables will automatically be rounded Always refer to the manual to eliminate any doubt
Despite being able to use real numbers with Gcodes (G12.1, G52.1, etc) the control will round up a variable from one place to the right of the decimal and treat the value as an integer only
When a variable of null value is used, the control will, in most cases, ignore the command This can be dangerous
G97 M03 S#100 (The spindle will start clockwise at the last commanded value)
Safety
An operator was killed by a boring head on a machining center where the RPM was specified by a variable The variable was set to null, so the last programmed RPM was used by the control The RPM exceeded the rating of the boring head The head came apart and the operator was struck by the debris and killed
Safety
If you are using a variable and know that if the value is set outside a certain range that danger exists, then add safety checks to your code without fail.
Example: Spindle can run up to 6000 RPM but the boring head in use is rated to 2,500RPM #100 = 6000; M03 S#100;
#100 = 6000; IF [#100 GT 2500] THEN #3000=1 (RPM TOO HIGH); (Conditional statement that M03 S#100; checks that the RPM does not exceed 2500. If it does ALARM 3001 RPM TOO HIGH will be generated)
Variable #0
#0 is a read only System variable permanently set to null so it can be used for comparison #0 can also be used to set another variable to null
In the previous example the RPM check does not prevent a null value being used which would cause the spindle to run at the last programmed RPM.
#100 = #0; IF [#100 GT 2500] THEN #3000=1 (RPM TOO HIGH); IF [#100 EQ #0] THEN #3000=2 (NO RPM SET IN #100); G97 M03 S#100;
All variables are assumed null in these examples In math operations null (no value) is looked at as zero
#2 = #1;
#2 remains null because there is no math or evaluation in this statement #2 remains null. Even though the brackets make this an expression no math or evaluation occurs #2 will equal zero. No value plus no value has a value of zero #2 will equal zero
#2 = [#1];
#2 = #1 + #1
#2 = #1 * 5
In comparative expressions EQ (equal to) and NE (not equal to), null variables are not considered the same as 0
Examples - #1 = null [#1 EQ 0] [#1 NE 0] [#1 EQ #0] [#2 NE #0] False, null variable is not equal to 0 True, null variable is not equal to 0 True, #0 value is always null False, #0 value is always null
LT less than, LE - less than or equal to GT Greater than, GE - Greater than or equal to
[#1 LT 0] [#1 LE 0] [#1 GT 0] [#1 GE 0] False, 0 is not less than 0 True, 0 is equal to 0 False, 0 is not greater than 0 True, 0 is equal to zero
Using Variables
At this point you have enough knowledge to use macro variables in two of the most common ways.
Width of a groove
0.1
T1414; G96 M03 S200; G50 S5000; G00 X.55 Z.3; G99 G01 X.4 F.003 G00X.55 Z[.307+#514] G01 X.4 G00X1.18 T0 0.5
0.4
0.3
T1414; G96 M03 S200; G00 X.55 Z.#514; G99 G01 X.4 F.003 G00X1.18 T0
0.08
0.4
0.5
PN -1 -2 -3
A .3 .4 .5
Types of Variables
Read only permanent value (#0, 3100-3102) Local variables (#1 through #33) Common variables (#100 through #199) Permanent common variable (#500-#599)
System variables
A local variable is used locally as opposed to globally, that is to say that a local variable called by one macro call at a certain time is different from the same variable called at another time by a different macro call. Local variables are used to pass arguments from a macro call Variable number #1-#33 are tied to letter addresses in the macro call
0.08
0.4
0.5
PN -1 -2 -3
A .3 .4 .5
Variables
These variables are global. They have the same value in any macro call. These variable are read/write unless protected by parameter change
These variables are global. They have the same value in any macro call. These variable are read/write unless protected by parameter change
These variables will retain their values upon power down, reset, etc. These variables are preferred when input from the operator is required
Feature size adjustment Family of parts Tool life management count values
System Variables
The variables address will always return the same information, though the value will vary
System variables can be Read only, Read/Write, or Write only depending on the nature of the variable System Constants are system variables whose values are fixed. They are Read only.
Variables
This is useful in that a name that correlates to the variables value is more easily recognizable in the program than a variable number.
Examples:
X[#POS1] Y[#POS2] ; : Specifying a position by the variable name [#POS1] = #100+#101 ; : Executing a assignment statement by the variable name #[100+[#ABS]] = 500 ; : Same as above (by a variable number) #500 = [1000+[#POS2]*10] ; : Reading a variable by a variable name
SETVN Command
For the 50 common variables, #500 to #549, a name of up to eight characters can be specified by using a command as shown below.
Names can be used with system variables The name is fixed in the control and can not be changed
Example: Wear Offsets on a T Control
Unlike common variables, there is no page on the control that will display the value of system variables. You can see the value of a system variable by returning it to a common variable
For example to see the system variable for time, command: #100=#3012 The time will then be stored in variable 100 as Hour/Min/Sec
#1100=1(CLOSE SUPPORT)
#3000 is used to generate a macro alarm. #3000=1(VALUE A TOO LARGE) This will stop the machine in alarm status with alarm 3001(VALUE A TOO LARGE) Message displayed on the screen. W #3006 is used to stop the machine in feed hold status with a message. W #3006=1(INSTALL SUPPORT). #3007=Mirror Image status R
#3011 Date (Year/Month/Date) R #3012 Time (Hour/Minute/Second) R #3901 Total Number of Parts R/W #3902 Number of Required Parts R/W #4000 Main Program # R
G-Code Groups
#4102= B-Code #4107= D-Code #4108= E-Code #4109= F-Code #4111= H-Code #4113= M-Code #4114= Sequence # #4115= Program #
#4201 Starts Over with Current Block G-code Group 1 Modal Information.
Order of Operations
Algebraic order of operations
1. 2. 3. 4. 5.
P.E.M.D.A.S.
Parenthesis - In macro programming [ ] = ( ) Exponents Multiplication Division Addition Subtraction
6.
GOTO, DO, END G65, G66, G67 Custom G and M codes that command a macro call
When the machine is in single block mode, the machine does not stop when executing a macro
Macro blocks are not regarded as blocks with no movement in cutter compensation mode (G41, G42)
The flow of the program can be changed using branch and repetition statements.
Example: GOTO 10; (causes the program to jump ahead or behind to sequence number N10)
If the conditional expression is satisfied (true), the macro statement after THEN will be executed. Only a single macro statement can be executed
Sample Program
#1 = 1+2+3+4+5+6+7+8+9+10
A conditional statement is specified after WHILE. As long as the conditional statement is satisfied (true) the program from DO to END is executed.
Processes faster
Nesting
The identification numbers (1 to 3) in a DO_END loop can be used as many times in a program as desired (reuse). When a program contains overlapping DO ranges alarm PS0124 is generated.
Limitations
Infinite loops When DO m is specified without a WHILE statement preceding, an infinite loop is created between the DO and END commands. Processing time When a branch to the sequence number specified in a GOTO statement occurs, the sequence number is searched for. In the case of processing in the reverse direction use a While statement to reduce processing time. Null variable In conditional expressions that use EQ and NE, a null variable is not treated the same as 0. In all other conditional expressions null = 0
Macro Call
A macro program can be called using any of the following methods. There are two types of calling methods: macro call and subprogram call
Macro Call
When G65 is specified, the custom macro sub program at address P is called. Data (arguments) can be passed to the macro program.
After G65, address P is the program number of the macro program. When a number of repetitions are required, specify the number after address L. Range is 1-999999999. When L is omitted the value of L is assumed to be 1. By specifying arguments (A n, B n, Cn) values are passed to the corresponding variable.
Argument Specification I
Argument Specification II
Using a G-Code
Using a G-Code
Q (#17)=Pecking Amount
R (#18)=Rapid plane (absolute value) Z Start Point, (Set by system variable)
N300(END) M99 %
#113=[#113*#112](REDUCE PECK)
IF[#113LT#2]THEN#113=#2(PECK CLAMP) END1
(CHECK X-AXIS ABS. POSITION) IF[#5001GT0]GOTO10 (CHECK Y-AXIS MACH. POSITION) IF[#5024LT[#25-.02]]GOTO10 IF[#5024GT[#25+.02]]GOTO10
M99 N10(CUTOFF)
(RESET COUNT AND ALARMS) GOTO999(NO TOOLS EXPIRED) N881(1ST GROUP ALARM) #512=0(RESET 1ST COUNT) #513=0(RESET 2ND COUNT) #3000=1(GROUP 1 EXPIRED)
1 Preset #501 Tool 2 #503 Tool 3 #505 Tool 4 #507 Tool 5 #509 Tool 6 #511 Tool 7 #513 Tool 8 #515 Tool 9 #517 Tool 10 #519 Tool 11 #521 Tool 12 #523
Accumulator #502 #504 #506 #508 #510 #512 #514 #516 #518 #520 #522 #524
T0303 G0G99X1.0Z0M3S1000 M201(TIME RESET) (CUTTING PROCESS) M202(MEASURE TIME) G28U0 T0 M203(TOOL LIFE CHECK) M30
N299(END) M99
(ALARM GENERATED)
The most common use for probing on a CNC machine is to determine part location for machining. Probes can also be used to measure features. When selecting a probe for your machine it is very important to work with the supplier to determine what your software requirements are. Most vendors will have a standard probing software package, but often these may need to be customized to suit your needs. You will also need to determine the control options required. (High Speed Skip, Additional Macro Variables, Work Offsets, Ect.)
Open Discussion
Questions?
End
Thank You