CNC Programming Basics
CNC Programming Basics
Programming
For the Fanuc 0M controller
Axes convention
The tool can be moved to any position in a 3 dimensional cartesian co-ordinate system.
The Z axis is along the spindle axis. The X and Y axes are perpendicular to Z.
-
X
-
+ - Z
+
Y
Z
Part
X
Machine table
List of G-codes
G-code Function Format
G00 Positioning rapid traverse G0 X Y Z
G01 Linear interpolation (feed) G01 X Y Z F
G02 Circular interpolation CW (feed) G02 X Y I J F or G02 X Y R F
G03 Circular interpolation CCW (feed) G02 X Y I J F or G02 X Y R F
G04 Dwell G4 X1.0 (one sec)
G4 P1000 (1000 milli sec)
G10 Data setting Changing work offset
G10 G90 L2 P1 X163.684 Y-391.934 Z-693.344
L2 = Load work offset
P= 0 External work zero offset (G53)
P= 1 to 6 Work coordinate system 54 to G59
P= offset number
R= Tool offset value
List of M codes
M codes vary from machine to machine depending on the functions available on it. The machine tool
manufacturer decides them. The M codes listed below are the common ones.
M-codes Function
M00 Optional program stop automatic
M01 Optional program stop request
M02 Program end
M03 Spindle ON clock wise (CW)
M04 Spindle ON counter clock wise (CCW)
M05 Spindle stop
M06 Tool change
M07 Mist coolant ON (coolant 1 ON)
M08 Flood coolant ON (coolant 2 ON)
M09 Coolant OFF
M28 Rigid tapping cycle cancel
M29 Rigid tapping cycle enable
M19 Spindle orientation
M30 End of program, Reset to start
M98 Sub program call
M99 Sub program end
There are other M-codes for functions like gear change, pallet change, pallet clamp / unclamp, door open /
close etc.
N2
50
20 N1
X
0,0 30 50
Format
G0 X__
G0 Y__
G0 Z__
G0 X__ Y__Z__
Format
G01 X__ F__
G01 Y__ F__
G01 Z__ F__
G01 X__ Y__Z__ F__
Format
G02/03 X__ Y__Z__ I__ J__K__ F__ using the arc center
OR
G02/03 X__ Y__Z__ R__ F__ using the arc radius
Arc center
The arc center is specified by addresses I, J and K. I, J and K are the X, Y and Z co-ordinates of the arc
center with reference to the arc start point.
Arc radius
The radius is specified with address R.
Arc start
Y Arc end Arc radius
Arc center
X
Block format
G42 G42
Block format
Program Zero
Length offset
Face milling cutter
T-slot milling cutter
Boring tool
Part
Work co-ordinate
system 2 selection Machine table
Canned cycles
Canned or fixed cycles are programming aids that simplify programming. Canned cycles combine many
programming operations and are designed to shorten the program length, minimize mathematical
calculations, and use minimal tool motions.
Spindle CW Spindle CW
Ex:
M29 S1000
G98 G74 R3.0 Z-20.0 F1000.0 P100
XY
XY
M28
G0 G80
Lateral shift
Spindle CW
Final depth
Dwell at
bottom
Lateral shift
Spindle Orientation
Format
N__ G98 G76 R__ Z__ Q__ F__
Infeed feed rate mm/min
Lateral shift
Final depth
Safe height / R point
Fine boring cycle code
Return position code
Block number
Format
Format
Format
N__ G98/99 G83 R__ Z__ Q__ F__
Infeed feed rate mm/min
Peck depth
Final depth
Safe height / R point
Peck drilling cycle code
Return position code
Block number
Spindle CW Spindle CW
Format
Ex:
M29 S1000
G98 G84 R3.0 Z-20.0 F1000.0 P100
XY
XY
M28
G0 G80
Final depth
Format
Spindle CW Spindle CW
Format
Spindle orientation
Initial point
Bore axis
Lateral shift
Final depth
Spindle CW Safe height / R point
Format
N__ G98 G87 R__ Z__ Q__ F__
Infeed feed rate mm/min
Lateral shift
Final depth
Safe height / R point
Back boring cycle code
Return position code
Block number
Verifying NC programs
Safety priorities
Safety priorities must be followed when verifying programs.
Typical errors
Syntax errors
Errors which prevent the machine controller from executing a command. E.g., writing G101 instead of G01
Motion errors
Machine does not generate an error, so these are difficult to diagnose.
E.g., Writing X instead of Z; wrong co-ordinates; reversing CW and CCW commands; improper
incremental/absolute mode selection.
Omission errors
Omitting decimal points, forgetting to program feed rates, forgetting to turn on the coolant
Setup errors
Wrongly measured work offset and tool offsets, or correct measurement and wrong entry