CNC Program for Rectangular Pocket Milling

Writing a CNC program for a rectangular pocket involves defining the toolpath to clear material from the inside of a boundary to a specific depth.

Below is a standard G-code program using Absolute Programming (G90) and a Linear Interpolation strategy.

For a rectangular pocket, the most efficient method is a Ramp or Spiral entry followed by an Outward Square Spiral (often called “box milling”) to clear the area.

Sample G-Code: 50mm x 30mm Pocket

Pocket Size: 50mm (X) by 30mm (Y)

Depth: 5mm

Tool: 10mm Flat End Mill

Work Offset: G54 (Top-left corner of the workpiece is X0 Y0)

G-Code

(PROGRAM NAME: RECTANGULAR POCKET)
(TOOL: 10MM FLAT END MILL)

G21 (Metric units)
G90 (Absolute positioning)
G17 (XY plane selection)
G80 G40 G49 (Cancel canned cycles, compensation)

T1 M6 (Select Tool 1 and Tool Change)
S2500 M3 (Spindle speed 2500 RPM, CW)
G54 (Work coordinate system)

(POSITIONING)
G0 X25.0 Y15.0 (Move to center of pocket)
G43 H1 Z5.0 M8 (Tool length offset, Rapid to clearance, Coolant ON)

(START POCKETING)
G1 Z-5.0 F150 (Plunge to full depth - or use multiple passes)

(SPIRAL OUTWARD PATH)
G1 X30.0 F500 (Move to first X wall)
G1 Y20.0 (Move to first Y wall)
G1 X20.0
G1 Y10.0
G1 X40.0
G1 Y25.0
G1 X10.0
G1 Y5.0
G1 X45.0
G1 Y30.0
G1 X5.0
G1 Y0.0
G1 X50.0
G1 Y30.0
G1 X0.0
G1 Y0.0

(FINISH PASS AROUND PERIMETER)
G1 X50.0
G1 Y30.0
G1 X0.0
G1 Y0.0

(RETRACT)
G0 Z10.0 M9 (Rapid up, Coolant OFF)
G28 G91 Z0 (Return to home Z)
M30 (Program end)

Stepover: For pocketing, the stepover (distance between passes) should typically be 50% to 70% of the tool diameter to ensure no “islands” of material are left behind.

Cutter Compensation (G41/G42): Use these codes if you need the pocket dimensions to be extremely precise. In the example above, the tool center is programmed manually.

Corner Radius: Remember that a cylindrical tool cannot cut a perfectly sharp 90° internal corner. The corner radius of your pocket will be equal to the radius of your tool.

If you are looking for a different way to program a rectangular pocket, you have several options depending on your machine’s controller and your preferred toolpath strategy. While manual G-code (like the previous example) is universal, modern machines often use Canned Cycles or High-Efficiency Milling (HEM).

The Canned Cycle Method (Controller-Specific)

Many modern controllers have a single line of code that handles the entire pocket—calculating the step-over and depth passes automatically.

  • Haas (G150): This is a general-purpose pocket milling cycle. You define the shape in a sub-program, and G150 handles the “room-clearing” logic.
    • Example: G150 P100 Z-5.0 Q1.0 R2.0 I1.0 K0.1 F500
  • Siemens (POCKET3): A very powerful “conversational” cycle. You fill in parameters for length, width, corner radius, and machining strategy (helical vs. vertical plunge).
  • Fanuc: Does not have a standard “rectangular pocket” G-code (like G12 for circles), so programmers typically stick to M98 sub-programs or custom Macro B scripts.

Different Toolpath Strategies

The way the tool moves inside the pocket significantly impacts tool life and cycle time.

StrategyLogicBest For
Offset / SpiralThe tool starts at the center and “spirals” out toward the walls.General purpose, keeps the tool in constant contact.
Zig-Zag (Raster)The tool moves back and forth like a lawnmower.Clearing large areas quickly; requires a final perimeter pass.
Trochoidal (HEM)The tool moves in small circular “peels.”Hard materials; allows for full-depth cuts with high speed.
Plunge MillingThe tool “drills” out the pocket using only Z-axis moves.Deep pockets where tool vibration (chatter) is a problem.

High-Efficiency Milling (HEM) Example

Instead of taking shallow 1mm depth passes (like the first program), HEM takes the full 5mm depth at once but with a very small horizontal “step-over.” This uses the full length of the flute and prevents the tip of the tool from wearing out prematurely.

G-Code

(HEM STYLE POCKET - FULL DEPTH, SMALL STEP-OVER)
G00 Z2.
G01 Z-5.0 F100         (Plunge to full depth once)
(Small circular 'peeling' moves would go here)
...

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *