0% found this document useful (0 votes)
486 views56 pages

G-Code Programming Overview

This document provides an introduction to G-code programming for computer numerical control (CNC) machining. It reviews coordinate geometry basics, common terminology, and the G and M code programming language. It examines the rectangular and 3D coordinate systems, basic machine axes, additional optional axes, and common terminology. It also describes linear and circular interpolation methods, canned cycles, cutter compensation, zero points, cutter path generation, and cautions about multiple axis movements.

Uploaded by

hasan alsarraf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
486 views56 pages

G-Code Programming Overview

This document provides an introduction to G-code programming for computer numerical control (CNC) machining. It reviews coordinate geometry basics, common terminology, and the G and M code programming language. It examines the rectangular and 3D coordinate systems, basic machine axes, additional optional axes, and common terminology. It also describes linear and circular interpolation methods, canned cycles, cutter compensation, zero points, cutter path generation, and cautions about multiple axis movements.

Uploaded by

hasan alsarraf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

IIntroduction

t d ti to t G-Code
GC d
Programming
Comp ter Integrated Manufacturing
Computer Man fact ring

Unit 2: CNC Machining


In this lesson:
lesson
Review Coordinate Geometry Basics
Identify common Terminology
Examine G and M - Code language
Provide opportunities for Review and
Practice
Rectangular Coordinate System
Y-axis

A (X,Y)
(1,.875)
X axis
X-axis

Origin
g

.125 inch spacing


Ordered Pairs
(1.000,1.000
A )
( 1 125 625)
(-1.125,.625)
B

C
D
(.750,-1.000)

(-.375,-.500)
3D Coordinate System (X
(X,Y,Z)
Y Z)

Z- Y-axis
axis

X-axis
Basic Machine A
Axes:
es 3 axis
a is
Milling Machines: 3 axis
X – axis (table left and
right)
Y – axis (table in and out)
Z – axis (usually the
spindle axis)
Additional Axes
A es
A – axis
i ((angular
l axisi about
b t X - axis)
i )
B – axis ((angular
g axis about Y – axis))
C – axis (angular axis about Z – axis)

U – axis ((secondaryy axis p


parallel to X))
V – axis (secondary axis parallel to Y)
W – axis
i ((secondary
d axis
i parallel
ll l tto Z)
Milling Machines: 4 axis
Terminology
NC – Numerical Control
CNC – Computer Numerical Control
DNC – Direct Numerical Control
APT – Automatic Programmed Tool
CAD – Computer Aided Design
CAM – Computer Aided Manufacturing
CIM – Computer Integrated Manufacturing
Do nload Code Sheet
Download

Click here to open Code Sheet


G - Code Programming
G – Code
C d P Programming i
g y called the “Word Address”
Originally
programming format.

Processed one line at a time sequentially.


Common Format of a Block
Sequence Preparatory Dimension Feed Spindle Tool Misc.
# Function Words Rate Function Function Function

N50 G90 G01 X1.40Y2.25 F10 S1500 T01 M03

Individual Words
Reserved Code Words Worksheet
N – Sequence or line number
G – Preparatory function
f

Di
Dimension
i Words:
W d
X–
Y–
Z–
Word Address 1
N – Sequence or line number
A tag that identifies the beginning of a block of
code It is used by operators to locate specific
code.
lines of a program when entering data or verifying
the program operation.

G – Preparatory function
G words specify the mode in which the milling
machine is to move along its programmed axes.
Word Address 2
Dimension Words
X – Distance or position in X direction
Y – Distance or position in Y direction
Z – Distance or position in Z direction

M – Miscellaneous functions
M words specify CNC machine functions not
related to dimensions or axial movements.
Word Address 3
F – Feed rate (inches per minute or millimeters per
minute)
Rate at which cutting tool moves along an axis
axis.

S – Spindle speed (rpm – revolutions per minute)


Controls spindle rotation speed.

T – Tool number
Specifies tool to be selected.
selected
Word Address 4
I – Circular cutting reference for x axis

J – Circular cutting reference for y axis

K – Circular cutting reference for z axis


G Word
G words
d or codes
d tell
t ll th
the machine
hi tto
perform certain functions. Most G
words are modal which means they
remain in effect until replaced
p by
y
another modal G code.
Common G Codes
G00 – Rapid positioning mode
Tool is moved along the shortest route to
programmed X X,Y,Z
Y Z position
position. Usually NOT
used for cutting.
G01 – Linear Interpolation mode
Tool is moved along a straight-line path at
programmed rate of speed.

G02 – Circular motion clockwise (cw)


G03 – Circular motion counter clockwise
(ccw)
Common G Codes,
Codes con.,
con
G17 – XY plane
G18 – XZ plane
G19 – YZ plane
G20 – Inch Mode
G21 – Metric Mode
G28 – Return to axis machine Zero
(H
(Home) )
G Codes:
Codes G90
G90, G91
G90 – Absolute Coordinate Reference
References the next position from an absolute
zero point which is set once for the entire
program.

G91 – Incremental Coordinate Reference


References the next position from the previous
position.
position
G Codes:
Codes Canned C
Cycles
cles
G80 – Cancel canned cycle
G81 – Drilling cycle
G83 – Peck
P kd drilling
illi cycle
l
G84 – Tapping cycle
G85 – Boring cycle
G86 – Boring g cycle
y

NOTE: A canned cycle


y stays
y in effect until
cancelled by a G80.
Canned C
Cycles:
cles G81
G81 – Drilling Cycle
Feed to depth, rapid return

Example of program code:


N35 G81 X.500Y.500Z-1.000
X 500Y 500Z 1 000 R.100
R 100 F1.50
F1 50
N36 X1.000Y1.500
N37 X1.500Y2.000
X1 500Y2 000
N38 G80
Canned C
Cycles:
cles G83
G83, G84
G83 – Peck Drilling Cycle
Feed to an intermediate depth, rapid out, rapid
back to just above previous depth
depth, feed to next
depth, rapid out, repeat until reaching full depth.

G84 – Tapping Cycle


This cycle
y creates internal threads in an existing
g
hole.
NOTE: One cannot over-ride the feed rate.
Canned C
Cycles:
cles G85
G85, G86
G85 - Boring Cycle
Feed to depth, feed back out.

G86 – Boring Cycle


Feed to depth, rapid out.
G Codes:
C d Cutter
C tt C Compensation
ti
G40 – Cancel
C l cutter
tt diameter
di t
compensation.
G41 – Cutter compensation left.

G42 – Cutter compensation right.


M Word
M words tell the machine to perform
certain machine related functions,
such as: turn spindle on/off, coolant
on/off, or stop/end program.

Professional Development ID Code: 6006


Common M words
ords
M00 – Programmed pause
Automatically stops machine until operator pushes a button
to resume program.
p g

M01 – Optional stop


A stop acted upon by the machine when operator has
signaled this command by pushing a button.

M02 – End of program


Stops program when all lines of code are completed
completed. Must
be last command in program.
Common M words
ords
M03 – Turn spindle on
In clockwise direction

M04 – Turn spindle on


In counter clockwise direction

M05 – Stop
St spindle
i dl
Usually used prior to tool change or at end of program.

M06 – Tool change


Stops program and calls for a tool change, either
automatically or manually
manually.
Common M words
ords
M08 – Turns Accessory 1 on.
on
M09 – Turns Accessory 1 off.

M10 – Turns Accessory 2 on.


M11 – Turns
T Accessory
A 2 off.
ff

M30 – End of program


Similar to M02 but M30 will also “rewind” the program.
Must be last statement in program.
program If used
used, DO NOT
use M02.
Zero Points
P t Zero
Part Z
– Used for absolute programming mode.
– Usually
U ll a position
iti on th
the partt th
thatt allll absolute
b l t
coordinates are referenced to.
– Changes with different parts and programs
programs.

Machine Zero or Machine Home Position


– Fixed for each machine from the manufacturer.
– Not changeable.
C tter Path Generation
Cutter
Cutter
C tt path th is
i generated
t dbby moving
i ththe
tool from point to point. The points are
previously defined from the part
drawing g dimensions.
Each line of code will show the
destination point of where the tool will
go to.
g
Interpolation
Method of determining intermediate
points along
p g a cutting
gppath.

T
Two methods:
th d
• Linear interpolation – cut a path along a
specified
ifi d angle
l att a specified
ifi d ffeed
d rate.
t
• Circular interpolation – cut a path along an arc
or circle
i l att a specified
ifi d ffeed
d rate.
t
A is movements:
Axis mo ements Caution!
Ca tion!
Multiple axis movements are possible.
“Bestt Practice”
“B P ti ” iis NOT to
t make
k a 3-axis
3 i
movement using one line of code.
Move to position using two axes, X,Y;
th move th
then the Z with
ith an additional
dditi l
line of code.
E
Example
l 1:
1 NC Bl
Block
k
.125 GRID
T
Top View
Vi NC Bl
Block
k SPACES

Origin
(0,0)
Do nload Worksheet
Download

Click here to open Practice Exercises


.125 GRID
Worksheet Problem 1 SPACES

D( , ) I( , ) J( , )
B( , ) K( , )

L( , )

E( , )
A( , )

F( , )

C( , )
H( , ) G( , )
Origin
(0,0)
Pa se Lesson
Pause
E ample 1:
Example 1 Program NC
N01 G90 G80 T00
N02 G00 X0 Y3.000 Z1.000
N03 M03 S1000
E ample 1:
Example 1 Program NC
N01 G90 G80 T00
N02 G00 X0 Y3.000 Z1.000
N03 M03 S1000
N04 X.375 Y.250 Z1.000
N05 Z.100
Z 100
N06 G01 Z-.100 F5.00
N07 Y1.750
E ample 1:
Example 1 Program cont’d
N08 X1.250
X1 250 Y.250
Y 250
N09 Y1.750
N10 G00 Z.100
N11 X2.625
X2 625 Y.500
Y 500
N12 GO1 Z-.100
N13 X2.375 Y2.50
N14 X2.000
E ample 1:
Example 1 Program cont’d
N15 X1.750
X1 750 Y.500
Y 500
N16 Y1.500
N17 X2.000 Y1.750
N18 X2.375
N19 X2.625 Y1.500
E ample 1,
Example 1 con.,
con
N20 G00 Z1.000
Z1 000

N21 X0 Y3.000
Y3 000
N22 M05
N23 M30
E
Example
l 2:
2 PLTW Block
Bl k
.250 GRID
Worksheet Problem 2 SPACE

Oi i
Origin
E ample 2:
Example 2 Top View
Vie M( ,
)
F( , K( ,
J( , ) I( , )
C( , ) ) O( ,
) )

B( ,
) Q( ,
E( , )
)
A( ,
)

L( , P( ,
D( , ) )
G( , ) N( ,
) H( ,
)
Origin )

.250 Grid Space


Pa se Lesson
Pause
E ample 2:
Example 2 PLTW
N01 G90 G80 T01
N02 G00 X0 Y0 Z1.000
N03 M03 S1000
N04 X.750
X 750 Y.500
Y 500 Z1.000
Z1 000
N05 Z.100
N06 G01 Z-.250 F5.00
N07 Y2.500
E ample 2:
Example 2 PLTW cont’d
N08 X1.250
X1 250
N09 G02 X1.250 Y1.500 I1.250 J2.000
N10 G01 X.750
N11 G00 Z.100
Z 100
N12 X2.250 Y2.500
N13 G01 Z-.250
N14 Y.500
E ample 2:
Example 2 Program cont’d
N15 X3.250
N16 G00 Z.100
N17 X4.000
N18 G01 Z-.250
N19 Y2.500
Y2 500
N20 X3.500
N21 X4.500
E ample 2:
Example 2 PLTW cont’d
N22 G00 Z.100
N23 X5.000 Y2.500
N24 G01 Z-.250
N25 X5.500 Y.500
N26 X5.750
X5 750 Y1.500
Y1 500
N27 X6.000 Y.500
N28 X6.500 Y2.500
E ample 2:
Example 2 PLTW cont’d
N29 G00
G Z1.000
N30 X0 Y0
N31 M05
N32 M30
Curriculum Alignment:

Unit 2: CNC Machining


Section 2.3 – CNC Machining
P
PowerPoint
P i t – Introduction
I t d ti to t CNC
PowerPoint – CNC Programming
R f
References:
Oberg, E. & Jones F. D. & Horton, H. L. & Ryffell,
H H.
H. (2000). Machinery
H (2000) Handbook, 26th
Machinery’ss Handbook
ed., New York, NY: Industrial Press Inc.

Valentino, J.V. & Goldenberg, J. (2003).


Introduction to Computer Numerical Control
(CNC), 3rd ed., Upper Saddle River, NJ:
Prentice Hall
Credits:
Writer: Bob Arrendondo
Content Editor: Donna E. Scribner
Narration: Donna E. Scribner
PLTW Editor: Ed Hughes
g
Production: CJ Amarosa
Video Production: CJ Amarosa
Audio: CJ Amarosa
P j t Manager:
Project M D
Donna E
E. S
Scribner
ib

Common questions

Powered by AI

G codes in CNC machining are used to specify the modes and movements of the machine along its programmed axes, controlling operations such as rapid positioning (G00) and linear interpolation (G01). M codes, on the other hand, are used to handle the control functions of the machine, such as turning the spindle on or off (M03, M05) and stopping the program (M00, M30). The primary difference is that G codes deal with the motion and positioning within the machining process, whereas M codes manage auxiliary functions.

Challenges from using a 3-axis movement in a single line of code include potential tool collisions, difficulty in maintaining precision, and increased complexity in troubleshooting errors . These challenges can be mitigated by breaking movements into two-dimensional moves, such as operating X and Y first, followed by Z-axis adjustments with a separate line . This method ensures each axis correction is manageable and reduces the risk of expensive errors, maintaining overall machining accuracy.

Interpolation in CNC machining enhances capabilities by governing the paths along which tools move to meet precise specifications. Linear interpolation allows the tool to follow a straight path at a predetermined angle and feed rate, while circular interpolation enables movement along an arc or circular path . These functions facilitate complex geometry machining by ensuring that tools can travel along paths that match design requirements, thus enabling higher precision and diverse cutting profiles.

Tool function words in G-code, notably indicated by the 'T' code, specify which tool should be selected and used for a given operation . This allows the CNC machine to automatically change between different cutting tools as specified in the program, leading to higher efficiency in operations that require different tooling for different shapes or materials. By automating tool selection, these codes minimize downtime and human error during tool changes.

Zero points in CNC machining establish the reference positions for toolpath calculations, impacting both accuracy and repeatability of operations. Part zero, specific to each part and program, allows consistent reference for absolute coordinates, essential for precise manufacturing of components . Machine zero, a fixed position defined by the machine's manufacturer, ensures repeatability of operations across different sessions . Accurate setting and use of zero points are critical for reliable and consistent CNC outputs.

Rapid positioning (G00) is used to move the tool quickly along the shortest path to a given position, typically employed for moving the tool between operations rather than during cutting, as it is not used for machining operations . Linear interpolation (G01) moves the tool along a straight-line path at a specified feed rate, crucial for cutting operations that require precision in straight-line machining . The distinction is in their utility; rapid positioning maximizes efficiency in non-cutting moves, while linear interpolation ensures precision and control during cutting.

In an absolute coordinate system (G90), positions are specified from a fixed origin point, meaning every point is defined from an absolute zero set once for the entire program . In contrast, the incremental coordinate system (G91) refers to positions relative to the last point, so each new coordinate is related to the previous position . This allows flexibility in programming when movements are relative, but absolute coordinates are essential for consistency in repeated processes.

Cutter compensation impacts CNC machining by allowing the tool path to be offset to account for the actual diameter of the cutting tool, ensuring the finished part adheres to the intended dimensions . G41 applies compensation to the left of the cutting path, while G42 applies it to the right. This adjustment is crucial for precise cutting operations, as it compensates for tool wear and discrepancies in tool diameter, maintaining the accuracy of the machined component.

Canned cycles in CNC machining are predefined sets of operations that allow for efficient programming of repetitive tasks, such as drilling or tapping, by reducing the need to write extensive code for common machining processes . For example, G81 is a drilling cycle that feeds to a depth and returns rapidly, while G83 is a peck drilling cycle that removes material in steps to prevent chip build-up . Using these cycles simplifies programming and helps ensure consistent production.

Coordinate geometry is fundamental in CNC machining as it defines how a machine interprets and executes movements along the X, Y, and Z axes. In a three-axis milling machine, these coordinates allow precise positioning of the cutting tool, with the X-axis moving left and right, the Y-axis moving in and out, and the Z-axis typically representing the spindle movement . This geometry enables accurate shaping of materials according to the programmed design by converting coordinate data into physical movements.

You might also like