CNC Programming Intro & Code PDF
CNC Programming Intro & Code PDF
CNC Programming Intro & Code PDF
2
What is NC and CNC technology?
NC - emerged in the mid 20th century
• Numerical Control
• Can be traced back to the U.S. Air
Force, MIT, John Parsons
• Definition: Operation of machine
tools by means of specifically coded
instructions to the machine control
system
• Uses fixed logical functions that are
built-in and permanently wired
within the control unit
• “Hardwired”
What is NC and CNC technology?
NC - emerged in the mid 20th century
• Numerical Control
• Can be traced back to the U.S. Air
Force, MIT, John Parsons
• Definition: Operation of machine
tools by means of specifically coded
instructions to the machine control
system
• Uses fixed logical functions that are
built-in and permanently wired
within the control unit
• “Hardwired”
What is NC and CNC technology?
NC - emerged in the mid 20th century
• Numerical Control
• Can be traced back to the U.S. Air
Force, MIT, John Parsons
• Definition: Operation of machine
tools by means of specifically coded
instructions to the machine control
system
• Uses fixed logical functions that are
built-in and permanently wired
within the control unit
• “Hardwired”
What is NC and CNC technology?
CNC - Also emerged in the mid 20th century, about 20 years after NC
Computerized Numerical Control
Modern CNC systems use an internal microprocessor
Results in the ability of the user to change any program at the control unit
Greatly increases the tool’s flexibility
Advantages and Disadvantages
Advantages Disadvantages
• Highly accurate • High cost
• Short production • Maintenance
time • Training costs
• Reliable • Complex
• Flexible programming
• Simpler fixturing (requires skilled
• Contour machining workers)
• Space
Types of CNC Machine Tools
Mills and Machining Centers
Lathes and Turning Centers
Drilling Machines
Boring mills and Profilers
EDM Wire Machines
Punch presses and Shears
Flame cutting Machines
Routers
Water Jet & Laser profilers
Cylindrical Grinders
Welding Machines
Benders, Winding and Spinning Machines
CNC Milling Machine
CNC Milling Machine
CNC Lathe
CNC Flame/Plasma Cutting Machine
CNC Water Jets
Machine Control Unit
• A microcomputer that stores the program and executes the commands into
actions.
• The MCU consists of two main units: Data Processing Unit (DPU) and the
Control Loops Unit (CLU)
– CLU: consists of the circuits for position and velocity control loops,
acceleration/de-acceleration and functions such as spindle ON/OFF.
Machine Control Unit
Human-
machine
Servo drives
interface
PLC
G-code
interpreter
Digital scales
Cartesian Coordinate system
• Right Hand Rule: Three axes positioned
90 degrees from each other
CNC Sequence/Interface
CNC Milling
Definition: A Milling machine is a machine capable of
simultaneous cutting motion, using an end mill as the primary
cutting tool, along at least two axes at the same time
Common for modern CNC Milling machines to have more than 2
axes
Milling machines can be divided into three categories
By number of axes (2, 3, or more)
By the orientation of axes (vertical or horizontal)
By the presence or absence of a tool changer
CNC Milling, Machine Axes
• Milling machines and machining centers have at least three axes :
X,Y, Z.
• Flexibility can be further increased if they incorporate a 4th axis
(usually an indexing or rotary axis)
• Even more flexibility can be found on machines with 5 or more
axes ( usually 3 main ones + a rotary and one parallel to the Z)
https://www.youtube.co
4 axis m/watch?v=HpG9qlYFj
FU
https://www.youtube.com/watch
5-axis ?v=xZOiNdkJ8SU
CNC Milling, Machine Axes
• Vertical Machining Centers
• Most of the machining is
done on one face
• Mainly used for cutting
flat(-ish) parts
• Multiple axes can improve
flexibility
• Lighter maching
operations
CNC Milling, Machine Axes
https://www.youtube.com/watch?
v=KaMmVjTcAbw
• Horizontal Machining Centers
• Categorized as multi-tool and
versatile machines
• Mainly used for cutting
cubical parts
• Majority of machining has to
be done on more than one
face in a single step
• Much heavier machines,
faster stock removal
• Well suited for multi part
setups
Parts of a vertical mill
Vertical Milling Center Machine
Coordinates:
CNC Turning
CNC Turning Centers, AKA CNC Lathes
Can be categorized by type of design and number of axes
Front Lathe - An engine lathe type with flat ways
Slant Bed – ways tilted towards vertical
Most vertical CNC Lathe designs have two available axes
Horizontal CNC Lathe designs commonly have two axes, but are
also available with 3, 4, 6, or more axes, adding more flexibility to
the manufacturing of more complex parts
A typical CNC Lathe is designed with two standard axes: X and Z
X axis represents the cross-travel of the cutting tool
Z axis represents the longitudinal motion of the cutting tool
X and Z are perpendicular to each other
CNC Turning
CNC Lathe Axes
Lathe coordinates:
Coordinate Geometry
One of the first major steps towards basic understanding of CNC
principles and geometrical concepts is through understanding the
system of coordinates
Founded on a number of mathematical principles such as the real
number system and rectangular coordinates
Real Number System
Zero integer
Positive integers
Negative integers
Fractions
Decimal fractions
Rectangular Coordinate System
4-axis, 5 axis + setup:
Control System
In order to fully understand CNC Programming, it is especially
important to know how the computer, the CNC unit, actually
works. Below is a diagram of a Fanuc Control Panel
Control Systems Cont’d
Any control unit has two basic components
Operation panel
Rotary switches, toggle switches, push buttons
Display screen with a keyboard or a keypad
Is the window to control operations
Any active program can be viewed, even a graphical representation of the
toolpath
The keyboard is used to input instructions to the control
Existing programs can be modified or deleted
New programs can be added
It is important that the programmer knows and understands all of
the functions of the control system
Control System Cont’d
A typical operation panel of a CNC machining
center
Control System Cont’d, Important features
Handle
For setup purposes, CNC Machines have a rotary handle that will
move the selected axis by a certain multiplied increment
See adjacent figure
Control System Cont’d, Important Features
Parameter settings
Binary codes
Unit inputs
Settings values
Manual Program Interruption
Single Block Operation
Sequential operations
Feedhold
Special push button that stops all feeds on all active axes
Emergency Stop
Mushroom shaped, red button in a very accessible place on the machine.
All machine activity will stop and the main power supply will be cut off
Control System Cont’d, Important Features
Memory capacity
Programs are stored in the control memory, limited by capacity
Manual Data Input (MDI)
Enables the input of program data into the system one line at a
time
Program Data Override
Rapid Feedrate Override (Rapid traverse)
Spindle speed override
Feedrate override (Cutting rate)
Dry run mode
Program Planning
Development of any CNC Program should always begin with a very carefully planned process.
Typically starts with an engineering drawing or blueprint
This is done before any machining process is done
Basic steps and things to consider:
Initial Information Provided / Machine tools features
Part complexity / Evaluation of Machining features
Manual programming / computerized programming
Typical programming procedure / Program structure
Part drawing / Engineering Data
Methods sheet / Material Specifications
Machining sequence - Operations / tool order
Tooling selection / cutting holders / inserts / HSS Tools
Part setup / Part Holding / Fixtures
Technological decisions / cutting conditions
Work sketch and individual calculations
Quality considerations in CNC Programming
Program Planning Cont’d
Initial Information
The main purpose of most engineering drawings is to define the part
shape, individual dimensions, and relationships between part features
Machine features
Be sure that the selected CNC machine is suitable for a particular job
Take into account machine type and size
Being familiar with the CNC’s control system
Part Complexity
How difficult is it to manufacture the part? Manually? Automatically?
Machine capabilities?
Cost?
Many simple jobs can be given to a less experienced programmer or to a
CNC operator
Program Planning Cont’d
Manual Programming
Without a computer, is a very common method in preparing a part
program
Good for few uses, but should develop into a repeatable program if used
more frequently
Disadvantages
Length of time required to develop a fully functional program
Manual calculations
Large percentage of errors
Lack of tool path verifications
Advantages
Offers virtually unlimited freedom in actual development
Teaches a tight discipline and organization in program preparation
Forces programmer to understand programming techniques to a very fine level
of detail
Program Planning Cont’d
The use of CAD/CAM is also considered manual programming
due to the fact that a user has to design the part in a 3D software.
Part Drawing
The single most important document used in CNC Programming
Identifies the shape, important dimensions, tolerances, surface
finish, and other requirements
Computer-aided design (CAD)
• Computer‐aided
design (CAD) is the
use of computer
systems to assist in
the creation,
modification,
analysis, or
optimization of a
design.
Computer-aided manufacturing (CAM)
• Computer‐aided
manufacturing (CAM)
is the use of computer
systems to plan,
manage, and control
the operations of a
manufacturing plant
through direct or
indirect computer
interface with plant’s
resources.
Computer Aided Engineering
(CAE)
• Computer Aided
Engineering (CAE)
use of computer
systems to analyze
CAD geometry.
– It allows the designer
to simulate how the
product will behave
allowing for
optimization.
• Finite Element
Method (FEM)
– Divides model into
interconnected
elements
– Solves continuous
field problems
CAD/CAM/CAE
How CAD/CAM/CAE works:
• Developing NC code requires an understanding of:
1. Part geometry
2. Tooling
3. Process plans
4. Tolerances
5. Fixturing
• Most CAD/CAM/CAE systems provide access to:
1. Part geometry
2. Tooling
Program Planning Cont’d
Methods sheet
Some companies have a staff of qualified manufacturing
technologists or process planners responsible for determining all
manufacturing processes
Develop a series of machining instructions
Detailing the exact route of each part through the manufacturing process
Instructions are written on a Methods sheet
Material specifications
Material stock
Raw material such as a bar, billet, plate, forging, casting
The size and shape of the material determines that setup mounting method
Material Uniformity
Machinability Rating
Basic Motion G-Codes
Code Use
G00 Move at rapid speed to a new position
G01 Move at a controlled feed to a new position (cutting)
G02 Move in a clockwise circular arc at controlled feed (cutting)
G03 Move in a counterclockwise arc at controlled feed (cutting)
These are “modal” codes. Once used, the control assumes all new coordinates are using
the same command until a new one is invoked
On old controllers with limited memory, extra zeroes used up too much space in small
moves
So they were implemented to work in 1/1000 inch increments unless the decimal place was
inserted
Code Use
G20 Sets units as INCHES
G21 Sets units in mm
G81 Simple drilling canned cycle
Code Use
X Distance along X axis
Y Distance along Y axis
Z Distance along Z axis
A 4th axis
B 5th axis
C 6th axis
G00
Syntax:
This command would go from wherever the tool is at the moment and drive it to:
• 5 inches in positive X direction from machine zero position
• 1 inch in positive Y direction from machine zero position
• 3 inches in negative Z direction from machine zero position
This command would go from wherever the tool is at the moment and drive it to:
• 5 inches in positive X direction from machine zero position
• 1 inch in positive Y direction from machine zero position
• 3 inches in negative Z direction from machine zero position
X5 Y1
Y
X
G00
Do not use for cutting as it will likely break
Syntax: the tool! Straight line path is not guaranteed!
X5 Y1
Y
X
G01
Syntax:
Move from current position to position X, Y, Z at F inches per minute (or mm/min if in G21 mode)
This command would go from wherever the tool is at the moment and drive it to:
• 5 inches in positive X direction from machine zero position
• 1 inch in positive Y direction from machine zero position
• 3 inches in negative Z direction from machine zero position
All these motions occur simultaneously, so use caution. Path will be a straight line in 3 dimensions at
5 inches/min speed
G01
Syntax:
G01 X5. F5
Usually do Z motions and X,Y motions separately unless you are doing 3D profiles.
Move from current position to position X, Y at F inches per minute (or mm/min if in G21 mode)
following a clockwise circular path with centerpoint displaced by I in the X direction and J in the Y
direction
ending
Starting point X,Y
point
J
I centerpoint
G02
Syntax:
(starting from X0, Y0) Complete clockwise circle starting from X0 Y0, radius=2
Starting
point
centerpoint
I=1
G02
Syntax:
(starting from X0, Y0) Complete clockwise circle starting from X0 Y0, radius=2
Starting
point
I=-1
G03
Syntax:
Move from current position to position X, Y at F inches per minute (or mm/min if in G21 mode)
following a counterclockwise circular path with centerpoint displaced by I in the X direction and J in
the Y direction
Starting
ending
point
point X,Y
J
centerpoint I
G17
Specifies that G2 and G3 commands produce a circular motion in the XY plane
Z
I is center displacement
in X direction
Y
X
G18
Specifies that G2 and G3 commands produce a circular motion in the XZ plane
Z
I is center displacement
in X direction
G03 X0. Y0. Z0. I1. K0. F5
K is center
displacement in Z
direction
Y
X
G19
Specifies that G2 and G3 commands produce a circular motion in the YZ plane
Z
J is center
displacement in Y
direction G03 X0. Y0. Z0. J1. K0. F5
K is center
displacement in Z
direction
Y
X
What path does this code generate?
G17
G0 X0 Y0
G03 X0. Y0. I0. J1. F5
G02 X0 Y0 I0 J-1 F5
Other Basic Words
Code Use
M03 Start spindle rotating clockwise (viewed from above)
M04 Start spindle rotating counterclockwise (viewed from above)
M05 Stop spindle rotation
M08 Turn on flood coolant
M09 Turn off flood coolant
M30 End of program, rewind
N6 ( Rough Mill2 )
N7 G90 G54 G00 X-.06 Y-1.56
N8 G43 Z1. H09 M08
N9 G01 Z-.1 F3.
N10 G17 Y.06 F10.
N11 X3.06
N12 Y-1.56
N13 X-.06
.....
N6 ( Rough Mill2 )
N7 G90 G54 G00 X-.06 Y-1.56
N8 G43 Z1. H09 M08
N9 G01 Z-.1 F3.
N10 G17 Y.06 F10.
N11 X3.06
N12 Y-1.56
N13 X-.06
.....
N6 ( Rough Mill2 )
N7 G90 G54 G00 X-.06 Y-1.56
N8 G43 Z1. H09 M08
N9 G01 Z-.1 F3.
N10 G17 Y.06 F10.
N11 X3.06
N12 Y-1.56
N13 X-.06
.....
.....
.....
.....
.....
.....
.....
.....
.....
Never changes
Cat30
Cat40
Cat50
BT taper
NMTB taper
Tormach TTS
ZTCS = 4.000 in
Replace Tool 1 with Tool 2
Tool 1 length
L1 = 5.347 in
Tool 2 length
L1 = 3.758 in
Tool offset
1.589 in
.....
.....
.....
.....
.....
.....
.....
.....
N6 ( Rough Mill2 )
N7 G90 G54 G00 X-.06 Y-1.56
N8 G43 Z1. H09 M08
N9 G01 Z-.1 F3.
N10 G17 Y.06 F10.
N11 X3.06
N12 Y-1.56
N13 X-.06
.....
N6 ( Rough Mill2 )
N7 G90 G54 G00 X-.06 Y-1.56
N8 G43 Z1. H09 M08
N9 G01 Z-.1 F3.
N10 G17 Y.06 F10.
N11 X3.06
N12 Y-1.56
N13 X-.06
.....
Move from current position to position X, Y at F inches per minute (or mm/min if in G21 mode)
following a clockwise circular path with centerpoint displaced by I in the X direction and J in the Y
direction
ending
Starting point X,Y
point
J
I centerpoint
G02
Alternative Syntax:
Move from current position to position X, Y at F inches per minute (or mm/min if in G21 mode)
following a clockwise circular path with radius R
ending
Starting point X,Y
point R
centerpoint
G02
Alternative Syntax:
The R word is modal. Useful if you are doing a series of fillets or similar features
R1 G01 X0 Y5 F5
G02 X1 Y10 R1
G01 X9 Y10
G02 X10 Y9
G01 X10 Y1
G02 X9 Y0
G01 X1 Y0
G02 X0 Y1
Starting
point
G02
Syntax:
(starting from X0, Y0) Complete clockwise circle starting from X0 Y0, radius=2
Starting
point
centerpoint
I=1
G02
Alternative Syntax:
(starting from X0, Y0) Complete clockwise circle starting from X0 Y0, radius=1
Starting
point
centerpoint
R=1
G02
Alternative Syntax:
(starting from X0, Y0) Complete clockwise circle starting from X0 Y0, radius=2
Starting
point Centerpoint undefined
Starting
point
X1 Y2
R=1
X2 Y1
G02
Alternative Syntax:
Starting
point R=1
X1 Y2
X2 Y1
G02
Alternative Syntax:
R= -1
X1 Y2
R=1
Some: Specify the longer pathway by using
negative R value
X2 Y1
Some controllers do not allow crossing a
quadrant boundary for circular arcs (90o arcs
maximum)
Canned Cycles
Rapid move to X1 Y0
Rapid move to X1 Y0
G00 X0 Y0 Z3
Move in Z direction at speed 5 inches/min to a depth of Z = -1
G91 G81 X1 Y0 Z-1 R2 K3 F5
Rapid retract to Z = 2
Rapid move to X2 Y0
Rapid retract to Z = 2
Rapid move to X3 Y0
Rapid retract to Z = 2
Canned Cycles
Rapid move to X1 Y0
Rapid retract to Z = 2
Canned Cycles
Rapid move to X0 Y0 Z3
Retract to Z = 2
Canned Cycles
Rapid move to X0 Y0 Z3
Rapid move to X1 Y0
G00 X0 Y0 Z3 S150 M03
Move spindle down until Z = -1 is reached. Feedrate is
G90 G84 X1 Y0 Z-1 P500 R2 F20
specified in threads/inch with the G84 command – thus, the
spindle moves down 1/20 inch for every revolution of the
spindle – dwell for P msec
Rapid move to X1 Y0
G00 X0 Y0 Z3 S150 M03
Move spindle down until Z = -1 is reached. Feedrate is
G90 G74 X1 Y0 Z-1 P500 R2 F20
specified in threads/inch with the G84 command – thus, the
spindle moves down 1/20 inch for every revolution of the
spindle – dwell for P msec
Rapid move to X1 Y0
G00 X0 Y0 Z3 S150 M03
Move spindle down until Z = -1 is reached. Feedrate is
G90 G84.2 X1 Y0 Z-1 P500 R2 F20
specified in threads/inch with the G84 command – thus, the
spindle moves down 1/20 inch for every revolution of the
spindle – stop and dwell for 500 msec
Uses a spindle position sensor Reverse spindle to 150 rpm in CCW direction
that perfectly synchronizes motion
in Z direction with rotation Move spindle up until Z = 2 is reached. Feedrate is specified in
threads/inch with the G84 command – thus, the spindle moves
up 1/20 inch for every revolution of the spindle
Canned Cycles
Rapid move to X0 Y0 Z3
Rapid move to X1 Y0
G00 X0 Y0 Z3 S150 M03
Move spindle down until Z = -1 is reached. Feedrate is
G90 G84.3 X1 Y0 Z-1 P500 R2 F20
specified in threads/inch with the G84 command – thus, the
spindle moves down 1/20 inch for every revolution of the
spindle – stop and dwell for 500 msec
Y=2
Y=0
X=0 X=3
Cutter Compensation
D = 0.5
Y = 2.25
Y=2
Y=0
Y = -0.25
X=0 X=3
Cutter Compensation
D = 0.496
Y = 2.25
Y=2.002
Y=-0.002
Y = -0.25
X=0 X=3
Cutter Compensation
D = 0.25
Y = 2.125
Y=2
Y=0
Y = -0.125
X=0 X=3
Cutter Compensation
Y=2
G00 X4 Y0
G41 D3
G01 X0
Y=0
Y = -0.251
X=0 X=3
D3=0.251
Cutter Compensation
Programming a proper tool entry is
G41 – tool radius compensation left important!!!
G42 – tool radius compensation right
Y=2
G00 X4 Y0
G41 D3
G01 X0
D3=0.251
Y=0
Y = -0.251
X=0 X=3
Y=2
G00 X4 Y-1
G41 D3
G01 X3.25 Y0
G01 X0
Y=0
Y = -0.251
X=0
X=3 D3=0.251
Preferred practice
Program Planning Cont’d
Revolutions per minute = 12 * ft/min / ( pi * Dia [in]).
Imperical
Revolutions per minute = 1000 * m/min / (pi * Dia[mm])
Metric
Machining sequence
Defines the order of machining operaitons
Technical skills and machine shop experience help in program
planning, but much a common sense approach is equally important
Machining sequences must have logical order
Ex: Drilling must be programmed before tapping
Ex: Roughing operations before finishing
There are no fixed rules, but should be based on safety, quality, and
efficiency