1. G-Code and Their Functions
G00 — Rapid positioning
G01 — Linear interpolation
G02 — Clockwise circular interpolation
G03 — Counterclockwise circular interpolation
G04 — Dwell (timed pause)
G05 — Circular interpolation through an intermediate point
G06 — Parabolic interpolation
G07 — Z-spline interpolation
G08 — Feed acceleration
G09 — Feed deceleration
G10 — Data setting
G16 — Polar coordinate programming
G17 — XY plane machining
G18 — XZ plane machining
G19 — YZ plane machining
G20 — Inch units (FANUC system)
G21 — Metric units (FANUC system)
G22 — Radius dimension programming
G220 — Used in system operation interface
G23 — Diameter dimension programming
G230 — Used in system operation interface
G24 — Subprogram end
G25 — Jump machining
G26 — Cycle machining
G30 — Scaling cancellation
G31 — Scaling definition
G32 — Constant pitch thread cutting, inch
G33 — Constant pitch thread cutting, metric
G34 — Increasing pitch thread cutting
G35 — Decreasing pitch thread cutting
G40 — Tool compensation/offset cancellation
G41 — Tool compensation left
G42 — Tool compensation right
G43 — Positive tool offset
G44 — Negative tool offset
G45 — Tool offset +/+
G46 — Tool offset +/-
G47 — Tool offset -/-
G48 — Tool offset -/+
G49 — Tool offset 0/+
G50 — Tool offset 0/-
G51 — Tool offset +/0
G52 — Tool offset -/0
G53 — Linear offset cancellation
G54 — Workpiece coordinate system 1
G55 — Workpiece coordinate system 2
G56 — Workpiece coordinate system 3
G57 — Workpiece coordinate system 4
G58 — Workpiece coordinate system 5
G59 — Workpiece coordinate system 6
G60 — Exact path mode (fine)
G61 — Exact path mode (medium)
G62 — Exact path mode (rough)
G63 — Thread tapping
G68 — Tool offset, internal corner
G69 — Tool offset, external corner
G70 — Inch units (Siemens system)
G71 — Metric units (millimeters)
G74 — Return to reference point (machine zero)
G75 — Return to programmed coordinate zero
G76 — Thread cutting composite cycle
G80 — Fixed cycle cancellation
G81 — Outer circle fixed cycle
G331 — Thread fixed cycle
G90 — Absolute dimension
G91 — Incremental dimension
G92 — Preset coordinate
G93 — Inverse time feed rate
G94 — Feed rate per minute
G95 — Feed rate per revolution
G96 — Constant surface speed control
G97 — Cancel constant surface speed control
2. Detailed Explanation of G-Code Functions
Rapid Positioning
Format: G00 X(U)__ Z(W)__
Description:
- This command moves the tool rapidly to a specified position in point-to-point control mode. No machining occurs during movement.
- All programmed axes move simultaneously at the speed defined by parameters. When one axis reaches its programmed value, it stops, while other axes continue moving.
- Coordinates that do not need to move do not require programming.
- G00 can be written as G0.
Example:
G00 X75 Z200
G01 U-25 W-100
The tool moves rapidly 25 units along both X and Z axes to point A, then Z moves an additional 75 units rapidly to point B.
Linear Interpolation
Format: G01 X(U)__ Z(W)__ F__(mm/min)
Description:
- This command moves the tool to a specified position using linear interpolation. The movement speed is determined by the feed rate specified with the F command.
- All coordinates can move simultaneously (linked motion).
- G01 can be written as G1.
Example:
G01 X40 Z20 F150
The tool moves with two-axis linkage from point A to point B at a feed rate of 150 mm/min.
Circular Interpolation
Format 1: G02 X(U)__ Z(W)__ I__ K__ F__
Description:
- When using G90, X and Z represent the absolute coordinates of the arc’s endpoint relative to the programmed zero point. In G91, they represent incremental values relative to the arc’s starting point. Regardless of G90 or G91, I and K are the incremental coordinates of the arc’s center relative to the starting point. I corresponds to the X direction, and K to the Z direction. The arc center coordinates must not be omitted unless another programming format is used.
- The G02 command allows programming of quadrant arcs, full circles, etc. Note: When crossing quadrants, backlash compensation is automatically applied. If the backlash compensation set in the parameters significantly differs from the machine’s actual backlash, visible machining marks may appear on the workpiece.
- G02 can be written as G2.
Example: G02 X60 Z50 I40 K0 F120
The tool follows a clockwise arc to X60, Z50 with a center offset of I40 (X direction) and K0 (Z direction) at a feed rate of 120 mm/min.
Format 2: G02 X(U)__ Z(W)__ R(+/-)__ F__
Description:
- This format cannot be used for full-circle programming.
- R is the radius of the arc on one side of the workpiece. R is signed: “+” indicates an arc angle less than 180 degrees (can be omitted); “-” indicates an arc angle greater than 180 degrees.
- Based on the endpoint coordinates, if the distance between the start and endpoint is greater than 2R, the arc is replaced by a straight line.
Example: G02 X60 Z50 R20 F120
Format 3: G02 X(U)_ Z(W)_ CR=(radius) F
Format 4: G02 X(U)_ Z(W)_ D_(diameter) F_
Description:
These formats are essentially the same as Format 2, with CR specifying the radius and D specifying the diameter of the arc.
Counterclockwise Circular Interpolation
Description: The format is identical to the G02 command, except the arc rotates in the opposite (counterclockwise) direction.
Dwell (Timed Pause)
Format: G04_F_ or G04_K_
Description: Machining movement pauses for a specified duration, then resumes. The pause time is defined by the value following F, in seconds, with a range of 0.01 to 300 seconds.
Circular Interpolation via Intermediate Point
Format: G05 X(U)_ Z(W)_ IX_ IZ_ F_
Description: X and Z are the endpoint coordinates, while IX and IZ are the intermediate point coordinates. Other aspects are similar to G02/G03.
Example: G05 X60 Z50 IX50 IZ60 F120
Acceleration/Deceleration
Format: G08
Description: Occupies a single program line. When executed, the feed rate increases by 10%. To increase by 20%, two separate G08 lines are required.
Radius Programming
Format: G22
Description: Occupies a single program line. The system operates in radius mode, and subsequent values in the program are interpreted as radius dimensions.
Diameter Dimension Programming
Format: G23
Description: Occupies a single program line. The system operates in diameter mode, and subsequent values in the program are interpreted as diameter dimensions.
Jump Machining
Format: G25 LXXX
Description: When the program reaches this line, it jumps to the specified program segment (XXX represents the segment number).
Cycle Machining
Format: G26 LXXX QXX
Description: When the program reaches this line, the specified program segment (from LXXX to this line) is treated as a loop, with the number of cycles determined by the value following Q.
Scaling Cancellation
Format: G30
Description: Occupies a single program line. Used in conjunction with G31 to cancel its scaling function.
Ratio Definition
Format: G31 F_
G32: Equal pitch thread machining (imperial)
G33: Equal pitch thread machining (metric)
Format: G32 X(U)_ Z(W)_ F_
Description:
- X and Z are endpoint coordinates, F is the thread pitch.
- G32 can only machine single-start, single-tool threads.
- Changes in X values allow machining of tapered threads.
- Spindle speed should not be too high to avoid excessive tool wear.
Constant Pitch Thread Cutting (Metric)
Format: G33 X(U)_ Z(W)_ F_
Description: Same as G32, but for metric threads.
Set Workpiece Coordinates / Set Spindle Speed Limits
Format: G50 S_ Q_
Description:
S specifies the maximum spindle speed, Q specifies the minimum spindle speed.
Set Workpiece Coordinate Systems
Format: G54
Description: G54 corresponds to the first coordinate system, with its origin position set in the machine parameters.
- G55: Sets workpiece coordinate system 2
- G56: Sets workpiece coordinate system 3
- G57: Sets workpiece coordinate system 4
- G58: Sets workpiece coordinate system 5
- G59: Sets workpiece coordinate system 6
Exact Path Mode
Format: G60
Description:
During machining with multiple consecutive movements, using exact path programming (G60) introduces a buffering process (i.e., deceleration) before proceeding to the next segment.
Continuous Path Mode
Format: G64
Description:
Relative to G60, this mode is primarily used for rough machining, allowing continuous movement without deceleration between segments.
Return to Reference Point (Machine Zero)
Format: G74 X Z
Description:
- No other commands can appear in this program segment.
- Coordinates following G74 (X, Z) return to zero in sequence.
- The machine must have a reference point switch installed before using G74.
- Single-axis return to zero is also possible.
Return to Programmed Coordinate Zero
Format: G75 X Z
Return to Programmed Starting Point
Format: G76
Description:
Returns the tool to the position where machining began.
Outer/Inner Circle Fixed Cycle
Format: G81_X(U)__ Z(W)__ R__ I__ K__ F_
Description:
- X, Z are the endpoint coordinates; U, W are incremental values relative to the current point.
- R is the diameter to be machined at the starting section.
- I is the roughing feed, K is the finishing feed. Both I and K are signed values and must have the same sign. The sign convention is: “-” for cutting from the outer surface toward the center axis (outer circle), and “+” for the opposite.
- Different combinations of X, Z, and R determine various shapes, such as tapered or non-tapered, positive or negative taper, and left or right cutting.
- F specifies the cutting speed (mm/min).
- After machining, the tool stops at the endpoint.
Example: G81 X40 Z100 R15 I-3 K-1 F100
Machining Process:
- G01 feeds at twice the I value (first cut at I, final cut at I+K for finishing), performing deep cutting.
- G01 performs two-axis interpolation to cut to the endpoint section, stopping if machining is complete.
- G01 retracts the tool by I to a safe position, simultaneously smoothing the auxiliary cutting surface.
- G00 rapidly advances to a position outside the workpiece by I, reserving I for the next cutting step, and repeats from step 1.
Absolute Programming
Format: G90
Description:
- When G90 is programmed, all subsequent coordinate values are based on the programmed zero point.
- The machine defaults to G90 mode upon power-on.
Example:
N0010 G90 G92 X20 Z90
N0020 G01 X40 Z80 F100
N0030 G03 X60 Z50 I0 K-10
N0040 M02
Incremental Programming
Format: G91
Description:
When G91 is programmed, all subsequent coordinate values are calculated as incremental movements relative to the previous coordinate position. Each new segment uses the previous point as the starting point for programming.
Example:
N0010 G91 G92 X20 Z85
N0020 G01 X20 Z-10 F100
N0030 Z-20
N0040 X20 Z-15
N0050 M02
Set Workpiece Coordinate System
Format: G92 X__ Z__
Description:
- G92 changes the displayed coordinate values in the system without moving the axes, effectively setting the coordinate origin.
- The effect of G92 is to update the displayed tool tip coordinates to the specified values.
- X and Z after G92 can be programmed individually or together.
Feed Rate Per Minute: G94
Description:
This is the default machine state upon power-on, where the feed rate is specified per minute.
Subprogram Call
Format: G20 L_ N_
Description:
- L specifies the subprogram name following N, but N itself is not included in the input. The number following N must be between 1 and 99999999.
- No other content is allowed in this program segment.
Subprogram End and Return
Format: G24
Description:
- G24 indicates the end of a subprogram and returns to the next segment of the calling program.
- G24 is used in pair with G20.
- No other commands are allowed in the G24 segment.
3. G-code Programming Examples
Example: The following example illustrates the process of passing parameters in the subroutine calling process, please note the application.
Program name: P10
M03 S1000
G20 L200
M02
N200 G92 X50 Z100
G01 X40 F100
Z97
g02 z92 x50 i10 k0 f100
G01 Z-25 F100
G00 X60
Z100
G24
For multiple recalls, use the following format
M03 S1000
N100 G20 L200
N101 G20 L200
N105 G20 L200
M02
N200 G92 X50 Z100
G01 X40 F100
Z97
g02 z92 x50 i10 k0 f100
G01 Z-25 F100
G00 X60
Z100
G24
G331-Threading cycle
Format: G331 X_ Z_I_K_R_p_
Description:
(1) X varies toward the diameter, X=0 is a straight thread
(2) Z is the thread length, absolute or relative programming is possible
(3) I is the length of the thread in the X direction after cutting the tail, ± value
(4) R is the diameter difference between the outer diameter of the thread and the root diameter, positive value
(5) K pitch KMM
(6) p thread cycle processing times, i.e., cut in a few cuts
Tips:
(1) each feed depth of R ÷ p and rounding, the last knife does not feed to lighten the thread surface
(2) The backing off of internal threads is based on the positive and negative directions along X to determine the designation of the I value.
(3) The starting position of the threading cycle is the point of the tool aligned with the outer circle of the thread.
Example:
M3
G4 f2
G0 x30 z0
G331 z-50 x0 i10 k2 r1.5 p5
G0 z0
M05
4. Additional Information and Notes
1. G00 vs. G01
- G00: Moves in straight or polyline paths for point positioning only, not for cutting.
- G01: Moves in a straight line to the specified target point at the designated feed rate, typically used for cutting operations.
2. G02 vs. G03
- G02: Clockwise circular interpolation.
- G03: Counterclockwise circular interpolation.
3. G04: Dwell or Pause Command
- Used for spindle forward/reverse switching, machining blind holes, stepped holes, or turning grooves.
4. G17, G18, G19: Plane Selection Commands
- Specifies the machining plane, typically used for milling machines and machining centers.
- G17: X-Y plane (default, can be omitted) or a plane parallel to X-Y.
- G18: X-Z plane or a parallel plane; in CNC lathes, only the X-Z plane is used, no specific designation needed.
- G19: Y-Z plane or a parallel plane.
5. G27, G28, G29: Reference Point Commands
- G27: Returns to the reference point to check and confirm its position.
- G28: Automatically returns to the reference point via an intermediate point.
- G29: Returns from the reference point, used in conjunction with G28.
6. G40, G41, G42: Radius Compensation
- G40: Cancels tool radius compensation.
- G41: Left compensation.
- G42: Right compensation.
7. G43, G44, G49: Length Compensation
- G43: Positive tool length compensation.
- G44: Negative tool length compensation.
- G49: Cancels tool length compensation.
8. G32, G92, G76: Thread Cutting
- G32: Thread cutting.
- G92: Fixed thread cutting cycle.
- G76: Compound thread cutting cycle.
9. Turning Operations: G70, G71, G72, G73
- G71: Axial rough turning compound cycle.
- G70: Finishing compound cycle.
- G72: End face turning, radial rough turning cycle.
- G73: Profile rough turning cycle.
10. Milling Machines and Machining Centers
- G73: High-speed peck drilling for deep holes.
- G83: Peck drilling for deep holes.
- G81: Drilling cycle.
- G82: Deep hole drilling cycle.
- G74: Left-hand thread machining.
- G84: Right-hand thread machining.
- G76: Fine boring cycle.
- G86: Boring cycle.
- G85: Reaming cycle.
- G80: Cancels fixed cycle.
11. Programming Modes: G90, G91
- G90: Absolute coordinate programming.
- G91: Incremental coordinate programming.
12. Spindle Setting Commands
- G50: Sets the maximum spindle speed.
- G96: Constant surface speed control.
- G97: Spindle speed control (cancels constant surface speed control).
- G98: Returns to the reference point (last hole).
- G99: Returns to the R point (intermediate hole).
13. Spindle Rotation and Stop Commands
- M03: Spindle forward rotation.
- M04: Spindle reverse rotation.
- M05: Spindle stop.
14. Coolant Control Commands
- M07: Mist coolant on.
- M08: Liquid coolant on.
- M09: Coolant off.
15. Motion Stop Commands
- M00: Program pause.
- M01: Optional stop (planned stop).
- M02: Machine reset.
- M30: Program end, returns the program pointer to the beginning.
16. Subprogram Call
- M98: Calls a subprogram.
17. Return to Main Program
- M99: Returns to the main program from a subprogram.