You are on page 1of 20

ME 1355 – CAD/CAM LABORATORY

CNC MILLING PROGRAM

Ex.No.1

Study of G Codes and M Codes to Write Manual Part Programming for Fanuc Control
Systems

PREPARATORY FUNCTION ( G CODES )

The preparatory functions are the commands, which prepare the machine for different modes of
movement like contouring, thread cutting, positioning, peck drilling etc. These functions are also called as
G codes. G codes are used as machining commands.

MISCELLANEOUS FUNCTION ( M CODES )

The miscellaneous functions are the commands describing miscellaneous functions like
subprogram call or exit., spindle clockwise or counter clockwise, coolant ON/ OFF, program end etc.
these functions are also called as M codes. M codes are used as machine control commands.

SUBROUTINES

Subroutines or subprograms are mini programs similar to macros but are used in manual part
programming. It can be defined as a set of instructions that can be activated and used for repetitive
applications in the main program. In Fanuc control systems, subprograms are written as separate
programs with specific subprogram names. When a subprogram name is called in the main program, the
set of instructions in the subprogram is executed. After execution of the program flow returns to the main
program at a point immediately after the original call point.

CANNED CYCLE

Canned cycles are built-in- functions that are available to perform specific tasks like thread
cutting, grooving, pattern repeating, pocketing etc. A canned cycle simplifies the program using one or
two blocks with specific G codes to specify the machining operations, instead of using several blocks.

Examples are
G71 - Multiple turning cycle
G73 - Pattern turning cycle
G75 - Grooving cycle
G76 - Multiple thread cutting cycle
G170, G171 - Rectangular pocketing
G172, G173 - Circular pocketing
The list of G codes and M codes that can be used in milling machines are given below.

M CODES FUNCTION
M00 PROGRAM STOP

M01 OPTIONAL STOP

M02 PROGRAM STOP

M03 SPINDLE CLOCKWISE ROTATION

M04 SPINDLE ANTI-CLOCKWISE ROTATION

M05 SPINDLE STOP

M06 TOOL CHANGE

M08 COOLANT ON

M09 COOLANT OFF

M10 VICE ON

M11 VICE OFF

M13 COOLANT, SPINDLE CW

M14 COOLANT, SPINDLE CCW

M30 PROGRAM STOP AND REWIND

M70 X MIRROR ON

M71 Y MIRROR ON

M80 X MIRROR OFF

M81 Y MIRROR OFF

M98 SUBPROGRAM CALL

M99 SUBPROGRAM OFF/EXIT


G CODE FUNCTION
G00 RAPID POSITIONING

G01 LINEAR INTERPOLATION

G02 CIRCULAR INTERPOLATION CW

G03 CIRCULAR INTERPOLATION CCW

G04 DWELL

G20 INPUT IN INCH

G21 INPUT IN MM

G28 RETURN TO REFERENCE POINT

G40 CUTTER COMPENSATION CANCEL

G41 CUTTER COMPENSATION LEFT

G42 CUTTER COMPENSATION RIGHT

G43 TOOL LENGTH COMPENSATION ( + )

G44 TOOL LENGTH COMPENSATION ( - )

G49 TOOL LENGTH COMPENSATION CANCEL

G73 PECK DRILLING CYCLE

G74 COUNTER TAPPING CYCLE

G76 FINE BORING CYCLE

G80 CANNED CYCLE CANCEL

G81 DRILLING CYCLE, SPOT BORING

G82 DRILLING CYCLE, COUNTER BORING

G83 PECK DRILLING CYCLE

G84 TAPPING CYCLE

G85 BORING CYCLE

G90 ABSOLUTE COMMAND

G91 INCREMENTAL COMMAND

G92 PROGRAMMING OF ABSOLUTE ZERO POINT

G94 FEED PER MINUTE

G95 FEED PER REVOLUTION


A list of G codes and M codes that can be used in lathes are given below.

M CODES FUNCTION
M00 PROGRAM STOP

M01 OPTIONAL STOP

M02 PROGRAM END

M03 SPINDLE CLOCKWISE

M04 SPINDLE COUNTER CLOCKWISE

M05 SPINDLE STOP

M06 TOOL CHANGE

M08 COOLANT ON

M09 COOLANT OFF

M10 VICE OPEN

M11 VICE CLOSE

M30 PROGRAM END AND REWIND

M98 SUBPROGRAM CALL

M99 SUBPROGRAM EXIT


 

   
G CODES FUNCTION

G00 RAPID POSITIONING

G01 LINEAR INTERPOLATION

G02 CIRCULR INTERPOLATION CW

G03 CIRCULAR INTERPOLATION CCW

G04 DWELL

G20 INPUT IN inch

G21 INPUT IN mm

G28 REFERENCE POINT RETURN

G32 THREAD CUTTING

G40 TOOL NOSE RADIUS COMPENSATION CANCEL

G41 TOOL NOSE RADIUS COMPENSATION LEFT

G42 TOOL NOSE RADIUS COMPENSATION RIGHT

G50 SPINDLE SPEED CLAMPING

G70 FINISHING CYCLE

G71 MULTIPLE TURNING CYCLE

G72 MULTIPLE REPEATING CYCLE

G73 PATTERN REPEATING CYCLE

G74 PECK DRILLING CYCLE

G75 GROOVING CYCLE

G76 THREAD CUTTING CYCLE

G90 BOX TURNING CYCLE

G94 BOX FACING CYCLE

G98 FEED PER MINUTE

G99 FEED PER REVOLUTION


LINEAR INTERPOLATION AND CIRCULAR INTERPOLATION

Ex.No.2

Write a manual part program for the given diagram using Linear interpolation and circular
interpolation

O2000
[BILLET X100 Y100 Z10;
[TOOLDEF T1 D5;
[EDGEMOVE X0 Y0;
N10 G21 G40 G94;
N20 G50 S2000;
N30 G91 G28 Z0;
N40 G28 X0 Y0;
N50 M06 T0101;
N60 M03 S1000;
N70 G90;
N80 G00 X20 Y20 Z1;
N90 G01 X20 Y20 Z-1 F35;
N100 G01 X60 Y20 Z-1 F35;
N110 G03 X80 Y40 Z-1 R20 F35;
N120 G01 X80 Y60 Z-1 F35;
N130 G02 X60 Y80 Z-1 R20 F35;
N140 G01 X40 Y80 Z-1 F35;
N150 G03 X20 Y60 Z-1 R20 F35;
N160 G01 X20 Y20 Z-1 F35;
N170 G00 Z1;
N180 G91 G28 Z0;
N190 G28 X0 Y0;
N200 M05;
N210 M30;
The same program can also be written as given below.

EXAMPLE PROGRAM – 2 FOR MILLING OPERATION

O2001
[BILLET X100 Y100 Z10;
[TOOLDEF T1 D5;
[EDGEMOVE X0 Y0;
N10 G21 G40 G94;
N20 G50 S2000;
N30 G91 G28 Z0;
N40 G28 X0 Y0;
N50 M06 T0101;
N60 M03 S1000;
N70 G90;
N80 G00 X20 Y20 Z1;
N90 G01 Z-1 F35;
N100 X60 ;
N110 G03 X80 Y40 R20;
N120 G01 Y60;
N130 G02 X60 Y80 R20;
N140 G01 X40;
N150 G03 X20 Y60 R20;
N160 G01 Y20;
N170 G91 G28 Z2;
N180 G28 X0 Y0;
N190 M05;
N200 M30;
CIRCULAR POCKETING AND RECTANGULAR POCKETING

Ex.No.3

Write a CNC program for milling machine for the profile given using circular pocketing and
rectangular pocketing.

The syntax for circular pocketing is given below.


G170 R0 P0 Q3 X10 Y10 Z - 5 I0 J0 K24
G171 P75 S1000 R50 F45 B1500 J15
R - Position of tool to start cycle
P - Roughing (0) / finishing (1)
Q - Peck increment for each cut
X,Y & Z - Coordinates of bottom center of the circular pocket.
I&J - Finishing allowance for side and pocket base
K - Radius of circular pocket
P - Cutter movement percentage for next step
S - Roughing spindle speed
R - Roughing feed in Z direction
F - Roughing feed in XY directions
B - Finishing spindle speed
J - Finishing feed
The syntax for rectangular pocketing is given below:
G172 I30 J50 K0 P0 Q.5 R0 X10 Y10 Z-5
G173 I0 K0 P75 T1 S1000 R35 F45 B1500 J15 Z5
Where
I,J - Length of pocket in X, Y directions
K - Corner radius
P - Roughing (0) / Finishing (1)
Q - Depth of cut for each pass
R - Absolute depth from the surface
X&Y - Pocket corner coordinates
Z - Base of pocket
I,K - Pocket side and base finish allowance
P - Cutter width percentage
T - Tool number
S - Roughing spindle speed
R - Roughing feed in Z direction
F - Roughing feed in XY directions
B - Finishing spindle speed
J - Finishing feed
O2002;
[BILLET X100 Y100 Z10;
[TOOLDEF T1 D5;
[EDGEMOVE X0 Y0;
N10 G21 G40 G94;
N20 G91 G28 Z0;
N30 G28 X0 Y0;
N40 M06 T0101;
N50 M03 S2000;
N60 G90 G00 X30 Y10 Z5;
N70 G01 Z-1 F35;
N80 X30 Y30;
N90 X10 Y30;
N100 X10 Y40;
N110 G03 X10 Y60 R10;
N120 G01 X10 Y70;
N130 X30 Y70;
N140 X30 Y90;
N150 X40 Y90;
N160 G03 X60 Y90 R10;
N170 G01 X70 Y90;
N180 X70 Y70;
N190 X90 Y70;
N200 X90 Y60;
N210 G03 X90 Y40 R10;
N220 G01 X90 Y30;
N230 X70 Y30;
N240 X70 Y10;
N250 X60 Y10;
N260 G03 X40 Y10 R10;
N270 G02 X30 Y10;
N280 G00 Z5;
N290 G172 I30 J30 K0 P0 Q0.5 R0 X35 Y35 Z-1.5;
N300 G173 I0 K0 P75 T1 S2000 R75 F275 B2500 J200 Z6;
N310 G170 P0 Q0.5 R1 X50 Y50 Z-3 I0 J0 K10;
N320 G171 P75 S2000 R50 F150 B1500 J150;
N330 G91 G28 X0 Y0 Z0;
N340 M05;
N350 M30;
CNC PROGRAM USING SUBPROGRAM
Ex.No.4

Write a CNC program for milling machine for the profile given using sub program.

Profile depth = 5 mm

SUBPROGRAM
O9000;
N10 G91 G01 Z-1 F35;
N20 G90;
N30 G01 X40 Y20;
N40 G02 X60 Y20 R10;
N50 G01 X80 Y20;
N60 X80 Y50;
N70 G03 X20 Y50 R30;
N80 G01 X20 Y20;
N90 M99;
** save the subprogram as 4 digit number 9000.
Main Program
O2003
[BILLET X100 Y100 Z20;
[EDGEMOVE X0 Y0;
[TOOLDEF T1 D5;
N10 G21 G94 G40;
N20 G91 G28 Z0;
N30 G28 X0 Y0;
N40 M06 T0101;
N50 M03 S1000;
N60 G90 G00 X20 Y20 Z1;
N70 G01 Z0 F35;
N80 M98 P0059000;
N90 G01 Z1;
N100 G91 G28 Z0;
N110 G28 X0 Y0;
N120 M05;
N130 M30;
The statement M98 P0059000 can be explained as follows:
M 98 – For subprogram call.
P0059000 – 005 is the number of times the subprogram 9000 has to be called. (i.e. the subprogram 9000
has to be executed for 5 times.)
MIRRORING USING SUBPROGRAM

Ex.No.5

Write a CNC program for milling machine for the profile given using sub program and mirror
command.

Subprogram
O8000;
N10 G90 G00 X10 Y10 Z1;
N20 G01 Z-1 F35;
N30 G01 X30 Y10;
N40 G03 X10 Y30;
N50 G01 X10 Y10;
N60 G00 Z1;
N70 G00 X0 Y0;
N80 M99;

** save the file as 4 digit number 8000.


Main Program
O2004
[BILLET X100 Y100 Z10;
[EDGEMOVE X-50 Y-50;
[TOOLDEF T1 D5;
N10 G21 G94 G40;
N20 G91 G28 Z0;
N30 G28 X0 Y0;
N40 M06 T0101;
N50 M03 S1000;
N60 G90 G00 X0 Y0 Z5;
N70 M98 P0018000; ⎯⎯⎯⎯⎯⎯⎯⎯⎯ PROFILE 1
N80 M70; ⎯⎯⎯⎯⎯⎯⎯⎯⎯ X – Mirror On
N90 M98 P0018000; ⎯⎯⎯⎯⎯⎯⎯⎯⎯ PROFILE 4
N100 M71; ⎯⎯⎯⎯⎯⎯⎯⎯⎯ Y – Mirror On
N110 M98 P0018000; ⎯⎯⎯⎯⎯⎯⎯⎯⎯ PROFILE 3
N120 M80; ⎯⎯⎯⎯⎯⎯⎯⎯⎯ X – Mirror Off
N130 M98 P0018000; ⎯⎯⎯⎯⎯⎯⎯⎯⎯ PROFILE 2
N140 M81; ⎯⎯⎯⎯⎯⎯⎯⎯⎯ Y – Mirror Off
N150 G91 G28 Z0;
N160 G28 X0 Y0;
N170 M05;
N180 M30;
CNC PROGRAM USING DRILLING CYCLE

Ex.No.6

Write a CNC program for milling machine as shown in diagram using drilling cycle.

O2005;
[BILLET X100 Y100 Z20;
[TOOLDEF T1 D10;
[EDGEMOVE X-50 Y-50;
N10 G21 G94 G41;
N20 G91 G28 Z0;
N30 G28 X0 Y0;
N40 M06 T0101;
N50 M03 S1000;
N60 G90 G00 X0 Y0 Z5;
N70 G83 X0 Y25 Z-10 Q0.5 R1 F35; ⎯⎯⎯⎯⎯⎯⎯ DRILL 1
N80 X21.65 Y12.5; ⎯⎯⎯⎯⎯⎯⎯ DRILL 2
N90 X21.65 Y-12.5 ; ⎯⎯⎯⎯⎯⎯⎯ DRILL 3
N100 X0 Y-25; ⎯⎯⎯⎯⎯⎯⎯ DRILL 4
N110 X-21.65 Y - 12.5; ⎯⎯⎯⎯⎯⎯⎯ DRILL 5
N120 X-21.65 Y 12.5; ⎯⎯⎯⎯⎯⎯⎯ DRILL 6
N130 G80;
N140 G91 G28 Z0;
N150 G28 X0 Y0;
N160 M05;
N170 M30;
CNC PROGRAM USING FAST DRILLING CYCLE

Ex.No.7

Write a CNC program for milling machine as shown in diagram using fast peck drilling cycle.

O2006

[BILLET X100 Y100 Z20;


[TOOLDEF T1 D10;
[EDGEMOVE XO YO;
N10 G21 G94 G41;
N20 G91 G28 Z0;
N30 G28 X0 Y0;
N40 M06 T0101;
N50 M03 S1000;
N60 G90 G00 X15 Y80 Z5;
N70 G01 Z0;
N80 G91 G73 X10 Y0 Z-5 Q0.5 R0.0 K5 F35;
N90 G90;
N100 G00 X25 Y80 Z0;
N110 G91 G73 X15 Y-15 Z-5 Q0.5 R0.0 K4 F35;
N120 G91 G28 Z0;
N130 G28 X0 Y0;
N140 M05;
N150 M30;
Explanation
Statement N20:-
G73- Peck drilling
X10, Y10 denotes the incremental distance from its present position ( Present position is defined in N10)
Z-5 denotes the depth of the drill
Q0.5 denotes the depth of cut for each peck
K5 denotes that drilling has to be done five times at the given increment X & Y distances
R - denotes the position of tool to start in Z direction
The block N20 drills five holes. Initially the tool is positioned at X15 and Y80 in block N10.
From this position the tool takes a move of 10mm in X direction, which is point 1 and starts drilling. Then
it moves to point 2 and starts drilling. So on, five drills at points 1,2,3,4 & 5 are drilled. After that, the
tool is positioned at point 1. Then as per instructions in the block N30, the tool moves 15mm in X
direction and 15mm in Y direction, which is point 6 and starts drilling. It moves to points 7,8 & 9 and
performs drilling operation at each point as explained above.

You might also like