Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
542 views

Basic Machine Codes PDF

G-codes are used in CNC programming to control machine tool functions like positioning, linear and circular interpolation, and dwell times. Some common G-codes described in the document are: G00 for rapid positioning moves. G01 for linear cutting moves at a specified feedrate. G02 and G03 for clockwise and counter-clockwise circular cuts respectively, defined by radius and end point or center point. G04 adds dwell time for drilling operations. G17, G18, G19 select the working plane for circular moves.

Uploaded by

sabiha12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
542 views

Basic Machine Codes PDF

G-codes are used in CNC programming to control machine tool functions like positioning, linear and circular interpolation, and dwell times. Some common G-codes described in the document are: G00 for rapid positioning moves. G01 for linear cutting moves at a specified feedrate. G02 and G03 for clockwise and counter-clockwise circular cuts respectively, defined by radius and end point or center point. G04 adds dwell time for drilling operations. G17, G18, G19 select the working plane for circular moves.

Uploaded by

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

Sec. 2.

1]

Basic Machine Codes

25

2.1 BASIC MACHINE CODES


2.1.1

Basic G-Codes for CNC Milling Machine

G00 Positioning ( Rapid traverse )


G00 X__ Y__ Z__ ;
The tool is moved in rapid traverse mode to the point programmed by the address X,
Y and Z. This is used for non-cutting motion, as the move is achieved at full traverse rate.
The tool path is not necessarily a straight line. The move can be programmed in either
absolute (G90) or incremental (G91) mode.
Block format (example)
N60 G90 G00 X8.0 Y7.0 Z10.0 ;

G00
(8.0,7.0,10.0)

N60
G90
G00
X
Y
Z

Sequence number
Absolute dimensions
Linear interpolation in rapid traverse
X-coordinate of end position
Y-coordinate of end position
Z-coordinate of end position

(3.0,1.0,2.0)

X
G01 Linear Interpolation ( Feed )
G01 X__ Y__ Z__ F__ ;
The tool is moved in a straight line at a given or predefined feedrate.The speed of each
axis is automatically controlled so that the tool moves in a straight line. This is used for
linear cutting motion. The move can be programmed in either absolute (G90) or incremental
(G91) mode.
Block format (example)
N70 G91 G01 X5.0 Y6.0 Z8.0 F100 ;

G01
(8.0,7.0,10.0)

N70
G91
G01
X
Y
Z
F

Sequence number
Incremental dimensions
Linear interpolation
Distance from start to end position
along X-axis
Distance from start to end position
along Y-axis
Distance from start to end position
along Z-axis
Feedrate

(3.0,1.0,2.0)

26

Manual Part Programming

[Ch. 2

G02 Circular Interpolation ( Clockwise )


G02 X__ Y__ R__ F__ ;
Radius and end position
G02 X__ Y__ I__ J__ F__ ;
Arc centre andend position
The tool is moved in a clockwise circular arc by specifying either the radius and
the end position or the arc centre and the end position. This is used for circular cutting
at a specified feedrate.

G02
Block format (radius and end position example)

N80 G90 G02 X7.6 Y8.2 R3.5 F100 ;


N80
G90
G02
X
Y
R
F

(7.6,8.2)

Sequence number
Absolute dimensions
Circular interpolation, clockwise
X-coordinate of end position
Y-coordinate of end position
Radius of arc, arc less than 180 degrees
(see below)
Feedrate

R=3.5
Centre

(4.0,2.5)

Block format (arc centre, end position example)


N90 G90 G02 X7.6 Y8.2 I2.4 J2.3 F100. ;
N90
G90
G02
X
Y
I
J
F

G02

Y
(7.6,8.2)

Sequence number
Absolute dimensions
Circular interpolation, clockwise
X-coordinate of end position
Y-coordinate of end position
Distance along X-axis from start to
arc centre
Distance along Y-axis from start to
arc centre
Feedrate

When using the radius and end position


option, the radius is assigned either a positive or a
negative value. An arc equal to or less than 180
degrees has a positive radius (1) and an arc greater
than 180 degrees has a negative value (2).
Block format (radius and end position examples)

Centre
(6.4,4.8)

J
(4.0,2.5)
I

G02

Y
R

N100 G02 X__ Y__ R__ F__ ;

RRadius and end position with arc less than


180 degrees.

1
End position

N110 G02 X__ Y__ R-__ F__ ;


Radius and end position with arc greater than
180 degrees.

Sec. 2.1]

Basic Machine Codes

27

G03 Circular Interpolation ( Counter-clockwise )


Radius and end position
G03 X__ Y__ R__ F__ ;
G03 X__ Y__ I__ J__ F__ ;
Arc centre and end position
The tool is moved in a counter-clockwise circular arc by specifying either the radius
and the end position or the arc centre and the end position. This is used for circular cutting
at a specified feedrate.
Block format (radius and end position example)

G03

N120 G90 G03 X3.3 Y7.8 R3.5 F100. ;


(3.3,7.8)

N120 Sequence number


G90 Absolute dimensions
G03 Circular interpolation, counter-clockwise
X
X-coordinate of end position
Y
Y-coordinate of end position
R
Radius of arc, arc less than 180 degrees

R=3.5
Centre

(7.0,2.0)

X
Block format (radius and end position example)

G03
N130 G91 G03 X-5.7 Y1.5 R-3.5 F100. ;
N130
G91
G03
X
Y
RF

Sequence number
Incremental dimensions
Circular interpolation, counter-clockwise
Distance along X-axis from start to end
position
Distance along Y-axis from start to end
position
Radius of arc, arc greater than
180 degrees
Feedrate

R=3.5
Centre
(2.3,4.2)
Y

8.0 2.7
X

Block format (arc centre, end position example)

G03
N140 G90 G03 X1.7 Y4.1 I-2.4 J2.3 F100. ;
N140
G90
G03
X
Y
I
J
F

Sequence number
Absolute dimensions
Circular interpolation, counter-clockwise
X-coordinate of end position
Y-coordinate of end position
Distance along X-axis from start to
arc centre
Distance along Y-axis from start to
arc centre
Feedrate

Y
Centre
(5.0,4.9)

(1.7,4.1)

J
(7.4,2.6)
I

28

Manual Part Programming

[Ch. 2

G04 Dwell ( Time delay )


G04 X__ ; (seconds)
G04 P__ ; (milliseconds)
The tool is held stationary for a period of time, determined by address X in seconds
or P in milliseconds. This can be used for drilling and boring cycles to ensure true precision
of hole depth.
Block format (second example)

G04
N150 G04 X1.5 ;

Z
0

N150 Sequence number


G04 Dwell
X
Time delay in seconds

SECOND

X
The following example is equivalent to the one
above.
Block format (millisecond example)

G04
N160 G04 P1500 ;

Z
0

N160 Sequence number


G04 Dwell

MILLISECOND
x1000

Sec. 2.1]

Basic Machine Codes

G17, G18, G19 Plane Selection


G17 ;
X-Y plane
G18 ;
X-Z plane
G19 ;
Y-Z plane

The tool moves in one of these planes. This


is used for determining the plane in which
circular interpolation or cutter compensation
occur. The default is G17 in the X-Y plane.

29

G17 G18 G19

G19

Y
G18
G17

Block format (G02 example)


N170 G17 G02 X__ Y__ R__ F__ ;

G02

N180 G17 G02 X__ Y__ I__ J__ F__ ;

N190 G18 G02 X__ Z__ R__ F__ ;

G18

N200 G18 G02 X__ Z__ I__ K__ F__ ;


G19

G17

N210 G19 G02 Y__ Z__ R__ F__ ;

N220 G19 G02 Y__ Z__ J__ K__ F__ ;

Block format (G03 example)


N230 G17 G03 X__ Y__ R__ F__ ;

G03

N240 G17 G03 X__ Y__ I__ J__ F__ ;

N250 G18 G03 X__ Z__ R__ F__ ;

G18

N260 G18 G03 X__ Z__ I__ K__ F__ ;


G19

N270 G19 G03 Y__ Z__ R__ F__ ;


N280 G19 G03 Y__ Z__ J__ K__ F__ ;

G17

30

Manual Part Programming

[Ch. 2

G20, G21 Inch/Millimetre Units


G20 ;
Inch unit
G21 ;
Millimetre unit
The units are specified at the beginning of the program before setting the work
coordinate system (G92) and must be the only instruction in the block. Once G20 or G21
is specified, it should not be changed during the program.
Block format (inch example)
N30 G20 ;
N40 G92 X4.0 Y5.0 Z4.0 ;
N30 Sequence number
G20 Inch units

G92 with G20

N40 Sequence number


G92 Setting the work coordinate system

POSITION
X 0.0000 in.
Y 0.0000 in.
Z 0.0000 in.

(4.0,5.0,4.0)

4.0 in.
5.0 in.

4.0 in.

Block format (millimetre example)


N30 G21 ;
N40 G92 X100. Y150. Z100. ;
N30 Sequence number
G21 Millimetre units

G92 with G21

N40 Sequence number


G92 Setting the work coordinate system

POSITION
X 0.000 mm
Y 0.000 mm
Z 0.000 mm

(100,150,100)

100 mm
150 mm

100 mm

Sec. 2.1]

Basic Machine Codes

31

G22, G23 Stored Stroke Limit


G22 X__ Y__ Z__ I__ J__ K__ ; Stored stroke limit ON
G23 ;
Stored stroke limit OFF
The tool movements are restricted to the inside or the outside of a specified
rectangular volume. The volume is determined by addresses X, Y, Z, I, J and K. It is used
as a safety precaution to guard the tool from any obstruction on the machine table.
Parameter RWL in the CNC controller memory selects either the inside or the outside as the
restricted volume. An RWL parameter value of 0 selects the inside and an RWL parameter
value of 1 selects the outside.
Block format (RWL parameter 0 example)
N470 G22 X100. Y70. Z0. I250. J210. K100. ;
N470
G22
X
Y
Z
I
J
K

G22
Z

(Restricted volume on the inside)

Sequence number
Stored stroke limit ON
X-coordinate point of boundary
Y-coordinate point of boundary
Z-coordinate point of boundary
X-coordinate point of boundary
Y-coordinate point of boundary
Z-coordinate point of boundary

Y
(250,210,100)

(100,70,0)

Block format (RWL parameter 1 example)

G22
N480 G22 X100. Y210. Z100. I250. J70. K0. ;
N480
G22
X
Y
Z
I
J
K

Sequence number
Stored stroke limit ON
X-coordinate point of boundary
Y-coordinate point of boundary
Z-coordinate point of boundary
X-coordinate point of boundary
Y-coordinate point of boundary
Z-coordinate point of boundary

(Restricted volume on the outside)

Y
(100,210,100)

(250,70,0)

Block format (cancel stroke limit example)


N490 G23 G00 X50. ;
N490
G23
G00
X

Sequence number
Stored stroke limit OFF
Positioning
X-coordinate of end position

32

Manual Part Programming

[Ch. 2

G28 Return to Home Position


G28 X__ Y__ Z__ ;
The tool is moved to home position via an intermediate point defined by address X,
Y and Z. The intermediate point is determined by G90 or G91 function code. In combination
with G91, the G28 command is used at the beginning of each program to return the tool
to the home position or to make a tool change during the program. It is advisable to return
the Z-axis first in order to clear the workpiece and clamps, then return the X and Y axes.
All movement is at rapid traverse.
Block format (beginning of program example)

G28
N10 G91 G28 Z0.0 ;
N20 G91 G28 X0.0 Y0.0 ;
N10
G91
G28
Z

(with no intermediate point)

Home
position

Sequence number
Incremental dimensions
Return to reference point (Z home position)
Incremental Z-distance to
intermediate point

N20 Sequence number


G91 Incremental dimensions
G28 Return to reference point (X and Y
home position)
X
Incremental X-distance to
intermediate point
Y
Incremental Y-distance to
intermediate point

Y
Start
position

When performing a tool change, it is only necessary to return the Z axis to the home
position.
Block format (tool change example)

G28
N400 G90 G28 Z100. ;
N400 Sequence number
G90 Absolute dimensions
G28 Return to reference point (Z home position)
Z
Z-coordinate point of intermediate point

Z Home
position

Intermediate
point (Z=100)
Start
position

Sec. 2.1]

Basic Machine Codes

33

G29 Return from Home Position


G29 X__ Y__ Z__ ;
The tool is moved from the home position to an intermediate point and then to the
point defined by addresses X, Y and Z. It is used after a tool change and the intermediate
point is the one defined earlier by the G28 move. When using incremental programming,
an incremental distance from the intermediate point to the end point is given by addresses
X, Y and Z.

Block format (absolute example)

G29
N410 G90 G28 X60. Y100. ;

Y
Intermediate
point
(60,100)

N420 G29 X120. Y40. ;


N410 Sequence number
G90 Absolute dimensions
G28 Return to reference point
X
X-coordinate of intermediate point
Y
Y-coordinate of intermediate point

G28

G29

X and Y
Home
position

G29
G28

(120,40)

Start
position

N420 Sequence number


G29 Return from reference point
X
X-coordinate of end point
Y
Y-coordinate of end point

Block format (incremental example)

G29 with G91


N430 G90 G28 X80. Y110. ;
N440 G91 G29 X70. Y-60. ;
N430 Sequence number
G90 Absolute dimensions
G28 Return to reference point
X
X-coordinate of intermediate point
Y
Y-coordinate of intermediate point
N440 Sequence number
G91 Incremental dimensions
G29 Return from reference point
X
X-distance from intermediate point to end
point
Y
Y-distance from intermediate point to end
point

Y
Intermediate
point
(80,110)

G28
G29

X and Y
Home
position

G29

60
G28

70
Start
position

34
G40, G41, G42 Tool
G40 ;
G41 D__ ;
G42 D__ ;

Manual Part Programming

[Ch. 2

Radius Compensation
Tool radius compensation cancel
Tool radius compensation left
Tool radius compensation right

The tool is moved to the left (G41) or to the right (G42) of the program path by the
amount of the cutter radius. The offset amount is registered with a D address.
Block format (tool radius compensation left
example)

G41

N270 G90 G17 G01 G41 D10 X30. Y30. F100. ;

(30,55)

N280 G01 Y55. ;


N270 Sequence number
G90 Absolute dimensions
G17 X-Y plane selection
G01 Linear interpolation
G41 Tool radius compensation left
D
Offset amount
X
X-coordinate of end point
Y
Y-coordinate of end point
F
Feedrate
Block format (tool radius compensation right
example)

(30,30)

D10 = tool radius

X
G42

N290 G90 G17 G01 G42 D11 X30 Y30 F100. ;


(30,30)

N300 G01 X60. ;


N270 Sequence number
G90 Absolute dimensions
G17 X-Y plane selection
G01 Linear interpolation
G42 Tool radius compensation right
D
Offset amount
X
X-coordinate of end point
Y
Y-coordinate of end point
F
Feedrate

(60,30)

D11 = tool radius

X
G40

Block format (tool radius compensation cancel


example)
N310 G00 G40 X10. Y10. ;
N310 Sequence number
G00 Positioning at rapid traverse
G40 Tool radius compensation cancel
X
X-coordinate of end point
Y
Y-coordinate of end point

(10,10)

Sec. 2.1]

Basic Machine Codes

Examples of G41, G42 Tool Radius Compensation


Block format (outside corner at an obtuse angle)

35

G42

N600 G42 D16 ;


.
.

N650 G01 X60. Y40. F100. ;

(60,40)

(100,40)

N660 X100. Y40. ;


N600 Sequence number
G42 Cutter compensation right
D
Offset address 16
G01 Linear interpolation
X, Y Coordinates of end point

Block format (inside corner at an acute angle)

G42
N700 G42 D17 ;

.
.

(50,70)

N750 G01 X50. Y70. F100. ;


N760 G02 X95. Y20. R60 ;
N700 Sequence number
G42 Cutter compensation right
D
Offset address 17
X, Y Coordinates of end point
G02 Circular interpolation CW
X, Y Coordinates of end point
R
Radius of arc

60
R=

(95,20)

Block format (Outside corner at an acute angle)

G41
N800 G41 D18 ;

.
.

(80,75)

N850 G03 X40. Y50. R60. F100. ;


N860 G01 X80. Y75. ;
N800 Sequence number
G41 Cutter compensation left
D
Offset address 18
G03 Circular interpolation CCW
X, Y Coordinates of end point
R
Radius of arc
X, Y Coordinates of end point

(40,50)

36

Manual Part Programming

G43, G44, G49 Tool Length Compensation


G43 H__ ; or G43 Z__ H__ ;
Tool length compensation positive
direction
G44 H__ ; or G44 Z__ H__ ;
Tool length compensation negative
direction
The tool is moved above or below some
standard tool position in order to compensate for
cutter length. The offset direction is set by either
G43 or G44 and the amount is registered with an
H address in the CNC controller memory. The
value specified by address Z is either added to or
subtracted from the offset amount. The offset
amount registered to H00 is always 0. Tool length
compensation is used when two or more tools of
different length are used in a program. This
makes it possible to apply length compensation
without changing the program coordinates.

[Ch. 2

Z
Standard
tool

H10=9 mm
H11=8 mm

Block format (G43 example) H11=8 mm

G43

N900 G43 H11 ;

N900 Sequence number


G43 Tool length compensation, positive
direction
H
Offset address 11
Block format (G44 and Z example) H10 = 9mm
Actual tool path

N910 G44 H10 ;


or

24
16
Tool path without compensation

N910 G44 Z-9.0 H00 ;

N910 Sequence number


G44 Tool length compensation, negative
direction
H
Offset address 10
Z
Compensation amount
H00 Offset amount is zero

G44

Block format (tool length compensation


cancel example)
N920 G49 ;
or
N920 H00 ;

Tool path without


compensation
29
20
Actual tool path

G49 Tool length compensation cancel


H00 Tool length compensation set to zero

Sec. 2.1]

Basic Machine Codes

G50, G51 Scaling


G50 ;
G51 I__ J__ K__ P__ ;

37

(Scaling OFF)
(Scaling ON)

The tool is moved by a scaling factor P about a scaling point defined by address I, J
and K.
Block format (scaling example)

G51
N520 G51 I70. J70. K0. P500 ;

(30,110)

N530 G01 X110. Y110. F100 ;

(90,110)
(110,110)

N540 X110. Y30. ;


N550 X30. Y30. ;
N520 Sequence number
G51 Scaling ON
I
X-coordinate of scaling centre
J
Y-coordinate of scaling centre
K
Z-coordinate of scaling centre
P
Scaling factor
Block format (scaling cancel example)
N560 G50 ;
N540 Sequence number
G50 Scaling OFF

Scaling centre
(70,70)
(50,50)
(30,30)

(90,50)
(110,30)

Programmed path
Tool path with scaling

38

Manual Part Programming

[Ch. 2

G54, G55, G56, G57, G58, G59


Work Coordinate System
G54 ;
Work coordinate system #1
G55 ;
Work coordinate system #2
G56 ;
Work coordinate system #3
G57 ;
Work coordinate system #4
G58 ;
Work coordinate system #5
G59 ;
Work coordinate system #6
The tool is moved to a coordinate system by setting the distance in each axis from the
current tool position to zero point of the new coordinate system. All moves are made in
incremental mode. G54 is selected when the power is turned on.
Block format (example)

G54, G55, G56


N460 G55 G00 X30. Y20. ;

N470 G01 X5. Y20. F100. ;


G56

N480 G01 X20. Y0. ;


N490 G56 G00 X20. Y25. ;
N460 Sequence number
G55 Work coordinate system #2
G00 Positioning
X
X-distance to zero point of coordinate
system #2
Y
Y-distance to zero point of coordinate
system #2
N490 Sequence number
G56 Work coordinate system #3
G00 Positioning
X
X-distance to zero point of coordinate
system #2
Y
Y-distance to zero point of coordinate
system #2

25
20

G55
X

20

X
30

5 20

20

Sec. 2.1]

Basic Machine Codes

39

G90 Absolute Dimensions


G90 ;
All points and tool positions are taken from an origin which is set by the G92
command. When moving the tool from one point to another, the coordinate is entered using
address X, Y and Z.
Block format (example)

G90
Z

N50 G90 G01 X25. Y35. Z30. ;


N50
G90
X
Y
Z

Sequence number
Absolute dimensions
X-coordinate of end point
Y-coordinate of end point
Z-coordinate of end point

(25,35,30)

Y
30
35

(0,15,5)

25

G91 Incremental Dimensions


G91 ;
All points and tool positions are measured from the current point. When moving the
tool from one point to another, the distance between the points is entered using address X,
Y and Z. Plus or minus values are dependent on the new point in relation to the current
point.
Block format (example)
N60 G91 G01 X25. Y20. Z25. F100 ;
N60
G91
G01
X
Y
Z

G91
Z

Sequence number
Incremental dimensions
Linear interpolation
X-distance from current point to end point
Y-distance from current point to end point
Z-distance form current point to end point

(25,35,30)

25

20
(0,15,5)
25

40
G92

Manual Part Programming

[Ch. 2

Programming of Absolute Zero Point


G92 X__ Y__ Z__ ;

This command sets the origin of the coordinate system a specified distance from the
home position or current tool position. Address X, Y and Z defines the location of the origin
in relation to the current tool position. It is used at the start of the program to establish the
coordinate system in relation to the CNC machine home position or can be used to establish
the coordinate system in relation to some arbitrary position.
Block format (home position example)
N40 G91 G28 X0. Y0. Z0. ;
.
.

G92
Z

Home
position

N80 G92 X350. Y350. Z250. ;


N80
G92
X
Y
Z

Sequence number
Programming of absolute zero point
X-distance from tool position to zero point
Y-distance from tool position to zero point
Z-distance from tool position to zero point

(350,350,250)
Absolute
zero point

Y
250

350

X
350

Block format (arbitrary position example)


N100 G92 X200. Y200. Z100. ;

G92
Z

N100 Sequence number


G92
Programming of absolute zero point
X
X-distance from tool position to zero point
Y
Y-distance from tool position to zero point
Z
Z-distance from tool position to zero point

Arbitrary
position

(200,200,100)
Absolute
Zero Point

100
200

200

Sec. 2.1]
2.1.2

Basic Machine Codes

41

Basic G Codes for CNC Lathe Machine

G00 Positioning ( Rapid traverse )


G00 X__ Z__ ;
The tool is moved in rapid traverse mode to the point programmed by address X and
Z. Address X is a diameter value. This is used for non-cutting motion, as the move is
achieved at full traverse rate. The tool path is not necessarily a straight line.
Block format (example)

G00

N110 G90 G00 X60. Z10. ;

N110 Sequence number


G90 Absolute dimensions
G00 Positioning
X
X-diameter of end point
Z
Z-coordinate of end point

(30,10)

60

G01 Linear Interpolation ( Feed )


G01 X__ Z__ F__ ;
The tool is moved in a straight line at a given or predefined feedrate. The speed of each
axis is automatically controlled so that the tool moves in a straight line. This is used for
linear cutting motion.
Block format (example)

G01

N120 G90 G01 X80. Z-100. F100. ;


N120 Sequence number
G90 Absolute dimensions
G01 Linear interpolation
X
X-diameter of end point
Z
Z-coordinate of end point
F
Feedrate

100
80

42

Manual Part Programming

[Ch. 2

G02 Circular Interpolation


( Clockwise )
G02 X__ Z__ R__ F__ ;
Radius and end position
G02 X__ Z__ I__ K__ F__ ;
Arc center and end position
The tool is moved in a clockwise circular arc by specifying either the radius and end
point or the arc center and end point. This is used for circular cutting at a specified feedrate.

Block format ( radius and end position example)


N70 G90 G02 X140. Z-100. R50. F100. ;
N70
G90
G02
X
Z
F

Sequence number
Absolute dimensions
Circular interpolation CW
X-diameter of end position
Z-coordinate of end position
Feedrate

G02
End
Point

R=50

Z
140
100

Block format (arc center and end position)

G02

N80 G90 G02 X140. Z-100. I75. K30. F100. ;


N80
G90
G02
X
Z
I
K
F

Sequence number
Absolute dimensions
Circular interpolation CW
X-diameter of end position
Z-coordinate of end position
X-distance from start to arc center
(this is not a diameter value)
Z-distance from start to arc center
Feedrat
e

End
Point

Arc
Centre
I

Z
140

K
100

Sec. 2.1]

Basic Machine Codes

43

G03 Circular Interpolation ( Counter-clockwise )


G03 X__ Z__ R__ F__ ;
Radius and end position
G03 X__ Z__ I__ K__ F__ ;
Arc centre and end position
The tool is moved in a counter-clockwise circular arc by specifying either the radius
and end point or the arc centre and end point. This is used for circular cutting at a specified
feedrate.
Block format (radius and end position example)

G03

N90 G91 G03 X100. Z-50. R60. F100. ;


N90
G91
G03
X
Z
R
F

Sequence number
Incremental dimensions
Circular interpolation CCW
Incremental X-diameter from start to end
position
Z-distance from start to end position
Radius of arc
Feedrate

End Point
50

R=60

Z
50

Block format (arc centre, end position example)


N100 G91 G03 X100. Z-40. I-25. K-80. F100. ;
N100 Sequence number
G91 Incremental dimensions
G03 Circular interpolation CCW
X
Incremental X-diameter from start to end
position
Z
Z-distance from start to end position
I
X-distance from start to arc centre
K
Z-distance from start to arc centre
F
Feedrate

G03

End Point
40

50
I

44

Manual Part Programming

[Ch. 2

G40, G41, G42 Tool Nose Radius Compensation


G40 X__ Z__ I__ K__ ;
Tool nose radius compensation cancel
G41 ;
Tool nose radius compensation left
G42 ;
Tool nose radius compensation right
The tool is moved to the left (G41) or to
the right (G42) of the programmed path by the
amount set in the tool offset table. Although the
two cutting edges of a turning tool appear to
come to a point, the point of the tool is a radius,
called the tool nose radius.

Block format (G41 example)

Tool tip without


compensation
R

Tool

G41

N190 G41 G01 X40. Z-50. ;


N200 G01 X60. Z-30. ;
N210 G01 X60. Z__ :
N190 Sequence number
G41 Tool nose radius compensation left
G01 Linear interpolation
X
X-diameter of end point
Z
Z-coordinate of end point

(30,-30)

(20,-50)

Tool direction
Tool path without
compensation

Block format (G42 example)

G42

N220 G42 G01 X30. Z-30. ;


N230 G01 X60. Z-50. ;
N240 G01 X60. Z__-100 ;
N220 Sequence number
G42
Tool nose radius compensation right
G01
Linear interpolation
X
X-diameter of end point
Z
Z-coordinate of end point

(30,-50)

(15,-30)

Z
Tool direction
Tool path without
compensation

Sec. 2.1]

Basic Machine Codes

45

G74 End Face Peck Drilling Cycle


G74 Z__ K__ F__ ;
Peck drilling
G74 X__ Z__ I__ K__ F__ D__ ; End facing
The tool moves in a forward motion then backward motion along the Z-axis. This
is used for peck drilling. When address X, I and D are included with G74, end facing
can be performed.
Block format (peck drilling example)

G74

N150 G90 G74 Z-50. K5. F50. ;

N150 Sequence number


G90 Absolute dimensions
G74 Peck drilling
Z
Z-coordinate of hole bottom
K
Depth of cut in Z direction
F
Feedrate

50

Cutting feed
Rapid traverse

Block format (end facing example)

G74

N160 G90 G74 X0. Z-8. I3. K5. F100. D1. ;


N160 Sequence number
G90 Absolute dimensions
G74 End facing
X
X-coordinate for depth of face
Z
Facing amount in Z direction
I
Depth of each face cut (incremental X
amount)
K
Depth of each cut in Z direction
F
Feedrate
D
Relief amount at end of each cut

X
Z

Z
K

Cutting feed
Rapid traverse

46
G75

Manual Part Programming

[Ch. 2

Grooving in X Axis
G75 X__ Z__ I__ K__ F__ D__ ;

The tool moves in a downward then an


upward motion along the X-axis. This is used for
grooving.

G75

Block format (example)


N170 G90 G75 X20. Z-8. I3. K-0.5 F100. D0. ;
I

N170 Sequence number


G90
Absolute dimensions
G75
Grooving in X-axis
X
X-coordinate for groove depth
Z
Z-coordinate for groove length
I
Depth of each peck cut (in X direction)
K
Movement amount in Z direction
F
Feedrate
D
Relief amount at bottom of each groove cut
G78 Thread Cutting Cycle
G78 X__ Z__ F__ ;
Straight thread cutting
G78 X__ Z__ I__ F__ ;
Taper thread cutting

Z
Cutting feed
Rapid traverse

G78

X
The tool performs straight thread cutting or
taper cutting depending whether address I is
specified. Address X is a diameter value and F is a
feedrate value to specify the lead. At the end point
the thread is chamfered at a 45 degree angle.

Block format (straight thread cutting example)


Z

N180 G90 G78 X50. Z-30. F1.5 ;

Cutting feed
Rapid traverse

N180 Sequence number


G90 Absolute dimensions
G78 Thread cutting cycle
X
X-diameter value for depth of thread
Z
Z-coordinate of end point
F
Feedrate determines lead
Block format (taper thread cutting example)

G78

N190 G90 G78 X50. Z-30. I10. F1.5 ;


N190 Sequence number
G90
Absolute dimensions
G78
Thread cutting cycle
X
X-diameter value for depth of thread,
at end point
Z
Z-coordinate of end point
I
Taper amount in X direction
F
Feedrate determines lead

Z
Cutting feed
Rapid traverse

Sec. 2.1]

Basic Machine Codes

47

G96, G97 Constant Surface Speed Control


G96 ;
Constant surface speed control
G97 ;
Constant surface speed control cancel
The spindle speed either remains constant or varies with the radius of the workpiece.
The spindle speed defined by address S is given with or before a G96 or G97.

Block format (G96 example)

G96

N60 G96 S0300 ;


N60 Sequence number
G96 Constant surface speed control
S
Surface speed (m/min)

Spindle
speed
(rpm)
Z (mm)

Block format (G97 example)

G97

N70 G97 S1000 ;


N70 Sequence number
G97 Constant surface speed control cancel
S
Spindle speed (rpm)

1000
Spindle
speed
(rpm)
Z (mm)

48

Manual Part Programming

[Ch. 2

2.1.3 M-Codes for CNC Machines


M-codes are used to control various functions on CNC machines. The following Mcodes are the same for both the lathe and milling machines, unless otherwise stated.
M00 Program Stop
M00 ;
Machining is stopped after a block containing M00. This can be used to make an
inspection before the machining is finished.
M01 Optional Stop
M01 ;
Machining is stopped after a block containing M01 only if the Optional Stop switch
on the CNC control panel is turned on.
M02 End of Tape, Restart
M02 ;
The end of an NC tape is indicated by M02. This is used when a program requires two
or more tapes. After reading an M02 the tape reader waits for the next tape to be inserted.
M03 Spindle Start Clockwise
M03 ;
The spindle rotation is started in a
clockwise direction. The spindle speed specified
with an S address is given before or with M03.

M04

Block format (example)


N50 S0300 M03 ;
N50 Sequence number
S
Spindle speed (m/min.)
M03 Spindle start CW
M04 Spindle Start Counterclockwise
M04 ;
The spindle rotation is started in a
counter-clockwise direction. The spindle speed
specified with an S address is given before or
with M04.

M03

X
Block format (example)
N60 S0200 M04 ;
N60 Sequence number
S
Spindle speed (m/min.)
M03 Spindle start CCW

Sec. 2.1]

Basic Machine Codes

49

M05 Spindle Stop


M05 ;
The spindle rotation is stopped. The spindle stops after a move command, if the
move and the spindle stop commands are both specified in the same block.
Block format (example)

M05
N80 G01 Z-20. M05 ;
N80
G01
Z
M05

Sequence number
Linear interpolation
Z-coordinate of end point
Spindle stops at Z=-20

Z
M06 Tool Change
M06 T____ ;

20

The current tool in use is replaced by the tool with the tool identification number given
in the T address. To perform a tool change on the milling machine, the Z-axis must be
returned home first. The tool is then inserted in the spindle arm. A tool change on the lathe
machine is performed by a rotation of the turret. The turret should be far enough away from
the workpiece to avoid a collision.
Block format (example)

M06
N90 M06 T0505 ;
N90 Sequence number
M06 Tool change
T0505
Tool number 05 with offset amount
stored with 05

05

Z
M07 Oil Mist On
M07 ;
The tool and workpiece are lubricated and cooled by an oil to improve the finish and
reduce tool wear and breakage.
Block format (example)

M07
N100 M07 ;
N100 Sequence number
M07 Oil mist on
M09 Coolant, Oil Unit Off
M09 ;
The coolant is turned off when cutting is
not being performed.

50

Manual Part Programming

[Ch. 2

M30 End of Program and Rewind


M30 ;
The end of a program is indicated by M30. This rewinds the NC tape and the program
in the CNC controller memory to its start after the program is completed.
M41 Low Range( for the lathe only )
M41 ;
The spindle rotates in the low gear. Its use depends on the material of the workpiece
and tool being used, and the required quality of the finished product.
M41 High Range
M42 ;

( for the lathe only )

The spindle rotates in the high gear. Its use depends on the material of the workpiece
and tool being used, and the requirement for a high quality finish.
M98 Subprogram Call
M98 P____ L__ ;
The program flow is transferred from the main program to the subprogram. Address
P specifies the subprogram being called and address L indicates the number of times the
subprogram is executed. See the subprogram section for more details.
M99 End of Subprogram
M99 ;
The program flow is transferred from the subprogram back to the main program. This
is used at the end of a subprogram. See the subprogram section for more details.

Sec. 2.1]
2.1.4
F

Basic Machine Codes

51

F-, S- and T-codes for CNC Machines


Feedrate Function
F___ ;

The tool is moved at a speed specified by address F. The feedrate units are inch/min
when programmed with G20 and mm/min when programmed with G21.
Block format (example)
N70 G21 G01 X10. F100. ;
N70
G21
G01
X
F

Sequence number
Metric units
Linear interpolation
X coordinate of end point
Feedrate (mm/min)

Spindle Speed Function


S____ ;
The spindle speed is specified by address S and is given in rpm.

Block format (example)


N40 S1000 ;
N40 Sequence number
S
Spindle speed (rpm)

Tool Function
T___ ;

The tool is called by its tool number and its tool offset number. Both numbers are
given in the T address and are registered in the tool table in the CNC controller memory.
Block format (example)
N30 T0104 ;
N30 Sequence number
T
Tool number (01), tool offset number (04)

52

Manual Part Programming

[Ch. 2

2.1.5 Examples of Basic Codes


Milling Example
The operations to machine the component shown in the figure below are as follows:
1)
2)
3)
4)
5)
6)
7)

Initialization
Facing
Deep side cutting
Track pocketing
Side cutting
Hole pattern
Program end

6 - 5 dia. * 20 deep
20
30
30
40

30
140

100
20
50
45
20
5
25

90

5
20

180

20

220

Z
5

20

10

Tools used:
100 mm dia. Face Mill
5 mm dia. End Mill
22 mm dia. End Mill
5 mm dia. Drill

Unit: mm

Sec. 2.1]

Basic Machine Codes

Listing of G code

1)

Initialization

O23;
N10
N20
N30
N40
N50
N60
N70

G91 G28 Z0.0;


G28 X0.0 Y0.0;
G21;
G92 X500.0 Y250.0 Z400.0;
T14;
M06;
S1400 M03;

2)

Facing

N80
N90
N100
N110
N120
N130
N140
N150
N160
N170
N180
N190
N200

G90 G43 G00 Z100.0 H14;


G00 X-170.0 Y-70.0;
G01 Z0.0 F500.0;
G01 X170.0 F1000.0;
Y-20.0;
X-170.0;
Y30.0;
X170.0;
Y80.0;
X-170.0;
G91 G28 Z0.0;
G28 X0.0 Y0.0;
M05;

3)

Deep side cutting

N210
N220
N230
N240
N250
N260
N270
N280

T15;
M06;
G49;
S1400 M03;
G90 G43 G00 Z100.0 H15;
G00 X-130.0 Y-70.0;
G01 Z-10.0 F500.0;
G42 G01 X-110.0 Y-70.0 D25
F1000.0;
G01 X110.0 F1000.0;
Y70.0;
X-110.0;
Y-70.0;
G01 G40 Y-100.0;
Z10.0;

N290
N300
N310
N320
N330
N340

53

Initialization
Z

Facing
Z

Deep side cutting


Z

54

Manual Part Programming

4)

Track pocketing

N350
N360
N370
N380
N390
N400
N410
N420
N430
N440

G00 X0.0 Y0.0;


G01 Z-5.0 F500.0;
G41 G01 Y-40.0 D25 F1000.0;
X20.0;
G03 X20.0 Y40.0 R40.0;
G01 X-20.0;
G03 X-20.0 Y-40.0 R40.0;
G01 X10.0;
G01 G40 X20.0 Y0.0;
G01 Z10.0;

5)

Side cutting

N450
N460
N470

G00 X-140.0 Y-70.0;


G01 Z-5.0 F1000.0;
G42 G01 X-90.0 Y-50.0 D25
F1000.0;
X65.0;
X90.0 Y-25.0;
Y20.0;
G03 X60.0 Y50.0 R30.0;
G01 X-60.0;
G02 X-90.0 Y20.0 R30.0;
G01 Y-50.0;
G01 G40 X-110.0 Y-90.0;
G01 Z10.0;
G91 G28 Z0.0;
G28 X0.0 Y0.0;

N480
N490
N500
N510
N520
N530
N540
N550
N560
N570
N580

[Ch. 2

Track pocketing
Z

Y
X

Side cutting
Z

Y
X

Sec. 2.1]
6)

Basic Machine Codes

Hole pattern

N590 T16;
N600 M06;
N610 S1400 M03;
N620 G49;
N630 G90 G43 G00 Z100.0 H16;
N640 G01 X20.0 Y0.0 F1000.0;
N650 G01 Z-20.0 F500.0;
N660 G04 X1.0;
N670 G01 Z0.0;
N680 G00 Y17.32 X10.0;
N690 G01 Z-20.0 F500.0;
N700 G04 X1.0;
N710 G01 Z0.0;
N720 G01 X-10.0;
N730 G01 Z-20.0 F500.0;
N740 G04 X1.0;
N750 G01 Z0.0;
N760 G01 X-20.0 Y0.0;
N770 G01 Z-20.0 F500.0;
N780 G04 X1.0;
N790 G01 Z0.0;
N800 X-10.0 Y-17.32;
N810 G01 Z-20.0 F500.0;
N820 G04 X1.0;
N830 G01 Z0.0;
N840 G01 X10.0;
N850 G01 Z-20.0 F500.0;
N860 G04 X1.0;
N870 G01 Z0.0;

7)

55

Drilling
Z

Program end

Program end
N880 G91 G28 Z0.0;
N890 G91 G28 X0.0 Y0.0;
N900 M05;
N910 G40;
N920 G49;
N930 M30;
%

You might also like