100% found this document useful (1 vote)
184 views

Notes CNC Program

G-codes are preparatory codes used in CNC programming to control machine motions and actions, with common modal G-codes specifying motion type like linear, circular, and dwell time. Modal G-codes remain active until changed by another G-code, while non-modal codes perform a single action. Common G-codes used in 3-axis milling include G00 for rapid positioning, G01 for linear cutting moves, and G02/G03 for clockwise and counterclockwise circular cuts.

Uploaded by

zairul
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
184 views

Notes CNC Program

G-codes are preparatory codes used in CNC programming to control machine motions and actions, with common modal G-codes specifying motion type like linear, circular, and dwell time. Modal G-codes remain active until changed by another G-code, while non-modal codes perform a single action. Common G-codes used in 3-axis milling include G00 for rapid positioning, G01 for linear cutting moves, and G02/G03 for clockwise and counterclockwise circular cuts.

Uploaded by

zairul
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Prepared by: Jurie@2020

WHAT IS COMPUTER AIDED MANUFACTURING (CAM)?


Computer-aided manufacturing (CAM) commonly refers to the use of numerical control (NC)
computer software applications to create detailed instructions (G-code) that drive computer
numerical control (CNC) machine tools for manufacturing parts in metal, wood, plastic or other
materials.

A broader definition of CAM can include the use of computer applications to define a
manufacturing plan for tooling design, computer-aided design (CAD) model preparation, NC
programming, coordinate measuring machine (CMM) inspection programming, machine tool
simulation, or post-processing.

Prepared by: Jurie@2020


WHAT IS COMPUTER NUMERICAL CONTROL (CNC)?

CNC (Computer Numerical Control) is the general term


used for a system which controls the functions of a machine
tool using coded instructions processed by a computer.

A part program is written, using G and M codes.


This describes the sequence of operations that the machine
must perform in order to manufacture the component.

This program can be produced off-line, ie, away from the


machine, either manually or with the aid of a CAD/ CAM
system.

The part program is loaded into the machines computer,


called the controller. At this stage, the program can still be
edited or simulated using the machine controller
keypad/input device.

The machine controller processes the part program and


sends signals to the machine components directing the
machine through the required sequence of operations
necessary to manufacture the component.

Prepared by: Jurie@2020


TYPE OF CNC MACHINES
Any automated system that uses computer to control machine by the means of command is a CNC machine;
from 3-Motor robots to 7-Axis Milling machine.

Generally these technologies are classified based on:


• Axis(2/3/4/5/6/7 - Axis machines)
• Orientation (vertical milling machine, turning machine)
• Mechanism (additive/subtractive); Example: additive (3D printing), subtractive (milling, turning)

Prepared by: Jurie@2020


TYPES OF CNC MACHINES (CONT’)
Generally, there are six types of CNC machines, all used for different purposes and materials:

• Milling Machines: Widely popular. In fact, they might even be the most popular type of CNC machine
used today. Milling machines utilize rotary cutters to shape workpieces to perfection. They can be
programmed to provide the required depth, angle and cutting direction.

• CNC Lathes: A lathe is utilized to develop highly precise conical and spherical shaped parts. This
particular machine uses turning centers wherein the cutting tool shaves off the excess material while the
material is rotating on a spindle.

• Drilling machines: CNC drills are highly advanced drilling machines where the speed of the drill and
the depth to be drilled is handled by highly sophisticated computer programs.

• Screw Machines: Screw machines are the advanced version of automated lathes. They are used to
produce smaller yet complex machined parts for automotive, aerospace, medical and electrical
hardware industries.

• CNC Grinders: This type of machine utilizes a rotary wheel that abrades the material into the desired
shape by repeatedly grinding it.

• CNC Plasma Cutters: Plasma cutters uses plasma beam to cut the materials into 2D shapes.

Prepared by: Jurie@2020


MATERIALS USED BY CNC MACHINES

Prepared by: Jurie@2020


TYPES OF CNC CONTROLLERS (CONTROL SYSTEMS)

There are various type of CNC controllers (control systems) in the market nowadays. Some of them
are as follows:
• Siemens
• Fanuc
• Heidenhein
• Mitsubishi
The above four are generic control system that are used by most CNC machine manufacturers.
However there are some CNC machine manufacturers that have their own control systems:-
• Haas
• Mazak
• Hurco
• Cincinati
• And many more…….

Prepared by: Jurie@2020


WHAT IS POST-PROCESSING IN CNC
A CNC post processor is a software that converts toolpaths created in a CAM system into NC programs
that can be read by a machine's controller to move the cutting tool along the programmed paths in a safe,
consistent and predictable manner in order to produce related parts. This is where the post
processor enters the equation.

CL: Cutter Location


APT: Common format for CL
data files

Prepared by: Jurie@2020


IN THIS COURSE WE WILL
ONLY FOCUS ON THE
BASIC VERTICAL 3-AXIS
CNC MILLING

Prepared by: Jurie@2020


VERTICAL 3-AXIS CNC MILLING MACHINE

Prepared by: Jurie@2020


AXES IN 3-AXIS CNC MILLING MACHINE
Machine controller
(the “heart” of the CNC machine)

Spindle

Cutter

3 axis CNC machine that involved with


X, Y, Z axes.

Prepared by: Jurie@2020


PROGRAM EXAMPLE

Prepared by: Jurie@2020


CODES IN CNC PROGRAM

Known as a “BLOCK”

Letter Number

EXAMPLE OF CNC PROGRAM


As we know that the CNC machine is operated by
using CNC program (coding system).

Each instruction to the CNC machine consists


of a letter followed by a number.

Each letter is associated with a specific type


of instruction/action or information that needed by
the CNC machine to proceed with its operation.

Letters that used codes in CNC program are listed


in the table on the next slide.

Prepared by: Jurie@2020


CODES (LETTERS) IN CNC PROGRAM

Prepared by: Jurie@2020


BASIC CNC MILLING CODES

EXAMPLE OF CNC PROGRAM As mentioned previously, the CNC programming comes with letter
codes.

G code:
It is known as geometry code – involve with actual tool movements
in X, Y & Z directions.

M code:
It is known as miscellaneous code – involve with necessary
actions for machining such as spindle on/off, coolant on/off, tool
change, end of program.

T code:
It is known as tool number code/tooling code – involve when it is
necessary to change the new cutting tools for certain related
machining cutting process in the same CNC program.

Prepared by: Jurie@2020


BASIC CNC MILLING CODES (CONT’)

EXAMPLE OF CNC PROGRAM


N code:
It is a line number for each block of information.
(Generally it is a good practice to increment each block number
by 5 or 10 to allow additional blocks to be inserted if future
changes are required.

X, Y, and Z codes:
These codes are used to specify the coordinate axis.
Numbers that following the code, defines the coordinate at the
End of the cutting tool movement relative to an absolute or
Incremental reference point.

Prepared by: Jurie@2020


BASIC CNC MILLING CODES (CONT’)
I, J, and K codes:
These codes are used to specify the coordinate axis when
EXAMPLE OF CNC PROGRAM defining the center of a circle/arc.
Number that following the code defines the respective
coordinate for the center of the circle/arc.

F code:
It is used to specify the feed rate.

S code:
It is used to specify the spindle speed.

R code:
This code is refer to retract distance between the cutting tool
And the work piece when used with codes such as G81, G82,
And G83.

P code:
It is used to specify the dwell time associated with G04.
Prepared by: Jurie@2020
G CODES IN CNC
G-code is defined using the G address letter and a two digit number in NC Programming; Example: G00

G-Code is mostly used common name in NC Programming language since they prepare the machine for a
certain type of motion. G-codes instruct the machine where to move, how fast to move and which path to move.
G-codes are called as preparatory/geometry codes which prepare machine to move.

There are two types of G-codes,

1) Modal G-code.

2) Non-Modal G-code.

Modal G-code:
The G-codes for motions are called Modal G-code. The modal G-code once called it stays till it is cancelled with
another G-code. If G1 (Linear Move) command is called it will be executed again on the next line unless some
other command called which cancels G1.
Additionally, modal G codes are further split into groups according to their task and function. A modal G code will
remain active until another G code from the same group is programmed into a block, or it is cancelled. Example
units of programming inches (G21) and millimeters (G20) are modal. Model groups are as shown on the next
slide.

Prepared by: Jurie@2020


G CODES IN CNC (CONT’)

Non-Modal G-codes:
The Non-Modal G-codes effect only the lines on which they occur. Example: G04 (Dwell) is Non-Modal. The
machine suspends machine motions code, dwells for the programmed time, and then returns to normal
movements.
Prepared by: Jurie@2020
M-CODES IN CNC
M-codes are Non-Axis movement command which known as machine codes which control the miscellaneous
functions of machine excluding the axis movement of the machines.
M-Code is the Letter “M” Followed by the Numbers which control the machine functions. Example: M03 a controls the
spindle to rotate along clockwise direction.
M-code can be used to initiate a miscellaneous function not related to tool movement.
M-code Usually acts like a switches that stay ON until they are turned OFF by another M code
M-code is always allowed one per block of code.
Some M-codes are used in conjunction with other address, M06 tool change is always called with the conjunction
with a T word which is for tooling code.
The machine tool manufacturer often provides many additional M-Codes, many of these codes are non- standard,
and therefore we should consult the user manual of machine before making assumptions while using M-codes in
the CNC program.

M Code Modal Groups

Group 2 = [M26, M27} - axis clamping


Group 4 = [M0, M1, M2, M30, M60] - stopping
Group 6 = [M6] - tool change
Group 7 = [M3, M4, M5] - spindle turning
Group 8 = [M7, M8, M9] - coolant
Group 9 = [M48, M49] - feed and speed override bypass

Prepared by: Jurie@2020


G-CODES & M-CODES IN CNC PROGRAM
List of M-codes
M-code Function

Prepared by: Jurie@2020


BASIC CNC MILLING G-CODE
TYPES OF COORDINATE SYSTEM IN CNC MILLING PROCESS
BEFORE WE CAN PROCEED WITH THE G-CODE SYSTEM, FIRSTLY YOU SHOULD
REALLY UNDERSTAND THE CONCEPT OF COORDINATES THAT HAS BEEN USED
IN THE CNC PROGRAMMING.

• In the CNC program, there are two types of G-Code for coordinate system as
stated below:
- G90 (Absolute programming)
- G91 (Incremental programming)

• NOTE:
You no need to memorize all the G-codes.
You can refer to the G-code table for CNC milling as reference.

Prepared by: Jurie@2020


WHAT IS ABSOLUTE COORDINATE?
ALL POINT LOCATIONS/COORDINATES ARE REFERRING TO THE ORIGIN POINT (0,0,0) AS
REFERENCE.

POINT X COORDINATE Y COORDINATE

P0 0 0

P1 12 12

P2 26 16

P3 38 32

Prepared by: Jurie@2020


WHAT IS INCREMENTAL COORDINATE?

THE PRESENT POINT/COORDINATE IS A REFERENCE POINT FOR THE NEXT MOVEMENT OF


POINT/COORDINATE.

POINT X COORDINATE Y COORDINATE

P0 0 0

P1 12 12

P2 14 4

P3 12 16

Prepared by: Jurie@2020


CNC MILLING EXAMPLE: START WITH ABSOLUTE PROGRAMMING (G90)
OR
START WITH INCREMENTAL PROGRAMMING (G91)

Linear interpolation
Point 5
Point 1
Point 2
Point 3
Point 4
Point 4 Point 3 Point 5
Point 1

Program stop

Point 1 Point 2

Unit: in metric

Prepared by: Jurie@2020


CUTTER COMPENSATION

Prepared by: Jurie@2020


CUTTER COMPENSATION: G40, G41, G42
Cutter compensation or sometimes referred to as "cutter comp", is an
offset or shift from center point of the cutter/cutting tools to the
cutters edge along a programmed path.

The advantage of cutter compensation is the use of geometry based


offsets rather than tool center point, allowing for the same program to
use different diameter tools.

There are three G-codes that related to the cutter compensation


which as follows:
• G41: Cutter compensation left Depending on the cutting direction
• G42: Cutter compensation right
• G40: Cancel/turn off the cutter compensation G41 and G42

When programming a CNC machine, we have to take into


consideration the diameter of the cutter or the part will be undersize
by the radius of that tool.

Using G41 and G42 cutter compensation, will enable the machine to
calculate this, so we can program to the dimensions of the drawing.
This explanation can be showed further as in the figure on the next
slide.

Prepared by: Jurie@2020


CUTTER COMPENSATION: G40, G41, G42 (CONT’)

CUTTER

WORK PIECE CUTTER COMPENSATION; 5mm


FROM THE CENTER OF THE CUTTER

WORK PIECE

CUTTER

Prepared by: Jurie@2020


EXAMPLE: CUTTER COMPENSATION

CNC PART PROGRAM

CODES EXPLANATION
G00 : Rapid transverse
G01 : Linear interpolation
G41 : Tool nose radius compensation left
G43 : Tool length compensation “+” direction
G54 : Workpiece coordinate system 1 selection
G90 : Absolute command
G91 : Incremental command
M06 : Tool change
H : Tool length offset

Prepared by: Jurie@2020


CIRCULAR INTERPOLATION

Prepared by: Jurie@2020


CIRCULAR INTERPOLATION IN CNC PROGRAMMING

Use when the dimensions/measurements are involved with radius for an arc, partial arc or
complete circle. One of the example is to create fillet.

The I, J, & K representing the radius on each axis direction. The usage of I, J, & K is to avoid
from any confusion with X, Y, & Z.

I : representing radius on the X axis direction.


J : representing radius on the Y axis direction.
K : representing radius on the Z axis direction.

All of these I, J, & K can be replaced with “R” to indicate the radius. The value of the radius
can be “-” or “+” depends on the direction.

Prepared by: Jurie@2020


CIRCULAR INTERPOLATION
Circular interpolation can be divided into two:
1) Clock wise (CW) circular interpolation.
2) Counter clock wise (CCW) circular interpolation.

The G-code for CW circular interpolation is G02, while for CCW circular interpolation is G03.

CW (G02) CCW (G03)

Work piece Cutter

Prepared by: Jurie@2020


CIRCULAR INTERPOLATION (CONT’)

The circular interpolation commands (G02 & G03)


need end point & radius to cut the arc.

For example, let say the starting point of an


arc is (X1,Y4) while the end point is (X4,Y1).

To find the radius, just measure the distance


from starting point to the center point (the
distance is indicated as “J” – remember that “J”
representing Y direction for the radius of arc/circle).

Since the movement from the starting point to


center point is downwards, therefore the “J”
which is representing Y direction will shows
with “-” sign.

Prepared by: Jurie@2020


CIRCULAR INTERPOLATION (CONT’)

CLOCK WISE (G02) COUNTER CLOCK WISE (G03)

Prepared by: Jurie@2020


CIRCULAR INTERPOLATION (CONT’)
CLOCK WISE (G02) COUNTER CLOCK WISE (G03)

Prepared by: Jurie@2020


CNC MILLING EXAMPLE #1: CIRCULAR INTERPOLATION CLOCKWISE(G02)
AND CIRCULAR INTERPOLATION COUNTER-CLOCK WISE (G03)

• I : representing radius on X direction


• J : representing radius on Y direction

Point S
Point A
Point B
Point C
Point D
Point E
Point F
Point G
Point H
Point I
Point A
Point S

Unit: in inches

Prepared by: Jurie@2020


CNC MILLING EXAMPLE #2: CIRCULAR INTERPOLATION CLOCKWISE(G02)
AND CIRCULAR INTERPOLATION COUNTER-CLOCK WISE (G03)

In this case, I & J can be replaced with R which means radius


Point 12
Point 11
Point 10
Point 1
Point 9 Point 2
Point 3
Point 8 Point 4
Point 7 Point 5
Point 6
Point 7
Point 8
Point 9
Point 10
Point 11
Point 12
Point 1

Point 6
Point 1 Point 2 Point 3 Point 4 Point 5

Unit: in metric
Prepared by: Jurie@2020
EXAMPLE: ABSOLUTE COMMAND, CIRCULAR INTERPOLATION,
CUTTER COMPENSATION

PART PROGRAM
SELF ASSESSMENT #1 • Write a part program based
from the given profile.
• Use absolute command
• Workpiece thickness: 20mm
• Units: Metric millimeter
• SP is a Starting Point

SP (0,0)

Prepared by: Jurie@2020


SELF ASSESSMENT #2
Create a G-code programming for the below figure. Use absolute command. “SP” is the starting point.
Try to use both methods, the I, J, & K, as well as the “R” coordinate systems for the radius. All units are in metric
millimeter.

Prepared by: Jurie@2020


SELF ASSESSMENT #3
Create a G-code programming for the below figure. Use incremental command. Try to use both
methods, the I, J, & K, as well as the “R” coordinate systems for the radius. Follow the direction
from “Starting point” and to “P1, P2, P3………”. All units are in metric millimeter.

Prepared by: Jurie@2020


SELF ASSESSMENT #4

• Write a part program based


from the given profile.
• Use cutter compensation G42.
• Cutter diameter: 16mm
• Use absolute command
• Workpiece thickness: 20mm
• Units: Metric millimeter
• SP is a Starting Point

SP (0, 0)
MAIN PROGRAM
&
SUBPROGRAM
Prepared by: Jurie@2020
MAIN PROGRAM & SUBPROGRAM IN CNC

Main program:
It is a whole body of entire CNC program. All CNC
commands/programs in order to produce a certain
part will include under this main program.

Subprogram:
It is a normal CNC program which called from a
program (normally called Main program) to add
some kind of repeatable machining operation.

The subprogram can be within the same program


(main program) OR from the separate program
created and then loaded on the controller.

Prepared by: Jurie@2020


WHAT IS M97, M98 & M99 OF M-CODES?
WHAT IS M-CODE: M97 LOCAL SUBPROGRAM CALL (P, L)?
• It is the M-code that used to call a Subprogram with the reference of the line number N within the same program.

• Pxxxx code is a line number/subprogram number that to be repeated.

• xxxx is the line number in the same program.

• This is used for the simple program within the program and does not require complication of creating a
subprogram.

• A local subprogram must end with an M99 (end the subprogram).

• If there is a repetition of the loop of subprogram L count on the M97 line, the sub-program will be repeated L
number of times.

M97 Program Format:

M97 Pxxxx Lnn


Where: xxxx is the line number
nn is the number of repetitions of the subprogram involved

Prepared by: Jurie@2020


WHAT IS M97, M98 & M99 OF M-CODES? (CONT’)
Example:
Main program:
O01234 (Program number and Start of main program)
N0001 T02 M06;
N0002 T03
N0003 G54 G90 G00 Z50
N0004
N0005
... (Part program)
...
M97 P0015 L3 (Jumps to line N0015, after the M30, to execute a local
sub-program for 3 times)
... (The M99 at the end of the sub-program will cause it to jump
back here.)
...
...
... (Finish part program)
...
M30 (End of main program)
N0015 (Identifies the start of the Local Sub-Program called up by
M97 P0015)
...
... (Local sub-program portion of Main program)
...
M99 (Jumps back to the line after local sub-program call in the main
program)

Prepared by: Jurie@2020


WHAT IS M97, M98 & M99 OF M-CODES? (CONT’)

WHAT IS M-CODE: M98 SUBPROGRAM CALL (P, L)?

• M98 is M-code of a subprogram call. Normally, we write this M-code in the main program.

• M98 is the M-code used to call a Subprogram with the reference to the separate program
created and loaded on the controller.

• The Pxxxx code is the sub-program number being called; it must be in the same block as the
M98.

• A sub-program must end with an M99 to enter to main program after the subprogram.

• If there is a repetition of the loop of subprogram L count on the M98 line, the sub-program will be
repeated L number of times before continuing to the next block.

Prepared by: Jurie@2020


WHAT IS M97, M98 & M99 OF M-CODES? (CONT’)
M98 Program Format:

M98 Pxxxx Lnn


Whereas, xxxx is the line number
nn is the number of repetitions

Example:
Main program:
O01234 (Program number and Start of main program)
N0001 T02 M06;
N0002 T03
N0003 G54 G90 G00 Z50
...
...
... (Part program)
...
...
M98 P111 (Jumps to program O00111 to execute sub-program)
... (The M99 at the end of the sub-program will jump back here)
...
... (Finish part program)
...
M30 (End of main program)
Sub-program:
O00111 (Identifies the start of a separate sub-program)
...
... (Sub-program portion of part)
...
M99 (Jumps back to the line after the sub-program call in the main program).
Prepared by: Jurie@2020
WHAT IS M97, M98 & M99 OF M-CODES? (CONT’)

WHAT IS M-CODE: M99 END SUBPROGRAM OR RETURN/LOOP?


• M99 is M-code for end subprogram or return (loop) for main program.

• If in the main program: it will cause the program to loop back to the beginning and repeat over
and over again without stopping.

• If in the subprogram: it will end the subprogram and return to the main program (a line after the
related subprogram call).

Prepared by: Jurie@2020


WHAT IS M97, M98 & M99 OF M-CODES? (CONT’)
Example:
Main program:

O01234
...
... (Complete part program)
...
...
M99 (This will cause the program to jump back to the beginning and
repeat itself)
An M99 without a P code at the end of a sub-program will return to
the main Program.)

Example:
Main program: Sub-program:

O01234 O00111 (sub-program number)


... ...
... (Part program) ... (Sub-program portion of part)
... ...
M98 P111 (Jumps to program O00111 to run) M99 (Jumps back to the line after the sub-program call)

... (The M99 at the end of the sub-program will jump back here)
...
... (Finish part)
...
M30 (End of main program)
Prepared by: Jurie@2020
EXAMPLE: CNC MILL SUBPROGRAM

CNC PART PROGRAM

SUBPROGRAM

Prepared by: Jurie@2020


POCKET IN
CNC PROGRAMMING MILLING

Prepared by: Jurie@2020


EXAMPLE: POCKET MILLING

Subprogram number

For the circle


Pocket with 2mm
depth

Depth 6mm

Subprogram (for the rectangle pocket) with 2mm


depth
Subprogram number

Prepared by: Jurie@2020


DRILLING IN
CNC PROGRAMMING MILLING

Prepared by: Jurie@2020


HOLE DRILLING (G-CODE: G81) IN CNC MILLING PROCESS
Step that involved in the G-code drilling

Format arrangement & explanation

G81: Drilling cycle


G98: Return to initial point in canned cycle
G99: Return to R point in canned cycle

Point Z is a hole drilling depth

Material/Work piece

Prepared by: Jurie@2020


HOLE DRILLING (G-CODE: G81) IN CNC MILLING PROCESS

G-CODE PROGRAMMING

Prepared by: Jurie@2020


SELF ASSESSMENT
Write a complete PART PROGRAM for the blank
comes together with SUBPROGRAM (for the holes).
you may use absolute or incremental command
or combination of both (if necessary).

STARTING
POINT
WITH DEPTH 10mm

UNITS: METRIC MILLIMETER

Prepared by: Jurie@2020


REFERENCES
http://cnc-programming-tips.blogspot

https://www.slideshare.net/MaheshNamdev1/4-basic-cnc-programming-milling

https://www.academia.edu/40488047

http://www.helmancnc.com

https://www.quora.com/How-do-I-learn-CNC-programming

https://gcodetutor.com/gcode-tutorial

https://machmotion.com/blog

https://www.mechaterrain.com

https://www.slideshare.net/manujarora98/g-and-mprogrammingformillsmanual

https://mdaltd.ca/cnc-machines-face-modern-manufacturing/

http://cnc-programming-tips.blogspot.com
Prepared by: Jurie@2020

You might also like