Fanuc G Code Complete Guide - WhalesCNC

Fanuc G Code Complete Guide

I. Brief Description of FANUC G-Code Functions

G-Code Description G-Code Description
G00 Rapid Positioning G40 Tool Compensation/Tool Offset Cancel
G01 Linear Interpolation G41 Tool Compensation—Left
G02 Clockwise Circular Interpolation G42 Tool Compensation—Right
G03 Counter-Clockwise Circular Interpolation G43 Tool Offset—Positive
G04 Dwell (Timed Pause) G44 Tool Offset—Negative
G05 Circular Interpolation Through Midpoint G45 Tool Offset +/+
G06 Parabolic Interpolation G46 Tool Offset +/-
G07 Z-Spline Curve Interpolation G47 Tool Offset -/-
G08 Feed Acceleration G48 Tool Offset -/+
G09 Feed Deceleration G49 Tool Offset 0/+
G10 Data Setting G50 Tool Offset 0/-
G16 Polar Coordinate Programming G51 Tool Offset +/0
G17 Machining in XY Plane G52 Tool Offset -/0
G18 Machining in XZ Plane G53 Linear Offset, Cancel
G19 Machining in YZ Plane G54 Set Workpiece Coordinate
G20 Inch Units (FANUC System) G55 Set Workpiece Coordinate Two
G21 Metric Units (FANUC System) G56 Set Workpiece Coordinate Three
G22 Radius Dimension Programming G57 Set Workpiece Coordinate Four
G220 Used on System Operation Interface G58 Set Workpiece Coordinate Five
G23 Diameter Dimension Programming G59 Set Workpiece Coordinate Six
G230 Used on System Operation Interface G60 Exact Path Mode (Fine)
G24 Subprogram End G61 Exact Path Mode (Medium)
G25 Jump Machining G62 Exact Path Mode (Coarse)
G26 Loop Machining G63 Thread Tapping
G30 Scale Cancel G68 Tool Offset, Internal Angle
G31 Scale Definition G69 Tool Offset, External Angle
G32 Constant Pitch Thread Cutting, Inch G70 Inch Units (Siemens, FANUC is G21)
G33 Constant Pitch Thread Cutting, Metric G71 Metric Units, Millimeter
G34 Increasing Pitch Thread Cutting G74 Return to Reference Point (Machine Zero)
G35 Decreasing Pitch Thread Cutting G75 Return to Programming Coordinate Zero
G80 Fixed Cycle Cancel G331 Thread Fixed Cycle
G81 External Circle Fixed Cycle G90 Absolute Dimensions
G91 Relative Dimensions G92 Preset Coordinate
G93 Time Reciprocal, Feed Rate G94 Feed Rate, Feed per Minute
G95 Feed Rate, Feed per Revolution G96 Constant Surface Speed Control
G97 Cancel Constant Surface Speed Control

II. Detailed Explanation of G-Code Functions

Rapid Positioning

Format: G00 X(U)__Z(W)__

Description:

  1. This command moves the tool rapidly to a specified position using point-to-point control. No machining should be done during this movement.
  2. All programmed axes move simultaneously at the speed defined by the parameters. Once an axis completes its programmed distance, it stops, while the other axes continue to move.
  3. Coordinates that are not moving do not need to be programmed.
  4. G00 can also be written as G0.

Example: G00 X75 Z200
G01 U-25 W-100
First, X and Z move simultaneously 25 units quickly to point A, then Z moves another 75 units quickly to point B.

Linear Interpolation

Format: G01 X(U)__Z(W)__F__(mm/min)

Description:

  1. This command moves the tool to a specified position using linear interpolation. The movement speed is defined by the F command for feed rate. All coordinates can be linked together.
  2. G01 can also be written as G1.

Example: G01 X40 Z20 F150
Two-axis linkage from point A to point B.

Circular Interpolation

Format 1: G02 X(u)____Z(w)____I____K____F_____

Description:

  1. In G90 mode, the X, Z coordinates are the absolute coordinates relative to the programming zero point. In G91 mode, they are the incremental values relative to the starting point of the arc. Regardless of G90 or G91, I and K are the incremental coordinates of the center of the circle relative to the starting point. I is the value in the X direction, and K is the value in the Z direction. The center coordinates must not be omitted during circular interpolation unless programmed in another format.
  2. When programming with the G02 command, you can directly program quadrant circles, full circles, etc.

Note: When crossing quadrants, gap compensation will be automatically performed. If the gap compensation entered in the parameter area is significantly different from the actual machine backlash, obvious cutting marks will appear on the workpiece.

  1. G02 can also be written as G2.

Example: G02 X60 Z50 I40 K0 F120

Format 2: G02 X(u)____Z(w)____R(+/-)__F__

Description:

  1. Cannot be used for full circle programming.
  2. R is the radius of the single-sided R arc of the workpiece. The sign “+” indicates that the arc angle is less than 180 degrees; “-” indicates that the arc angle is greater than 180 degrees. The “+” can be omitted.
  3. It is based on the coordinates of the endpoint. When the length value of the endpoint and the starting point is greater than 2R, it 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___

These two programming formats are essentially the same as Format 2.

Clockwise Circular Interpolation

Description: Except for the direction of the arc rotation, the format is the same as the G02 command.

Dwell (Timed Pause)

Format: G04__F__ or G04__K__

Description: The machining motion pauses, and resumes after the time specified by the data following F. The unit is in seconds, ranging from 0.01 seconds to 300 seconds.

Circular Interpolation Through Midpoint

Format: G05 X(u)____Z(w)____IX_____IZ_____F_____

Description:

  1. X, Z are the endpoint coordinates, IX, IZ are the midpoint coordinates. Other aspects are similar to G02/G03.

Example: G05 X60 Z50 IX50 IZ60 F120

Acceleration/Deceleration

Format: G08

Description: They occupy a line by themselves in the program segment. When the program runs to this segment, the feed rate will increase by 10%. To increase by 20%, it needs to be written as two separate segments.

Radius Programming

Format: G22

Description: It occupies a line by itself in the program, and the system operates in radius mode. The values below in the program are also based on the radius.

Diameter Dimension Programming

Format: G23

Description: It occupies a line by itself in the program, and the system operates in diameter mode. The values below in the program are also based on the diameter.

Jump Machining

Format: G25 LXXX

Description: When the program runs to this segment, it jumps to the program segment specified (XXX is the program segment number).

Loop Machining

Format: G26 LXXX QXX

Description: When the program runs to this segment, the specified program segment starts to this segment as a loop. The number of loops is determined by the value following Q.

Scale Cancel

Format: G30

Description: It occupies a line by itself in the program and is used in conjunction with G31 to cancel the function of G31.

Scale Definition

Format: G31 F_____

Constant Pitch Thread Cutting (Inch)

Format: G32/G33 X(u)____Z(w)____F____

Description:

  1. X, Z are the endpoint coordinates, F is the pitch.
  2. G33/G32 can only machine single-point, single-start threads.
  3. Changes in the X value can machine tapered threads.
  4. When using this command, the spindle speed should not be too high, otherwise tool wear will be significant.

Set Workpiece Coordinate / Set Spindle Max (Min) Speed

Format: G50 S____Q____

Description: S is the maximum spindle speed, Q is the minimum spindle speed.

Set Workpiece Coordinate

Format: G54

Description: The system can have multiple coordinate systems. G54 corresponds to the first coordinate system, and its origin position value is set in the machine parameters.

Set Workpiece Coordinate Two

Format: G55

Description: Same as above.

Set Workpiece Coordinate Three

Format: G56

Description: Same as above.

Set Workpiece Coordinate Four

Format: G57

Description: Same as above.

Set Workpiece Coordinate Five

Format: G58

Description: Same as above.

Set Workpiece Coordinate Six

Format: G59

Description: Same as above.

Exact Path Mode

Format: G60

Description: In the actual machining process, when several actions are connected together, using exact path programming will introduce a buffering process (i.e., deceleration) before proceeding to the next segment of machining.

Continuous Path Mode

Format: G64

Description: Relative to G60, mainly used for rough machining.

Return to Reference Point (Machine Zero)

Format: G74 X Z

Description:

  1. No other content should appear in this segment.
  2. The coordinates following G74 will zero X and Z in sequence.
  3. Before using G74, make sure the machine is equipped with a reference point switch.
  4. Single-axis zeroing can also be performed.

Return to Programming Coordinate Zero

Format: G75 X Z

Description: Returns to programming coordinate zero.

Return to Programming Coordinate Starting Point

Format: G76

Description: Returns to the position where the tool started machining.

External (Internal) Circle Fixed Cycle

Format: G81__X(U)__Z(W)__R__I__K__F__

Description:

  1. X, Z are the endpoint coordinates, U, W are the incremental values relative to the current point.
  2. R is the diameter of the starting cross-section to be machined.
  3. I is the roughing feed, K is the finishing feed. Both I and K are signed numbers, and their signs should be the same. The sign convention is as follows: cutting from the outside towards the center axis (external turning) is “-“, and the opposite is “+”.
  4. Different X, Z, R determine different external circle switches, such as: with or without taper, forward taper or reverse taper, left cutting or right cutting, etc.
  5. F is the cutting speed (mm/min).
  6. After machining, the tool stops at the endpoint.

Example: G81 X40 Z 100 R15 I-3 K-1 F100

Machining Process:

  1. G01 feeds in 2 times I (the first cut is I, the last cut is I+K for finishing), for depth cutting.
  2. G01 two-axis interpolation, cutting to the endpoint cross-section, stop if machining is complete.
  3. G01 retracts the tool I to a safe position, while performing auxiliary surface smoothing.
  4. G00 rapid feed to a high working surface outside I, reserve I for the next step of cutting, repeat to step 1.

Absolute Value Programming

Format: G90

Description:

  1. When G90 is programmed, all subsequent coordinates are based on the programming zero point.
  2. After the system is powered on, the machine is in the G state.

Example Code:

N0010 G90 G92 x20 z90

N0020 G01X40 Z80 F100

N0030 G03X60 Z50 I0 K-10

N0040 M02

Incremental Programming

Format: G91

Description: When G91 is programmed, all subsequent coordinates are calculated based on the previous coordinate position as the starting point for the programming value. In the next segment of the coordinate system, the previous point is always used as the starting point for programming.

Example Code:

N0010 G91 G92 X20 Z85

N0020 G01X20 Z-10 F100

N0030 Z-20

N0040 X20 Z-15

N0050 M02

Set Workpiece Coordinate System

Format: G92 X__ Z__

Description:

  1. G92 only changes the current coordinate values displayed by the system and does not move the coordinate axis, achieving the purpose of setting the coordinate origin.
  2. The effect of G92 is to change the displayed tool tip coordinates to the set values.
  3. The X and Z following G92 can be programmed separately or together.

Feed Rate, Feed Per Minute

Description: This is the machine’s default state when powered on.

Subroutine Call

Format: G20 L__ N__

Description:

  1. The number following L is the name of the subroutine to be called, following N, but N should not be entered. Only numbers 1~99999999 are allowed after N.
  2. No content other than the above description should appear in this segment.

Subroutine End and Return

Format: G24

Description:

  1. G24 indicates the end of the subroutine and returns to the next segment of the program that called this subroutine.
  2. G24 and G20 appear in pairs.
  3. No other instructions are allowed to appear in the segment with G24.

III. G-Code Programming Examples

Example: Parameter Passing in Subroutine Calls

Program Name: P10

Code:

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

If you want to call multiple times, 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—Thread Machining Cycle

Format: G331 X__ Z__I__K__R__p__

Description:

  1. X indicates the diameter change; X=0 is for straight threads.
  2. Z is the thread length; both absolute and relative programming are acceptable.
  3. I is the tail-off length in the X direction after the thread is cut; it can be a positive or negative value.
  4. R is the diameter difference between the outer and root diameter of the thread; it is a positive value.
  5. K is the thread pitch in mm (KMM).
  6. p is the number of passes for thread machining, i.e., how many cuts to complete the thread.

Tips:

  1. The depth of each cut is R÷p, rounded to the nearest integer. The last cut is not made to smooth the thread surface.
  2. The tail-off for internal threads is determined by the positive or negative direction along X, which determines the sign of the value I.
  3. The starting position of the thread machining cycle is to align the tool tip with the outer circle of the thread.

Example Code:

M3

G4 f2

G0 x30 z0

G331 z-50 x0 i10 k2 r1.5 p5

G0 z0

M05

IV. Additional Notes and Precautions

1. G00 and G01

  • G00: The motion trajectory can be either a straight line or a polyline. This command is only used for point positioning and not for cutting.
  • G01: Moves in a straight line to the target point specified by the command at a specified feed rate. Generally used for cutting operations.

2. G02 and G03

  • G02: Clockwise circular interpolation
  • G03: Counterclockwise circular interpolation

3. G04 (Delay or Pause Command)

  • Generally used for switching between forward and reverse, machining blind holes, stepped holes, and turning grooves.

4. G17, G18, G19 (Plane Selection Commands)

  • G17: X-Y plane, can be omitted, or can be a plane parallel to the X-Y plane.
  • G18: X-Z plane or a plane parallel to it. In CNC lathes, only the X-Z plane exists, so no need to specify.
  • G19: Y-Z plane or a plane parallel to it.

5. G27, G28, G29 (Reference Point Commands)

  • G27: Return to the reference point, check and confirm the reference point position.
  • G28: Automatically return to the reference point (via an intermediate point).
  • G29: Return from the reference point, used in conjunction with G28.

6. G40, G41, G42 (Radius Compensation)

  • G40: Cancel tool radius compensation

7. G43, G44, G49 (Length Compensation)

  • G43: Positive length compensation
  • G44: Negative length compensation
  • G49: Cancel tool length compensation

8. G32, G92, G76

  • G32: Thread cutting
  • G92: Fixed cycle for thread cutting
  • G76: Compound cycle for thread cutting

9. Turning Operations: G70, G71, G72, G73

  • G71: Axial rough turning compound cycle
  • G70: Finish turning compound cycle
  • G72: Face turning, radial rough turning cycle
  • G73: Pattern rough turning cycle

10. Milling Machines and Machining Centers

  • G73: High-speed deep hole peck drilling
  • G83: Deep hole peck drilling
  • G81: Drilling cycle
  • G82: Deep hole drilling cycle
  • G74: Left-hand thread cutting
  • G84: Right-hand thread cutting
  • G76: Fine boring cycle
  • G86: Boring cycle
  • G85: Reaming
  • G80: Cancel cycle command

11. Programming Modes: G90, G91

  • G90: Absolute coordinate programming
  • G91: Incremental coordinate programming

12. Spindle Setting Commands

  • G50: Set the maximum spindle speed
  • G96: Constant surface speed control
  • G97: Spindle speed control (Cancel constant surface speed control)
  • G99: Return to R point (Intermediate hole)
  • G98: Return to reference point (Final hole)

13. Spindle Rotation and Stop Commands: M03, M04, M05

  • M03: Spindle forward
  • M04: Spindle reverse
  • M05: Spindle stop

14. Cutting Fluid Switch: M07, M08, M09

  • M07: Mist coolant on
  • M08: Liquid coolant on
  • M09: Coolant off

15. Motion Stop: M00, M01, M02, M30

  • M00: Program pause
  • M01: Optional stop
  • M02: Machine reset
  • M30: Program end, pointer returns to the beginning

16. M98: Call Subprogram

17. M99: Return to Main Program

Need to buy a machine tool?

You can upload drawings of machined parts. Our experts will help you determine the best machine for your needs.

About WhalesCNC

WhalesCNC is a high-quality CNC machine tool manufacturer located in Xuzhou, Jiangsu, China. It has more than 20 years of manufacturing experience and is committed to comprehensive solutions to improve cutting efficiency.

OUR PRODUCTS

VMC1160

Machining Centers

Vertical

Machining Centers

Gantry

Turning Center

Horizontal

Machining Centers

Horizontal

Contact US