Skip to main content

Translate- हिंदी, मराठी, English

ISO G-Codes for CNC Milling & Canned cycles

 

CNC (Computer Numerical Control) milling machines are controlled by a specialized programming language commonly known as G-code, which adheres to the ISO 6983 standard. This language comprises G-codes (Geometric codes) that dictate tool motion and M-codes (Miscellaneous codes) that manage machine functions. Additionally, "canned cycles" provide simplified commands for common, repetitive machining operations.

ISO G-Codes for CNC Milling

G-codes are preparatory functions that instruct the CNC machine on how to move the tool. They define the geometry of the toolpath.

Common G-Codes for Milling:

  • G00 (Rapid Traverse): Moves the tool at the maximum possible speed to a specified position. Used for non-cutting movements to quickly reposition the tool.
    • G00 X100 Y50 Z10 - Rapidly moves the tool to X100, Y50, and Z10.
  • G01 (Linear Interpolation): Moves the tool in a straight line at a programmed feed rate. Used for cutting operations.
    • G01 X20 Y30 F100 - Moves the tool linearly to X20, Y30 at a feed rate of 100 units/minute.
  • G02 (Circular Interpolation, Clockwise - CW): Moves the tool along a circular arc in a clockwise direction at a programmed feed rate. Requires specifying the end point (X, Y, Z) and either the center of the arc (I, J, K) or the radius (R).
    • G02 X50 Y50 I20 J0 F50 - Moves clockwise to X50, Y50 with the arc center at I20 (relative to current X) and J0 (relative to current Y).
  • G03 (Circular Interpolation, Counter-Clockwise - CCW): Moves the tool along a circular arc in a counter-clockwise direction at a programmed feed rate. Similar parameters to G02.
    • G03 X50 Y50 R25 F50 - Moves counter-clockwise to X50, Y50 with a radius of 25.
  • G04 (Dwell): Causes the machine to pause for a specified duration (in seconds or milliseconds). Used for operations like clearing chips, allowing the spindle to reach speed, or ensuring proper depth.
    • G04 P1.5 - Dwells for 1.5 seconds.
  • G17 / G18 / G19 (Plane Selection): Defines the active working plane for circular interpolation, cutter compensation, and other operations.
    • G17 - XY plane (default for milling)
    • G18 - XZ plane
    • G19 - YZ plane
  • G20 / G21 (Units Selection):
    • G20 - Imperial units (inches)
    • G21 - Metric units (millimeters)
  • G40 / G41 / G42 (Cutter Compensation): Used to compensate for the radius of the cutting tool, allowing the programmer to use part geometry directly.
    • G40 - Cancel cutter compensation.
    • G41 - Cutter compensation left (tool moves to the left of the programmed path).
    • G42 - Cutter compensation right (tool moves to the right of the programmed path).
  • G43 / G44 / G49 (Tool Length Compensation): Used to compensate for the length of the tool.
    • G43 - Tool length compensation positive (applies positive offset, usually to Z).
    • G44 - Tool length compensation negative (less common).
    • G49 - Cancel tool length compensation.
  • G54 - G59 (Work Coordinate System Selection): Selects one of several predefined work coordinate systems (WCS) to establish the workpiece zero point.
    • G54 - Activates WCS 1.
  • G80 (Canned Cycle Cancel): Cancels any active canned cycle. Essential to use after completing a series of canned cycle operations.
    • G80 - Cancels the current canned cycle.
  • G90 / G91 (Absolute / Incremental Programming):
    • G90 - Absolute programming (coordinates are relative to the program zero).
    • G91 - Incremental programming (coordinates are relative to the current tool position).
  • G98 / G99 (Return to Initial / R-Plane): Controls the Z-axis retract behavior within canned cycles.
    • G98 - Returns to the initial Z position (where the tool started before the canned cycle).
    • G99 - Returns to the R-plane (retract plane) after each hole.

ISO M-Codes for CNC Milling

M-codes are miscellaneous functions that control various machine operations that are not directly related to tool movement. They manage auxiliary functions like spindle control, coolant, and program flow.

Common M-Codes for Milling:

  • M00 (Program Stop): Halts the program until the operator manually restarts it. Used for inspection or manual intervention.
  • M01 (Optional Program Stop): Similar to M00, but only executes if the "Optional Stop" button on the machine control panel is enabled.
  • M02 (End of Program): Stops the program and resets the control, but does not reset other functions like M30.
  • M03 (Spindle On, Clockwise - CW): Starts the spindle rotating in a clockwise direction. Usually accompanied by an S word to set the spindle speed (e.g., S2500 M03).
  • M04 (Spindle On, Counter-Clockwise - CCW): Starts the spindle rotating in a counter-clockwise direction. Used for left-hand threading or special milling operations.
  • M05 (Spindle Stop): Stops the spindle rotation.
  • M06 (Tool Change): Initiates a tool change. The T word specifies the new tool number (e.g., T02 M06).
  • M07 (Mist Coolant On): Activates mist coolant.
  • M08 (Flood Coolant On): Activates flood coolant.
  • M09 (Coolant Off): Turns off all coolant.
  • M19 (Spindle Orient): Orients the spindle to a specific angular position, often used before a tool change or fine boring.
  • M29 (Rigid Tapping Mode): Prepares the machine for rigid tapping, where the spindle rotation and Z-axis feed are synchronized precisely. Required before G84 (tapping cycle) for rigid tapping.
  • M30 (Program End and Reset): Stops the program, resets the control to the beginning of the program, and often resets other machine functions (e.g., coolant off, spindle off).
  • M98 (Subprogram Call): Calls a subprogram (or subroutine) to be executed.
  • M99 (End of Subprogram / Loop Program): Returns control from a subprogram to the main program or loops the main program if used at the end of the main program.

Canned Cycles for Drilling, Peck Drilling, Reaming, Tapping, and Finish Boring

Canned cycles are pre-programmed sequences of machine movements that simplify programming for repetitive operations like drilling, boring, and tapping. Instead of writing multiple lines of G00 and G01 commands for each hole, a single canned cycle command can define the entire operation.

General Canned Cycle Format (common parameters):

Gxx X... Y... Z... R... F... Q... P... L...

  • Gxx: The specific G-code for the canned cycle (e.g., G81, G83, G84, G85, G76).
  • X, Y: The X and Y coordinates of the hole location. If omitted, the last commanded X/Y position is used.
  • Z: The final depth of the hole, measured from the programmed Z-zero or the R-plane depending on the control and setup.
  • R: The R-plane (Retract Plane) or initial point plane. This is the Z-level from which the tool starts feeding and to which it retracts.
  • F: Feed rate for the cutting motion.
  • Q: (Specific to peck drilling and fine boring) The depth of each peck or the amount of tool offset.
  • P: (Specific to boring/tapping) Dwell time at the bottom of the hole (in milliseconds or seconds, depending on control).
  • L: (Optional) Number of repetitions if drilling multiple identical holes in a pattern (less common in milling where hole locations are usually listed sequentially).

1. Drilling (G81 - Simple Drilling Cycle)

The G81 cycle is used for simple through-holes or spot drilling. The tool rapidly approaches the R-plane, then feeds to the programmed Z-depth, and finally rapidly retracts to the R-plane or initial plane (based on G99/G98).

Sequence:

  1. Rapid traverse to the X, Y hole position.
  2. Rapid traverse to the R-plane.
  3. Feed to the Z-depth.
  4. Rapid retract to the R-plane (G99) or initial Z-plane (G98).

Example: G90 G54 G00 X10 Y10 (Move to first hole in absolute coordinates) G43 H01 Z5.0 M08 (Apply tool length offset, move to Z5, turn on coolant) G99 G81 X10 Y10 Z-15.0 R2.0 F100 (Drill first hole: X10, Y10, depth -15.0, R-plane at Z2.0, feed 100. Return to R-plane after each hole) X20 Y10 (Drill second hole at X20, Y10 using same parameters) X30 Y20 (Drill third hole at X30, Y20) G80 (Cancel canned cycle) G00 Z100.0 M09 (Rapid retract to safe Z, turn off coolant)

2. Peck Drilling (G83 - Deep Hole Peck Drilling Cycle)

The G83 cycle is used for deep holes to break chips and clear them from the hole, preventing chip packing and improving tool life. The tool feeds in small increments (pecks), retracting fully (or partially) after each peck.

Sequence:

  1. Rapid traverse to the X, Y hole position.
  2. Rapid traverse to the R-plane.
  3. Feed down by the first peck depth (Q).
  4. Rapid retract to the R-plane (or a small clearance amount above the current peck depth).
  5. Rapid traverse back to the current peck depth (minus a small clearance).
  6. Feed down by the next peck depth (Q).
  7. Repeat steps 4-6 until the final Z-depth is reached.
  8. Rapid retract to the R-plane (G99) or initial Z-plane (G98).

Example: G90 G54 G00 X10 Y10 G43 H02 Z5.0 M08 G99 G83 X10 Y10 Z-50.0 R2.0 Q5.0 F80 (Peck drill at X10, Y10, depth -50.0, R-plane at Z2.0, peck depth 5.0mm, feed 80) X20 Y10 G80 G00 Z100.0 M09

(Note: Some controls have G73 for chip breaking peck drilling, which performs partial retracts, while G83 performs full retracts. Always check the machine's manual.)

3. Reaming (G85 - Reaming Cycle)

The G85 cycle is designed for reaming, where a reamer tool is fed into a pre-drilled hole to achieve a precise diameter and smooth finish. The tool feeds into the hole and feeds back out at the same programmed feed rate, preventing damage to the reamed surface.

Sequence:

  1. Rapid traverse to the X, Y hole position.
  2. Rapid traverse to the R-plane.
  3. Feed to the Z-depth.
  4. Feed retract to the R-plane (G99) or initial Z-plane (G98).

Example: G90 G54 G00 X10 Y10 G43 H03 Z5.0 M08 G99 G85 X10 Y10 Z-15.0 R2.0 F50 (Ream at X10, Y10, depth -15.0, R-plane at Z2.0, feed 50. Tool feeds in and out) X20 Y10 G80 G00 Z100.0 M09

4. Tapping (G84 - Right-Hand Tapping Cycle)

The G84 cycle is used for tapping threads into pre-drilled holes. For rigid tapping, M29 must be active to synchronize the spindle rotation and Z-axis feed precisely with the thread pitch.

Sequence:

  1. Rapid traverse to the X, Y hole position.
  2. Rapid traverse to the R-plane.
  3. Spindle rotates CW (M03 implied or commanded before).
  4. Feed to the Z-depth (feed rate is the thread pitch in units/revolution, or calculated based on RPM and pitch).
  5. At the Z-depth, the spindle reverses rotation (M04 implied).
  6. Feed retracts to the R-plane (G99) or initial Z-plane (G98) at the same feed rate.
  7. Spindle resumes CW rotation (M03 implied).

Parameters:

  • F: Feed rate, which must be the thread pitch (e.g., for an M8x1.25 thread, F1.25).
  • S: Spindle speed.

Example: G90 G54 G00 X10 Y10 G43 H04 Z5.0 M08 S500 M03 (Set spindle speed to 500 RPM, CW) M29 S500 (Activate rigid tapping mode at 500 RPM) G99 G84 X10 Y10 Z-15.0 R2.0 F1.25 (Tap at X10, Y10, depth -15.0, R-plane at Z2.0, thread pitch 1.25mm) X20 Y10 G80 G00 Z100.0 M09 M05 (Spindle stop)

(Note: For left-hand tapping, G74 is often used, or G84 can be used with M04 for initial spindle direction, depending on control. Check specific machine manual.)

5. Finish Boring (G76 - Fine Boring Cycle / G86 - Boring Cycle)

There are several boring cycles, with G76 being a popular "fine boring" or "precision boring" cycle and G86 being a "bore and stop" cycle.

G76 (Fine Boring Cycle - with oriented spindle stop and tool shift): This cycle provides high precision by retracting the boring bar in a specific direction away from the machined surface after reaching the bottom of the hole, preventing tool marks on the bore wall during retraction. The spindle must have orientation capability (M19).

Sequence:

  1. Rapid traverse to the X, Y hole position.
  2. Rapid traverse to the R-plane.
  3. Feed to the Z-depth.
  4. At Z-depth, the spindle stops and orientates to a specific angular position (e.g., facing away from the cut).
  5. The tool shifts horizontally by a small amount (Q) away from the bore surface.
  6. Rapid retract to the R-plane (G99) or initial Z-plane (G98).
  7. The tool shifts back to its original position.
  8. Spindle restarts.

Parameters:

  • P: Dwell time at the bottom (optional).
  • Q: Amount of tool shift (in X or Y) to clear the bore wall (must be a positive value).
  • I, J: (Some controls) Used for offset amounts in X and Y.

Example: G90 G54 G00 X10 Y10 G43 H05 Z5.0 M08 S800 M03 G99 G76 X10 Y10 Z-15.0 R2.0 Q0.02 F75 (Fine bore at X10, Y10, depth -15.0, R-plane at Z2.0, tool shifts 0.02mm, feed 75) X20 Y10 G80 G00 Z100.0 M09 M05

G86 (Boring Cycle - Bore and Stop): The G86 cycle feeds into the hole, stops the spindle at the bottom, and then rapidly retracts. This cycle is simpler than G76 and is suitable where spindle orientation and tool relief during retraction are less critical or not available.

Sequence:

  1. Rapid traverse to the X, Y hole position.
  2. Rapid traverse to the R-plane.
  3. Feed to the Z-depth.
  4. Spindle stops at Z-depth.
  5. Rapid retract to the R-plane (G99) or initial Z-plane (G98).
  6. Spindle restarts.

Parameters:

  • P: Dwell time at the bottom (optional).

Example: G90 G54 G00 X10 Y10 G43 H06 Z5.0 M08 S800 M03 G99 G86 X10 Y10 Z-15.0 R2.0 P1000 F60 (Bore at X10, Y10, depth -15.0, R-plane at Z2.0, dwell for 1 second, feed 60) X20 Y10 G80 G00 Z100.0 M09 M05

Important Considerations for Canned Cycles:

  • Modal vs. Non-Modal: Most G-codes, including canned cycles, are modal. Once activated, they remain active until cancelled (G80) or superseded by another G-code from the same group.
  • Parameter Variations: The exact meaning and availability of parameters (e.g., Q, P) can vary slightly between CNC machine manufacturers (e.g., Fanuc, Haas, Siemens). Always refer to the specific machine's programming manual.
  • Safety: Always ensure adequate clearance for tools and workholding when using canned cycles, especially with rapid retracts.
  • Initial and R-Planes: Proper definition of the initial Z-plane and the R-plane is crucial for safe and efficient operation. The R-plane is typically a safe distance above the workpiece where the cutting feed begins.

Comments