Introduction
G-code program structure shows how to organize instructions so a CNC machine can follow them step-by-step to make parts.
O1234 (Program number and start) N10 G21 (Set units to millimeters) N20 G90 (Set absolute positioning) N30 G01 X10 Y10 F100 (Move in a straight line) N40 M30 (End program)
O1000 N10 G90 N20 G00 X0 Y0 N30 M30
O2000 N10 G21 N20 G01 X50 Y50 F200 N30 M30
O3000 N10 (Start of program) N20 G90 (Absolute positioning) N30 G00 X0 Y0 (Rapid move to origin) N40 M30 (Program end)
O1234 (Sample G-code program)
N10 G21 (Set units to millimeters)
N20 G90 (Use absolute positioning)
N30 G00 X0 Y0 (Rapid move to start point)
N40 G01 X50 Y0 F150 (Cut straight line at feed 150)
N50 G01 X50 Y50 (Cut straight line up)
N60 G01 X0 Y50 (Cut straight line left)
N70 G01 X0 Y0 (Cut straight line down to start)
N80 M30 (End of program)O1000 or similar.M30 ends the program, G01 and G90 are motion and positioning commands, not start markers.O1000 -> Option DM30 is used to stop and end a G-code program.G00 moves the tool, G90 sets positioning mode, and O1000 is a program number, not an end command.M30 -> Option CO1000 G90 G00 X10 Y5 G01 X20 Y15 F100 M30
G00 X10 Y5 moves the tool rapidly to X=10, Y=5. Then G01 X20 Y15 F100 moves it linearly to X=20, Y=15.G01 X20 Y15, so the tool ends at X=20, Y=15.O2000 G01 X10 Y10 G90 M30
G90 sets absolute positioning and should be set before any move commands like G01.G01 before setting G90, which can cause unexpected positioning behavior.O3000 and set absolute positioning G90 before moves.G01 X50 Y50 F200 moves the tool at feed rate 200, and M30 ends the program properly.Pass the test and this pattern moves unknown