0
0
Ev-technologyHow-ToBeginner · 4 min read

G Code for Milling Pocket: Syntax and Example

To mill a pocket using G-code, you typically use G0 for rapid moves, G1 for linear cutting moves, and G2/G3 for circular interpolation to create the pocket shape. The program moves the tool in layers to clear the material inside the pocket area.
📐

Syntax

The basic G code commands for milling a pocket include:

  • G0 X... Y... Z...: Rapid move to position.
  • G1 X... Y... Z... F...: Linear cutting move with feed rate.
  • G2/G3 X... Y... I... J... F...: Circular interpolation clockwise (G2) or counterclockwise (G3) with center offsets.
  • M3 and M5: Spindle on and off.

These commands are combined to move the tool around the pocket area, removing material layer by layer.

gcode
G0 Z5.0
M3 S1000
G0 X10 Y10
G1 Z-2.0 F100
G1 X50 Y10 F200
G1 X50 Y50
G1 X10 Y50
G1 X10 Y10
G0 Z5.0
M5
💻

Example

This example mills a simple rectangular pocket 40mm by 40mm, 2mm deep, starting at X10 Y10. It uses linear moves to cut the pocket perimeter and retracts the tool safely.

gcode
G21 ; Set units to millimeters
G90 ; Absolute positioning
G0 Z5.0 ; Raise tool to safe height
M3 S1200 ; Start spindle at 1200 RPM
G0 X10 Y10 ; Move to pocket start
G1 Z-2.0 F100 ; Lower tool into material
G1 X50 Y10 F300 ; Cut bottom edge
G1 X50 Y50 ; Cut right edge
G1 X10 Y50 ; Cut top edge
G1 X10 Y10 ; Cut left edge
G0 Z5.0 ; Retract tool
M5 ; Stop spindle
M30 ; End program
⚠️

Common Pitfalls

Common mistakes when programming pocket milling include:

  • Not retracting the tool before rapid moves, causing crashes.
  • Using incorrect feed rates that are too fast or too slow.
  • Forgetting to turn the spindle on (M3) or off (M5).
  • Not using incremental offsets correctly for circular pockets.

Always verify tool paths with simulation before running on the machine.

gcode
Wrong:
G1 X10 Y10 Z-2.0 F300 ; Cutting move without spindle on

Right:
M3 S1200 ; Spindle on
G0 Z5.0 ; Safe height
G0 X10 Y10
G1 Z-2.0 F100 ; Cutting move
📊

Quick Reference

CommandDescription
G0Rapid positioning move
G1Linear cutting move with feed rate
G2Clockwise circular interpolation
G3Counterclockwise circular interpolation
M3Spindle on
M5Spindle off
FFeed rate for cutting moves
ZVertical position of the tool

Key Takeaways

Use G0 for safe rapid moves and G1 for cutting moves with feed rates.
Turn spindle on with M3 before cutting and off with M5 after.
Move the tool in layers to mill the pocket depth safely.
Verify tool paths with simulation to avoid crashes.
Use G2/G3 for circular pockets with correct center offsets.