0
0
Ev-technologyHow-ToBeginner · 3 min read

G Code for Milling a Straight Line: Syntax and Example

To mill a straight line in G code, use G01 for linear interpolation with specified coordinates. For example, G01 X10 Y0 F100 moves the tool in a straight line to X=10, Y=0 at feed rate 100.
📐

Syntax

The basic G code command to mill a straight line is G01, which tells the machine to move in a straight line at a controlled feed rate.

  • G01: Linear interpolation (straight line move)
  • X, Y, Z: Target coordinates for the move
  • F: Feed rate (speed of the tool movement)

Example: G01 X20 Y10 F150 moves the tool straight to X=20, Y=10 at feed rate 150.

gcode
G01 X10 Y0 F100
💻

Example

This example shows a simple G code program that mills a straight line from the current position to X=50, Y=0 at a feed rate of 200 mm/min.

gcode
G21 ; Set units to millimeters
G90 ; Use absolute positioning
G00 X0 Y0 ; Rapid move to start point
G01 X50 Y0 F200 ; Mill straight line to X=50, Y=0
M30 ; End of program
Output
The CNC machine moves rapidly to X0 Y0, then mills a straight line to X50 Y0 at feed rate 200 mm/min, then stops.
⚠️

Common Pitfalls

Common mistakes when milling a straight line include:

  • Forgetting to set the feed rate (F), which can cause the machine to move too fast or not move at all.
  • Using G00 instead of G01 for cutting moves; G00 is rapid positioning and does not cut.
  • Not setting the correct coordinate mode (G90 for absolute or G91 for incremental), leading to unexpected tool paths.

Wrong: G00 X50 Y0 (moves fast, no cutting)
Right: G01 X50 Y0 F150 (cuts a straight line)

gcode
G00 X50 Y0 ; Incorrect for cutting
G01 X50 Y0 F150 ; Correct for cutting
📊

Quick Reference

CommandDescription
G00Rapid move (no cutting)
G01Linear interpolation (cutting straight line)
X, Y, ZTarget coordinates
FFeed rate (speed)
G90Absolute positioning mode
G91Incremental positioning mode

Key Takeaways

Use G01 with X, Y coordinates and feed rate F to mill a straight line.
Always set the correct positioning mode with G90 or G91 before moves.
Never use G00 for cutting moves; it is for rapid positioning only.
Specify feed rate F to control the cutting speed.
Start with a safe rapid move (G00) to the start point before cutting.