Lecture 3
Lecture 3
CNC Programming
G-codes
M-codes
What is G-
• Code?
Geometric code
• G-code is a language used to communicate to a
CNC machine. It tells the machine how to move
and what commands to execute.
• It is a way for a machinist to tell a CNC machine
what to do.
What is M-Code?
• Miscellaneous code
• Examples: coolant, spindle speed,
clockwise, counterclockwise and
changing to a specific tool number, etc.
Layout of a program
• % (it means the start of program)
• Program number (reference)
• Safety codes (safety codes to
cancel presets)
• Stock definition
• Tool change
• Move to position
• Spindle turns on
• Coolant turns on
• Cutting begins
• End of program
• Reset
The starting codes of
any program
%
O0000
N100 G21
N102 G0 G17 G40 G49 G80 G90
N104 G91 G28 Z0.0
N106 G91 G28 X0.0 Y0.0
N108 M06 T01
N110 G92 X….. Y…… Z…..
N112 G00 X0.0 Y0.0
N114 G43 H01
N116 G00 Z5.0
N118 M03 S…….. M07
Frequently used G Codes and their use
G00 --Rapid move to position---Quickly travels to the position specified by
X, Y, Z
G01– Move to position while cutting– Reaches position specified by X, Y, Z
while making cut
G02– Making clockwise cut– Makes arc/round cut
G03– Making anticlockwise cut--Makes arc/round cut
G17– XY plane– If the plane is changed due to previous program it will
again return to XY
G90– Absolute distance– Always considers from 0,0,0
G54– Cancel offset– Previous offset of 0,0,0 will be cancelled
G40– Cancel tool radius offset
G49– Cancel tool length offset
G94– Feed per minute
G41– tool compensation left of cut (looking from behind)– Considers the
tool radius
G42-- tool compensation right of cut (looking from behind)
G43– tool length compensation – Considers the tool length
G80-- Cancel all canned cycle– Canned cycle is used to do multiple similar
works like drilling in different positions with same parameters
G83– Pecking canned cycle– Used for peck drilling
G91– Incremental movement– Adds the given value with previous position
G04– Dwell– Stays in the specified position for given time. Its calculated as
1000th of a second. So 4000 will mean 4 second.
G20– Unit in inch
G21– Unit in mm
Frequently used M Codes and their
use
N, G, X, Y , Z, A, B, C, I, J,
K, F, S, T, R, M
F: feed rate of the tool motion
S: cutting-speed
T: tool number
CNC Words
N, G, X, Y , Z, A, B, C, I, J,
K, F, S, T, R, M
• X, Y, Z, A, B, C: provide the coordinate
positions of the tool. X, Y, and Z define
the three translational (Cartesian) axes of
a machine. A, B and C are used for the
three rotational axes about the X, Y, and
Z axes.
• I, J, K: specify the center for circular
motion
G codes
• Unit selection:
– G20 (inch), G21(metric)
• Coordinates selection:
– G90(absolute), G91(incremental)
• Working plane selection:
– G17(X-Y), G18(Z-X), G19(Y-Z)
G90 and G91
• G90: absolute distance;
represent positions in terms
of the currently active
coordinate system (Program
Zero)
• G91: incremental distance
mode; axis numbers
represent increments from
the current position.
G90 and G91
G90 and G91
G92
• G92 means “set an offset in
all coordinate systems”
• G92 X….. Y….. Z…. , the
values in (x, Y and Z) are the
distances between the
machine zero (home position
and the program zero)
G92
• G92 means “set an offset in
all coordinate systems”
• G92 X10.0 Y5.0 Z0.0
G92 and G43
• The program
zero at Z is the
same at home
position without
installing any
tool.
• G43 H0… makes
the
compensation
offset with the
values saved in
the tools table
G92 and G43
Tool Tool Diameter Height
Number Description
T01 Center Drill 3 -50
T02 Drill bit 10 -5
T03 End Mill 8 -30
T04 Face Mill 75 -6
T05 Tap Mill 12 -25
G90: Y
absolute 100 R50
coordinates 60 R60
40
X
O 90 120 140 200
Circular interpolation:
G02, G03
Circular
interpolation: G02,
G03
Annotation for Circular
Interpolation
– I0.0, J0.0, and K0.0 can be omitted.
– If X,Y,Z are all omitted in the
program, that means start and end
of arc are same points.
N0020 G02 I20.0 (a full circle)
– If I, J, K, and R all appears in
circular interpolation instruction, R
is valid and I, J, and K are invalid
Circular interpolation:
G02, G03
N0020 G02 I20.0 (a full circle)
Circular interpolation:
G02, G03
(a full circle)
M code
• miscellaneous word
• miscellaneous functions:
– turn the spindle on/off
– start/stop the machine
– turn on/off the coolant
– change the tool
– rewind the program (tape)
M code
M00 Program stop M06 Tool change
Flood coolant
M01 Optional stop M07
on
modal groups
M code: M00, M01
Define Tool
CNC data
Make 3D model
Simulate
cutting