Professional Documents
Culture Documents
NC Programming
NC Programming
Programming
For the Fanuc 0T controller
Axes convention
X Axis
Z Axis
N2
20
0,0
N1
30
50
CNC Turning
Programming
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.
+
+Z
Z
+
Y
-
+Y
+X
-X
+
-Y
-Z
CNC Milling
Programming
+
Y
X
Z
+
Part
X
Machine table
CNC Milling
Programming
List of G-codes
G-code
G00
G01
G02
G03
G04
G20
G21
G28
G30
G40
G41
G42
G43
G52
G54
G55
G56
G57
G58
G59
G74
G76
G80
G81
G82
G83
G84
G85
G86
G87
G90
G91
G94
G95
G98
G99
Function
Positioning rapid traverse
Linear interpolation (feed)
Circular interpolation CW
Circular interpolation CCW
Dwell
Inch unit
Metric unit
Automatic zero return
2nd reference point return
Tool nose radius compensation cancel
Tool nose radius compensation left
Tool nose radius compensation right
Tool length compensation
Local co-ordinate system
Work co-ordinate system 1 selection
Work co-ordinate system 2 selection
Work co-ordinate system 3 selection
Work co-ordinate system 4 selection
Work co-ordinate system 5 selection
Work co-ordinate system 6 selection
Left hand tapping cycle
Fine boring cycle
Canned cycle cancel
Drilling cycle
Drilling cycle with dwell
Peck drilling cycle / deep drill
Tapping cycle
Boring / Reaming cycle
Boring cycle
Back boring cycle
Absolute command
Incremental command
Feed per minute
Feed per revolution
Return to initial point in canned cycle
Return to R point in canned cycle
CNC Milling
Programming
List of M codes
M codes vary from machine to machine depending on the functions available on it. They are decided by the
manufacturer of the machine. The M codes listed below are the common ones.
M-codes
M00
M01
M02
M03
M04
M05
M06
M07
M08
M09
M19
M30
M98
M99
Function
Optional program stop automatic
Optional program stop request
Program end
Spindle ON clock wise (CW)
Spindle ON counter clock wise (CCW)
Spindle stop
Tool change
Mist coolant ON (coolant 1 ON)
Flood coolant ON (coolant 2 ON)
Coolant OFF
Spindle orientation
End of program, Reset to start
Sub program call
Sub program end
There are other M-codes for functions like gear change, pallet change, pallet clamp / unclamp, door open /
close etc.
Y
N2
50
20
0,0
N1
30
50
CNC Milling
Programming
Feed
Feed
Part
Part
CNC Milling
Programming
Format
N__ G02/03 X__ Y__Z__ I__ J__K__ F__
OR
N__ G02/03 X__ Y__Z__ R__ F__
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.
Y
Arc start
Arc end
-I
-J
Arc center
Arc radius
CNC Milling
Programming
Arc start
Arc radius
Arc end
Arc center
Block format
N__ G02 X__Y__ Z__ R__ F__
N__ G03 X__Y__ Z__ R__ F__
G41
G41
G42
G42
Block format
CNC Milling
Programming
Program Zero
CNC Milling
Programming
Gauge line
Length offset
Length offset
Length offset
Length offset
Boring tool
Part
CNC Milling
Programming
10
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.
Examples : drilling, peck drilling, tapping, boring, back spot facing.
G81
Drilling cycle
G82
G83
G84
G85
G86
Boring cycle
G87
G74
G76
CNC Milling
Programming
11
Rapid
Rapid
Feed
Format
N__ G98/99 G81 R__ Z__ F__
Infeed feed rate mm/min
Final depth
Safe height / R point
Drilling cycle code
Return position code
Block number
CNC Milling
Programming
12
Rapid
Feed
Feed
Dwell at bottom
Dwell at bottom
Format
N__ G98/99 G82 R__ Z__ P__ F__
Infeed feed rate mm/min
Dwell at bottom
Final depth
Safe height / R point
Counter bore drilling cycle code
Return position code
Block number
CNC Milling
Programming
13
Rapid
Feed
Final depth
Initial
point
Feed
Final depth
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
CNC Milling
Programming
14
Rapid
Feed
Initial
point
Rapid
Feed
Spindle CW
Spindle CW
Final depth
Final depth
Spindle CCW
Spindle CCW
Format
N__ G98/99 G84 R__ Z__ F__
Infeed / retract feed rate mm/min
Final depth
Safe height / R point
Right hand tapping cycle code
Return position code
Block number
CNC Milling
Programming
15
Rapid
Final depth
Initial
point
Rapid
Feed
Final depth
Format
N__ G98/99 G85 R__ Z__ F__
Infeed / retract feed rate mm/min
Final depth
Safe height / R point
Reaming cycle code
Return position code
Block number
CNC Milling
Programming
16
Rapid
Rapid
Feed
Spindle CW
Spindle CW
R point / Safe height
Final depth
Final depth
Spindle stop
Spindle stop
Format
N__ G98/99 G86 R__ Z__ F__
Infeed feed rate mm/min
Final depth
Safe height / R point
Boring cycle code
Return position code
Block number
CNC Milling
Programming
17
Initial point
Bore axis
Lateral shift
Final depth
Safe height / R point
Spindle CW
Format
N__ G98
CNC Milling
Programming
18
Rapid
Feed
Initial
point
Rapid
Feed
Spindle CCW
Spindle CCW
Final depth
Final depth
Spindle CW
Spindle CW
Format
N__ G98/99 G74 R__ Z__ F__
Infeed / retract feed rate mm/min
Final depth
Safe height / R point
Left hand tapping cycle code
Return position code
Block number
CNC Milling
Programming
19
Rapid
Initial
point
Lateral shift
Rapid
Feed
Lateral shift
Spindle CW
Spindle CW
Final depth
Final depth
Dwell at
bottom
Dwell at
bottom
Lateral shift
Lateral shift
Spindle Orientation
Spindle Orientation
Format
N__ G98
CNC Milling
Programming
20
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
CNC Milling
Programming
21
CNC Milling
Programming
N2 X25.
N3 Z-50.
N4 X50.
N5 Z-100.
N2 X50.
N3 Z-50.
N4 X100.
N5 Z-100.
CNC Turning
Programming
List of G-codes
G-code
G00
G01
G02
G03
G04
G20
G21
G28
G30
G32 / G33
G40
G41
G42
G50 / G92
G70
G71
G72
G73
G74
G75
G76
G94 / G98
G95 / G99
G96
G97
Function
Positioning rapid traverse
Linear interpolation (feed)
Circular interpolation CW
Circular interpolation CCW
Dwell
Inch unit
Metric unit
Automatic zero return
2nd reference point return
Thread cutting (single motion)
Tool nose radius compensation cancel
Tool nose radius compensation left
Tool nose radius compensation right
Local co-ordinate system setting, max. spindle speed setting
Finishing cycle
Stock removal in turning
Stock removal in facing
Pattern repeating
Peck drilling on Z axis / Face grooving
Peck drilling on X axis / Int-Ext grooving
Multiple threading cycle
Feed per minute
Feed per revolution
Constant surface speed control
Constant surface speed control cancel
List of M codes
M codes vary from machine to machine depending on the functions available on it and the manufacturer of
the machine decides them. The M codes listed below are the common ones.
M-codes
M00
M01
M02
M03
M04
M05
M06
M07
M08
M09
M30
M98
M99
Function
Optional program stop automatic
Optional program stop request
Program end
Spindle ON clock wise (CW)
Spindle ON counter clock wise (CCW)
Spindle stop
Tool change
Mist coolant ON (coolant 1 ON)
Flood coolant ON (coolant 2 ON)
Coolant OFF
End of program, Reset to start
Sub program call
Sub program end
There are other M-codes for functions like gear change, tail stock quill in/out, chuck clamp/unclamp, chip
conveyor forward/backward, door open / close etc.
CNC Turning
Programming
Rapid traverse
Feed motion
CNC Turning
Programming
CCW arc
CW arc
Format
N__ G02/03 X__ Z__ I__ K__ F__
OR
N__ G02/03 X__ Z__ R__ F__
Arc center
The arc center is specified by addresses I and K. I and K are the X and Z co-ordinates of the arc center with
reference to the arc start point.
X
Arc start
Arc end
-K
-I
Arc center
Z
I =(X coord. of center - X coord. of start point)/2
K = Z coord. of center - Z coord. of start point
I and K must be written with their signs.
CNC Turning
Programming
Arc radius
The radius is specified with address R.
Arc radius
Arc end
Arc start
Arc center
X axis
CNC Turning
Programming
2. If tool nose radius compensation is not used for motion from P2 to P3, material is left out as shown in the
figure.
CNC Turning
Programming
Type No. 1
Type No. 2
Type No. 3
Type No. 4
Z
Z
X
X
Z
X
Type No. 5
X
Z
Type No. 6
Z
X
Type No. 7
Type No. 8
Z
CNC Turning
Programming
The direction of the imaginary tool nose viewed from the tool nose center is determined by the direction of
the tool during cutting.
3
Neutral tools
CNC Turning
Programming
10
G32
Thread cutting is done by moving the tool along the thread repeatedly at different depths tiil the final thread
profile is formed. Each cut must start at the same angular position on the part. The spindle has an encoder,
which generates a pulse at exactly the same angular position in every revolution. When a threading motion is
programmed, the linear motion of the tool starts when this pulse is detected. This ensures that every cut starts
at the same angular position.
Thread cutting must be done at constant spindle speed.
Block format
N__ G32 X__ Z__ F__
X, Z are the end point of the thread and F is the pitch of the thread.
The controller calculates feed rate through the following relationship
Feed rate = Pitch x Spindle speed
Each threading cut involves 4 motions: 1 threading motion and 3 rapid traverse motions. Since a thread
normally requires multiple cuts, G32 results in a long program and is not normally used. The G76 canned
cycle is normally used for threading.
CNC Turning
Programming
11
Canned cycles
A canned cycle simplifies a program by using a few blocks containing G-codes functions to specify the
machining operations usually specified in several blocks.
CNC Turning
Programming
12
CNC Turning
Programming
13
CNC Turning
Programming
14
Verifying NC programs
Safety priorities
Safety priorities must be followed when verifying programs.
Operator safety - priority 1
Safety of the person operating the machine
Machine tool safety - priority 2
Prevention of damage to the machine
Workpiece safety - priority 3
Prevention of part rejection
Typical errors
Syntax errors
This prevents 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
CNC Turning
Programming
15
CNC Turning