NC PART PROGRAMMING
Coordinate System
Z AXIS
• workpiece-rotating machine:
Z is parallel to the spindle Z
• tool-rotating machine:
Z is parallel to the tool axis
Z
Z
Coordinate System
X AXIS
workpiece-rotating machine:
X
X is the direction of tool movement Z
horizontal milling machine :
X axis is parallel to the table
vertical machine :
+X axis points to the right
when the programmer X
Z Z
is facing the machine.
X
Y Y
Basic Programming of a CNC Milling Machine
Machine coordinate system
• The point that is specific
to machine and serves as
the reference of the
machine is referred to as
the machine zero point
• Machine tool builder
sets a machine zero
point for each machine
Work co- ordinate system
• A coordinate system used for
machining a workpiece is
referred to as a workpiece
coordinate system
• A workpiece co-ordinate
system is also called as work
reference zero or work datum.
• The work datum will be set
by the user before the
machining process begins
NC Words
• N, G, X, Y, Z, A, B, C, I, J, K, F, S, T, M
N: Specify the sequence number
G: Preparatory word to prepare for control functions (the motion
of each axis, coordinate system, coordinate plane, cutter radius
compensation, tool length offset……)
M: Miscellaneous word to control miscellaneous functions
(spindle on/off, start/stop the machine, turn on/off the coolant,
change the tool, and rewind the program tape)
F: Feed rate, S: Spindle speed,
T: Tool identification/ tool change
NC Words
G54-G59: Work coordinate system selection
NC Words
M CODES
M00 Program stop M06 Tool change
M01 Optional stop M07 Flood coolant on
M02 End of program M08 Mist coolant on
M03 Spindle CW M09 Coolant off
M04 Spindle CCW M30 End of tape
NC Words
• Modal codes and non modal codes
– modal functions/ modal G code
Modal functions stay active until some other command (other
G code of the same group) changes it. Modal commands are
arranged in sets called “modal groups”, and only one member
of a modal group may be in forces at any given time.
– non-modal functions/ one-shot G code
Non-modal functions have effect only on the lines on which
they occur.
NC Words
modal groups
NC Words
M CODES modal groups
M00 Program stop M06 Tool change
M01 Optional stop M07 Flood coolant on
M02 End of program M08 Mist coolant on
M03 Spindle CW M09 Coolant off
M04 Spindle CCW M30 End of tape
NC Words
N, G, X, Y , Z, A, B, C, I, J, K, R, F, S, T, M
F: feed rate of the tool motion
S: cutting-speed
T: tool number
NC Words
N, G, X, Y, Z, A, B, C, I, J, K, R, F, S, T, 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
• R: Radius of the arc
Sample NC Program Block
N00 G90 G01 X50 Y50 Z0 F10
FEED RATE (mm/min)
Z COORDINATE
Y COORDINATE
X COORDINATE
PREP CODE - LIN INTERPOL
PREP CODE - ABSOLUTE
BLOCK SEQUENCE #
G codes
• Unit selection:
– G70 (inch), G71(metric)
• Coordinates selection:
– G90(absolute), G91(incremental)
• Working plane selection:
– G17(X-Y), G18(Z-X), G19(Y-Z)
Rapid traverse: G00
• G00:
– to make the machine move at maximum speed.
– It is used for positioning motion.
G90 G00 X20.0 Y10.0
End
G90:
(20,10)
absolute
coordinates (10,10)
Start (0,0
)
Linear interpolation: G01
• G01:
– linear interpolation at feed speed.
G91 G01 X200.0 Y100.0 F200.0
Y
G91: End
incremental 100.0
coordinates
Start 200.0 X
Circular interpolation: G02, G03
• G02, G03:
– For circular interpolation, the tool destination and the circle
center are programmed in one block
– G02 is clockwise interpolation, G03 is counterclockwise
interpolation
G 02 R
G17 X __ Y __ F __;
G 03 I __ J __
G 02 R
G18 X __ Z __ F __;
G 03 I __ K __
G 02 R
G19 Y __ Z __ F __;
G 03 J __ K __
End point Circle center, radius
Return to Machine Zero: G28
G91: incremental
G28 coordinates
• The machine passes by the specified point, and then move
to the machine zero.
G91 G28 X_, Y_, Z_
• X,Y,Z are the coordinate of specified point that is saved in memory of
machine.
• Usually this instruction is used in the beginning and end of program.
Machine
Zero
Specified
A
point
M code: M00, M01
M00 and M01 both stop the machine in the middle of a program.
M01 is effective only when the optional stop button on the
control panel is depressed. The program can be resumed
through the control panel.
M code: M03, M04, M05
M03 turns on the spindle clockwise.
M04 turns the spindle on counterclockwise.
(The spindle rpm must be specified in the same line or in a
previous line. )
M05 turns off the spindle.
M code: M07, M08, M09
M07 and M08 turn on different modes of coolant.
– M07: flood coolant on
– M08: mist coolant on
M09 turns off the coolant.
M code: M06, M02
M06 signals the tool-change operation.
On a machine equipped with an automatic tool changer, it stops
the spindle, retracts the spindle to the tool-change position,
and then changes the tool to the one specified in the T-code.
M02 marks the end of the program.
Programming Example-1
Making 150 mm* 150 mm square Tool length compensation =
for a depth of 5mm in a given Billet H01
G21
N01 G71 G94 ; Metric input, Feed in mm/min.
N02 M06 T01 ; (Tool change)
N03 G91 G28 X0 Y0 Z0 ; The tool is moved to home position
N04 G90 G43 H01 Z20 ; Tool length compensation call
N05 M03 S1000 ; Positioning above the reference and spindle
starts rotating at 1000 rpm
N06 G00 X25.0 Y25.0 ; Rapid movement to point 1
N07 G01 Z-5.0 F40 ; The tool is moved inside work of 5.0 mm
N08 Y175.0 ; The tool is moved to second corner
N09 X175.0 ; The tool is moved to third corner
N10 Y25.0 ; The tool is moved to fourth corner
N11 X25.0 ; The tool is moved back to first corner
N12 G00 Z100.0 M05 ; The tool is taken out of the work and spindle
stop
N13 G91 G28 X0 Y0 Z0 ; The tool is moved back to home position
N14 M30 ; Program stop
Example-2
N00 G90 G71 G94 ; Ab. coordinates, Metric, Feed-mm/min
N01 M06 T1 ; Load Tool 1
N02 G00 Z 10 ; Rapid to 10mm above part
N03 M03 S3000 ; Turn spindle on to 3000 rpm
N04 G00 X20Y20 ; Rapid to point A
N05 G01 Z-2 F10 ; Plunge to -2mm at 10mm/min.
N06 X20Y60 ; Straight line interp. to B
N07 X35Y40 ; Straight line interp. to C
N08 X50Y60 ; Straight line interp. to D
N09 X50Y20 ; Straight line interp. to E
N10 G00 Z10 ; Retract Cutting Tool
N11 X70Y20 ; RAPID TO POINT H
N12 G01 Z-2 F10 ; Plunge to -2mm at 10mm/min.
N13 X70Y60 ; Straight line interp. to F
N14 G02 X60 Y20 I70 J40 ; CW Circle interp.
N15 G00 Z10 ; Retract Cutting Tool
N16 M05 ; Turn off Spindle
N11 G91 G28 X0 Y0 Z0 ; The tool is moved back to home position
Example-3
N00 G72 G94 inch input, Feed in inch/min.
N10 G41 D01 M03 S1000 Begin compensation ( left ) , set feed
and speed, spindle on ( CW )
N20 G00 X6.000 Y6.000Z1.000 Move to lower left corner
N30 G01 Z-1.000 F5 Plunge down the tool
N40 G01 Y8.000 Cut to upper left corner
N50 G01 X8.000 M96 Cut to upper right corner with external curve
N60 G01 Y6.000 M95 Cut to lower right corner with external curve
N70 G01 X6.000 M96 Cut to lower left corner with external curve
N80 G01 Z1.000 Lift the tool
N90 G40 M30 End the composition, stop the machine
20
30
(0,0,0)
10
N01 G90 G21 G94 ; absolute mode, input in mm, feed mm/min
N02G90 G00 Z5 ; rapid traverse to 5mm above plate
N03 M03 S1000 M08 ; spindle rotates in clockwise at 1000rpm, coolant on
N04 G00 X20 Y30 ; rapid traverse to (25,30)
N05 G01 Z-10 F90 ; actual drilling
N06 G00 Z5 ; rapid traverse to 5mm above plate
N07 G91 G28 ; Return to reference
N08 M05 ; spindle off
N09 M09 ; coolant off
N10 M30 ; program end
(0,0)
Z
R22 R21 R20
20 10 X
40
N01 G90 G21 G94 M03 S2000
N02 G91G28 X0 Y0 Z0
N02 G90 G00 X44 Z2
N03 G01 X42
N04 Z-20 F80
N05 G00 X44 Z2
N06 G01 X40
N07 Z-10 F80
N08 G00 X44 Z2
Note: Please enter the diameter as
X coordinate N09 M05
N10 G91 G28
N11 M30
CANNED CYCLE FUNCTIONS
- Set of operations assigned to one block and performed
automatically without any possibility of interruption.
- Process can be executed with one command instead of
programming a series of individual moves,
- For example drilling a hole involves
performing a group of well defined motions.
Canned cycle perform these repetitive motions
with a simple set of codes.
- Once the Canned cycle is activated it
will repeat the drilling cycle at every location
as specified in the program.
Usually Canned cycle involves a set of six operations
- Positioning of the X and Y axes at rapid traverse.
- A rapid traverse move to an initial clearance level plane (G98)
- The machining cycle is executed
- A dwell or other operation is executed at the bottom of the hole.
- A rapid traverse return to the R level plane along the Z axis
(G99)
- A rapid traverse return to the initial level plane along the Z axis.
Block format is
N….G…G….X…Y…Z…R…Q…P….F….K….
N= the block number
G=the type of cycle function
G= initial or R level return
X, Y= the hole position (positioning is carried out by rapid
traverse)
Z= depth of the hole
R= distance between plane R and the surface of the material.
Level R refers to the horizontal plane, positioned
closely above the material on which the tool tip moves. The
programmed value or R is valid until the new value is entered. It
doesn't have to be included in every block. The tool will return to
this level at the end of each hole drilled.
Q= the depth of cut for individual pecks (not used for every
drilling cycle)
P= the dwell time for the drill while rotating at the bottom of
the hole (not used for every drilling cycle)
dwell is in seconds for the purpose of complete
removal of excess material
F= feed rate
K= number of repeats
G81- canned cycle for spot drilling
G82- for counter boring
G83- deep hole peck drilling
G86- boring cycle
G80- cancelling canned cycle.
G81- SPOT DRILLING CYCLE
N1 G91 G28 X0 Y0 Z0
N2 T01 M06
N3 G21 G94
N4 G17 G90 G54 G00 X20 Y20
N5 G43 H01 Z100
N6 M03 S1000 Z20
N7 G99 G81 Z-4. R5 F300
N8 X80
N9 Y80
N10 X20
N11 X50 Y50
N12 G80 G00 Z100
N13 G91 G28 X0 Y0 Z0
N14 M05
N15 M30
N01 G54 G91G28 X0 Y0 Z0
N02 G90 G21 G94 M03 M08 S800;
N05 G01 X30 Z0 F2
N10 G00 Z1 Note: Please enter the diameter as
N15 G00 X20 X coordinate
N20 G01 Z-35 F10
N25 G01 X30 Z-65
N30 G00 X30 Z1
N35 M05 M09
N40 M02