Common G-Codes for CNC Machine

Share:
CNC programming is a term that refers to the methods for generating the instructions with the help of preparatory and miscellaneous functions that drives the CNC machine tool. CNC programming requires the knowledge of Preparatory function (G Codes) and Miscellaneous function (M Codes) which are supplied along with the machine manuals for programmers help.

Preparatory Function (G-Code)

G codes are instructions describing machine tool movement. It often requires other information such as feed rate or axes co-ordinates. The FANUC standard has a large selection of G codes, all of which may not be available on all the machines. Following is the list of common G codes.
G-Code

Code
Description
Code
Description
G00
Rapid traverse
G40
TNRC cancel
G01
Linear interpolation
G41
TNRC left

G02
CW circular interpolation

G42

TNRC right

G03
CCW circular interpolation

G50
Work coordinate change/ Maximum spin setting
G04
Dwell
G96
Constant surface speed
G20
Inch data input
G97
Constant RPM
G21
mm data input
G98
Feed per minute
G28
Reference point return
G99
Feed per revolution


Description of G Codes. The description of commonly used G codes is given below. Some of the G codes are called non-modal or one-shot G codes. Such codes are effective only at the blocks where they are specified (a single but complete programming instruction is called a block which consists of word addresses such as G01 X30 M03 S2000 F60 etc. A new block should start from a new line). Other codes are called modal codes and are effective until changed. For example, if two consecutive blocks use G00, then it is not necessary to write G00 in the second block. In fact, even the parameters of G codes such as coordinates, feed etc. are modal values, and hence, need not be repeated in subsequent blocks if they remain unchanged.

(a) G00 Rapid Positioning of Tool. The tool goes to a defined point at a fast speed from the current position in a straight line, if only X or only Z is changing. If both are required to change for reaching the defined point, the path may not be the straight path. Thus, G00 does not always affect an exact straight line motion. This code is used only for positioning the tool for the next operation. The speed of the tool movement is the fastest possible speed on a particular machine. This speed is pre-defined for a machine by the manufacturer. The user has no control over it.

Examples: G00 X32, Z 2 (goes to absolute coordinates (32, 2)
G00 U10 W -5 (goes to (10, -5) point with respect to the current position, i.e. to absolute coordinates (42,-3))

(b) G01 Linear Interpolation. A G01 causes linear motion up to the given position at the last or currently specified feed rate.
Examples:
  • G01 X30.0 2-1.0 F100.0 (goes to absolute coordinates (30.-1) from the current position in a straight line at feed 100)
  • G01 X 0.0 (Z  and F  values are as defined in the previous command. Unchanged parameters need not be repeated)
(c) G02 Clockwise Arc. A G02 causes a clockwise arc of the specified radius from the current position to the specified position at the last or currently specified feed rate.
Examples:
  • G02 X30.0 Z-15.0 R5.0 F60 (a clockwise arc of radius 5 is made from the current position to (30.-15) point at feed 60. If such an arc is mathematically not possible, the machine would give an error message.) 
  • G02 X 40.0 Z -20.0 (Radius 5 and feed 60. as chosen in the previous statement, is implied)
(d) G03 Counter Clockwise Arc. A G03 causes a counter clockwise arc of the specified radius from the current position to the specified position at the current or previously specified feed rate.
Example: G03 X30.0Z-15.0 R5.0 F60

Note
(a) Arcs can also be made by specifying the centre, rather than the radius. The centre is specified by I and K addresses, which are the relative coordinates of the centre with respect to the start point in X and Z directions, respectively (Refer Fig. 4.1). For example, if the current position of the tool is (0, 0), then both G03 X30 Z-15 R15 and G03 X30 Z-15 I0 K-15 make the same arc. I0 and K0 may be omitted.

(b) If I, K and R addresses are specified simultaneously. I and K are ignored and an arc of specified radius is made.

(c) Usually, it is better to specify an arc by its radius, because even a slight inaccuracy (± 0.05 mm, typically) in specifying the centre may not be permitted by the machine and the program will terminate. The exact centre lies on the perpendicular bisector of the line joining the start point and the end point. If the error in specifying the centre is within the permissible limits, the machine places the centre at a point on the perpendicular bisector which is nearest to the specified centre. It does not manipulate the specified end point for making a possible arc. The R address, on the other hand, will always make an arc unless the radius is smaller than half the distance between the start point and the end point.

(d) Practically, there is no limitation on the minimum radius for circular interpolation. However, every machine has its own limitation for the maximum radius it can handle.
(e) G04 Dwell. A G04 causes the program to wait for a specified amount of time. The time can be specified in seconds with the X or U prefixes, or in milliseconds with the P prefix.
Examples:
G04 X1.5
G04 U1.5
G04 P1500 (all the three statements result in a pause of 1.5 seconds)

(f)  G20 Inch Data Input. A G20 causes coordinates to be interpreted as being in inches. This can only be specified at the start of the main program.
Example: G20

(g) G21 Metric Data Input. A G21 causes coordinates to be interpreted as being in mm. This can only be specified at the start of the main program. Usually this is the default setting of a machine.
Example: G21

(h) G28 Go to Reference Point. A G28 causes a fast traverse to the specified position and then to the machine datum. Both are straight line motions.
Examples:       G28 X34.0 Z5.0 (tool goes to the machine datum via (34, 5 point)
G28 U0.0 W0.0 (tool goes datum directly because U0, W0 refers the current

(i) G40 Cancel Compensation. A G40 cancels tool nose radius compensation.
Example: G40

(j) G41 Compensate Left. G41 enables tool nose radius compensation to the left of the programmed path. The tool shifts to the left of its direction of 1 motion by its radius.
Example: G41

(k) G42 Compensate Right. A G42 enables tool nose radius compensation to the right of the programmed path, when viewed along its direction of motion.
Example: G42

(l) G96 Enables Constant Surface Speed. It sets the surface speed to 100 meters a minute. The RPM changes suitably to maintain a constant surface speed. RPM can increase upto a maximum value as defined by G50 (clamp spindle).
Example: G96 S 100

(m) G97 Cancels Constant Surface Speed. The spindle speed will not change until the next S value is encountered. Usually, this is the default choice.
Example: G97

(n) G98 Feed per minute mode. This is the default.
Examples: G98 (the feed per minute mode is set, but feed not specified here.) G98 F100 (feed = 100 specified)

(o) G99 Feed Per Revolution Mode.
Example: G99

Note. Feed in mm/min = Feed in mm per revolution x RPM

No comments