Simple Shaft Turning on CNC Lathe: Full G/M-Code Example

Simple Shaft Turning on CNC Lathe: Full G/M-Code Example

For this example, we’ll program a basic stepped shaft on a CNC lathe using Fanuc-style G-code. Assume the following specifications:

  • Stock: 2-inch diameter bar, protruding 5 inches from the chuck.
  • Final part: Face the end, turn a 1.5-inch diameter section for 2 inches length, then step down to a 1-inch diameter section for 2 inches length.
  • Tools: T0101 for roughing (e.g., carbide insert tool), T0202 for finishing.
  • Units: Inches (G20).
  • Spindle: Constant surface speed (G96).
  • Feed: Per revolution (G99).
  • No threading or other advanced features—just basic facing and turning.

This is a complete, self-contained program. Note that actual code may vary slightly by machine control (e.g., Fanuc, Haas), so test in simulation first. The roughing uses G71 (stock removal cycle), and finishing uses G70 (finishing cycle). The contour (N100 to N200) describes the finished profile.

O1234 (STEPPED SHAFT TURNING EXAMPLE)
G20 G99 (INCH MODE, FEED PER REV)
G50 S2500 (MAX SPINDLE RPM)
G28 U0 W0 (HOME TOOL)

(ROUGHING TOOL)
T0101 (TOOL 1, OFFSET 1)
G96 S400 M03 (CONSTANT SFM 400, SPINDLE CW)
G00 X2.2 Z0.2 M08 (RAPID TO START POSITION, COOLANT ON)

(FACE THE END)
G00 Z0.1
G01 X-0.06 F0.01 (FACE CUT)
G00 X2.2 Z0.2

(ROUGH TURNING CYCLE)
G71 U0.05 R0.05 (DEPTH OF CUT 0.05 IN, RETRACT 0.05 IN)
G71 P100 Q200 U0.04 W0.005 F0.012 (X ALLOWANCE 0.04 IN, Z ALLOWANCE 0.005 IN, FEED 0.012 IPR)
N100 G00 X1.0 (START OF FINISH CONTOUR - SMALL DIA)
G01 Z0.0 (FACE POSITION)
X1.5 Z-2.0 (TURN TO 1.5 DIA OVER 2 IN LENGTH - NOTE: TAPER IF NEEDED, BUT STRAIGHT HERE)
X1.0 Z-4.0 (STEP TO 1.0 DIA OVER NEXT 2 IN)
N200 G00 X2.2 (END OF CONTOUR - CLEAR)

G00 X2.2 Z0.2 (RETRACT)
G28 U0 W0 (HOME TOOL)

(FINISHING TOOL)
T0202 (TOOL 2, OFFSET 2)
G96 S500 M03 (CONSTANT SFM 500, SPINDLE CW)
G00 X2.2 Z0.2 M08 (RAPID TO START, COOLANT ON)

(FINISH PASS)
G70 P100 Q200 F0.005 (FINISH USING SAME CONTOUR, FEED 0.005 IPR)

G00 X2.2 Z0.2 M09 (RETRACT, COOLANT OFF)
M05 (SPINDLE STOP)
G28 U0 W0 (HOME TOOL)
M30 (PROGRAM END)
%

Explanation of Key Sections

  • Setup (O1234 to G28): Program number, units, max RPM, and home the tool for safety.
  • Roughing Tool Setup: Select tool, start spindle, position, and turn on coolant.
  • Facing: A simple linear cut to square the end face.
  • G71 Roughing Cycle: Removes bulk material in steps, following the defined contour (N100-N200). The first G71 line sets depth and retract; the second references the contour blocks, allowances, and feed.
  • Contour Definition (N100-N200): Describes the finished shape. Starts at the smallest diameter, moves along Z, and steps up in X for the larger section. Ends by clearing in X.
  • Finishing: Switch tools, higher speed for better surface, then G70 to follow the same contour precisely at a finer feed.
  • Shutdown: Retract, stop spindle and coolant, home, and end program.

This program assumes a standard 2-axis CNC lathe with no tailstock. Adjust feeds, speeds, and depths based on material (e.g., aluminum vs. steel) and tool specs to avoid issues like chatter or breakage. For more complex shafts (e.g., with grooves or threads), additional cycles like G76 could be added. Always dry-run or simulate before running on the machine.

Similar Posts

Leave a Reply

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