Mastering G18: XZ Plane Selection for CNC Turning and Milling
In CNC machining, the G17
, G18
, and G19
G-codes are fundamental commands used to define the active working plane. This article focuses on the G18
G-code, which selects the XZ plane. While G17
(XY plane) is the default for most milling operations, G18
(XZ plane) is the standard and essential plane selection for CNC turning operations. We’ll also explore its less common, but sometimes necessary, use on machining centers.
This article will cover:
- The concept of plane selection.
- The specific function of
G18
on CNC lathes (its primary use). - The use of
G18
on CNC machining centers (mills). - How
G18
affects circular interpolation (G02
/G03
). G18
and cutter compensation/tool nose radius compensation (G41
/G42
).G18
and canned cycles.- Control-specific considerations (Fanuc, Siemens, Haas, Mazak, Mitsubishi).
- Troubleshooting tips.
- The role of CAM software.
Crucial Note: Always consult the programming manuals for your specific CNC control system and machine tool. While G17
, G18
, and G19
are generally standardized, there might be subtle variations.
1. Plane Selection: Defining the 2D Workspace
CNC machines operate in 3D space, but many operations are performed within a 2D plane. Plane selection G-codes tell the control which two axes define this plane. This is critical for:
- Circular Interpolation (
G02
/G03
): The control needs to know where to draw the arc. - Canned Cycles (Drilling, Tapping, etc.): These cycles usually operate perpendicular to the selected plane.
- Cutter Compensation (
G41
/G42
): The control needs to know in which plane to offset the toolpath. - Rotary Axes: The correct plane definition is crucial.
2. G17, G18, and G19: The Three Planes
G-Code | Plane | Milling (Typical) | Turning (Typical) | Notes |
---|---|---|---|---|
G17 |
XY | Default, most operations | Face milling (with live tooling & C-axis) | Most common plane for milling. |
G18 |
XZ | Side milling (tool axis parallel to Y) | Default, standard turning operations | Standard plane for turning. |
G19 |
YZ | Side milling (tool axis parallel to X) | Less common, specialized applications | Less common plane selection. |
3. G18 Syntax
The syntax is very simple:
G18 ; Select the XZ plane
G18
is a modal G-code. It remains active until another plane selection command (G17
or G19
) is programmed.
4. G18 on CNC Lathes: The Standard Turning Plane
On a standard 2-axis CNC lathe:
- X-axis: Controls tool movement across the workpiece diameter (usually programmed in diameter values).
- Z-axis: Controls tool movement along the workpiece length (parallel to the spindle axis).
The XZ plane (G18
) is where all standard turning operations take place:
- Facing: Machining the end of the workpiece.
- Turning (Straight and Tapered): Creating cylindrical or tapered surfaces.
- Grooving: Cutting grooves.
- Threading: Cutting threads.
- Parting Off: Separating the finished part.
It is essential to have G18
active for these operations.
Examples (Lathe - G18 is essential):
- Simple Facing and Turning:
O0001 (Facing and Turning)
G21 G18 G40 G99 ; Metric, XZ plane, cancel comp, feed/rev
T0101 ; Select tool 1, offset 1
G97 S1000 M03 ; Constant RPM, spindle on
G00 X55.0 Z5.0 ; Rapid to start position (slightly above diameter)
G01 Z0.0 F0.1 ; Face the part
G01 X-1.0 F0.05 ; Feed past center (for clean face)
G00 Z5.0 ; Rapid retract in Z
G00 X40.0 ; Rapid to turning start
G01 Z-50.0 F0.15 ; Turn along Z-axis
G00 X100.0 Z100.0 ; Rapid retract
M30 ; Program end
%
- Circular Interpolation (G02/G03) in the XZ Plane:
O0002 (Circular Interpolation - G18)
G21 G18 G40 G99 ; Metric, XZ plane, cancel comp, feed/rev
T0101 ; Select tool 1, offset 1
G97 S1000 M03 ; Constant RPM
G00 X20.0 Z5.0 ; Rapid to start
G01 Z0.0 F0.1 ; Feed to surface
G02 X40.0 Z-20.0 R15.0 F0.08 ; Clockwise arc (R method)
; X40.0 Z-20.0 = Endpoint
; R15.0 = Radius
G01 Z-50.0 ; Continue turning
G00 X100.0 Z100.0; Rapid Retract
M30 ; Program end
%
O0003 (Circular Interpolation - G18 - I and K)
G21 G18 G40 G99 ; Metric, XZ plane, cancel comp, feed/rev
T0101 ; Select tool
G97 S1000 M03
G00 X40.0 Z5.0 ; Rapid to start
G01 Z0.0 F0.1 ; Feed to surface
G03 X20.0 Z-20.0 I-10.0 K-15.0 F0.08 ; Counterclockwise arc (I, K method)
; X20.0 Z-20.0 = Endpoint
; I-10.0 K-15.0 = Center point offsets from *start point*
G01 X10.0 ; Continue
G00 X100 Z100; Rapid Retract
M30;
%
- Tool Nose Radius Compensation (TNRC - G41/G42) in the XZ Plane:
O0004 (TNRC Example - G18)
G21 G18 G40 G99 ; Metric, XZ, cancel comp, feed/rev
T0101 ; Select tool, offset 1 (with radius defined)
G97 S1000 M03
G00 X55.0 Z5.0 ; Rapid to start
G42 ; Activate TNRC (right)
G01 Z0.0 F0.1 ; Face
G01 X40.0 ; Approach
G01 Z-50.0 F0.15 ; Turn
G02 X50.0 Z-60.0 R10.0 ; Circular interpolation
G01 X60.0 ; Continue
G40 ; Cancel TNRC
G00 X100.0 Z100.0 ; Rapid retract
M30;
%
- Canned Cycle Example (G71 Rough Turning - Conceptual):
G18 ; XZ plane (Essential for most turning cycles)
G71 ... ; Rough turning cycle parameters ...
; ...
Most turning canned cycles assume G18
is active.
5. G18 on CNC Machining Centers (Mills)
On machining centers, G17
(XY plane) is the default. G18
(XZ plane) is used for:
- Side Milling: When the tool axis is parallel to the Y-axis. You’re milling a profile or feature that lies in the XZ plane.
- Specialized Canned Cycles: Some canned cycles might require
G18
orG19
(always check your manual).
Examples (Milling - G18):
- Milling a Vertical Slot (XZ Plane):
G17 ; Select XY (Just in case it was changed)
G00 X0 Z0 Y5.0 ; Rapid to start (Y is now the tool axis)
G18 ; Select XZ plane <-- ESSENTIAL
G01 X-0.25 F100 ; Feed to depth (X is depth in this case)
G01 Z-2.0 F50 ; Mill the slot along the Z-axis
G00 X0 ; Rapid retract in X
G17 ; Return to XY plane (IMPORTANT!)
- Circular Interpolation in XZ (G18):
G17
G00 X0 Z0 Y5.0 ; Rapid to start
G18 ; Select XZ plane
G01 X-0.25 F100 ; Feed to depth
G02 X-1.0 Z-1.0 I-0.5 K0.0 F30 ; Clockwise arc in XZ plane
G17; Return to default plane.
6. Live Tooling on Lathes: G17 and G18
G18
(XZ Plane): Used for standard turning operations.G17
(XY Plane): Used for milling operations on the face of the workpiece (using a virtual C-axis).G18
(XZ Plane): Used for milling on the circumference (with cylindrical interpolation, if supported).
Example (Lathe, Live Tooling, Milling on Face - G17):
; Milling a square on the *face* of a turned part.
G28 U0 W0; Home
T0101 M06 ; Select milling tool
G97 S2000 M03 ; Spindle on (constant RPM)
G00 X0 Z5.0 C0 ; Rapid to a safe position, C-axis engaged
G17 ; Select XY plane <-- ESSENTIAL for face milling!
G01 Z-2.0 F100 ; Feed to depth
; ... (Mill the square using X and C axes, with G17 active) ...
G00 Z5.0 ; Rapid retract
G18 ; Return to XZ plane <-- IMPORTANT!
G28 U0 W0 C0; Home
M30 ; Program end
%
7. Interaction with Other G-Codes (Review)
G02
/G03
: Plane selection dictates how these are interpreted.G41
/G42
: Cutter compensation is plane-dependent.- Canned Cycles: Many cycles are plane-dependent.
G90
/G91
: Not directly affected by plane selection, but be aware of the active plane.- G16: Polar Coordinate Selection.
8. Control-Specific Variations
- Fanuc:
G17
,G18
,G19
are standard. - Siemens:
G17
,G18
,G19
are standard. - Haas:
G17
,G18
,G19
are standard. - Mazak:
G17
,G18
, andG19
are standard in EIA/ISO mode. Mazatrol handles planes differently. - Mitsubishi:
G17
,G18
, andG19
are standard. - Other Controls: Always consult your documentation.
9. Troubleshooting
- Incorrect Tool Movements: Wrong plane selected is the most likely cause.
- Circular Interpolation Errors: Double-check the plane selection.
- Cutter Compensation Errors: Ensure correct plane before activating compensation.
10. CAM Software
CAM software handles plane selection automatically. You define the workpiece orientation, and the CAM system selects the appropriate plane (G17
, G18
, or G19
) for each toolpath.
11. Frequently Asked Questions (FAQ)
- Q: What’s the difference between G17, G18, and G19?
- A: They select different working planes:
G17
(XY),G18
(XZ),G19
(YZ).
- A: They select different working planes:
- Q: Which plane should I use for turning?
- A:
G18
(XZ plane) for all standard turning operations. UseG17
(XY plane) only for face milling with live tooling.
- A:
- Q: Which plane is the default on a milling machine?
- A:
G17
(XY plane) is the default on most mills.
- A:
- Q: Can I change planes in the middle of a program?
- A: Yes, but be extremely careful to understand the implications.
- Q: What happens if I select the wrong plane?
- A: Circular interpolation, tool compensation, and canned cycles will not behave as expected, which can cause damage.
12. Conclusion
The G18
command is fundamental to CNC turning, selecting the XZ plane for all standard turning operations. Understanding G18
and its relationship to G17
and G19
, circular interpolation, cutter compensation, and canned cycles, is essential for accurate and efficient CNC lathe programming. On machining centers, G18
is used for less frequent side-milling operations. Always consult your machine’s documentation, use CAM software for complex geometries, and include G18
explicitly in your turning programs for clarity and safety.