MEG 403 · Computer-Aided Design & Manufacturing
Our notes
2 min readProgram structure
A part program is a list of blocks (lines); each block has words made of a letter address and a number:
| Address | Meaning |
|---|---|
| N | block (sequence) number |
| G | preparatory function (type of move or mode) |
| X, Y, Z | coordinates |
| I, J, K or R | arc centre offsets or radius |
| F | feed rate |
| S | spindle speed |
| T | tool number |
| M | miscellaneous function (spindle, coolant, program end) |
Common G codes
| Code | Meaning |
|---|---|
| G00 | rapid positioning |
| G01 | linear interpolation (cutting) |
| G02 / G03 | circular interpolation clockwise / anticlockwise |
| G17 | XY plane |
| G20 / G21 | inch / mm units |
| G40 / G41 / G42 | cutter compensation off / left / right |
| G43 | tool length compensation |
| G54 | work coordinate system (work zero) |
| G90 / G91 | absolute / incremental coordinates |
| G81-G89 | canned drilling and boring cycles |
Common M codes
M03 spindle on clockwise; M04 anticlockwise; M05 spindle stop; M06 tool change; M08 coolant on; M09 coolant off; M30 program end and rewind.
Absolute and incremental
- G90 (absolute): every coordinate is measured from the work zero.
- G91 (incremental): every coordinate is the distance from the current position.
Moving from (10, 10) to (40, 30): absolute X40 Y30; incremental X30 Y20.
Worked example: profile with a rounded corner
Mill around a 50 × 30 mm profile with work zero at the lower left corner; the top right corner is an arc of radius 10 mm. (Tool centre path shown without cutter compensation, depth 2 mm.)
%
N10 G21 G90 G17 G54
N20 T01 M06
N30 S800 M03
N40 G00 X0 Y0 Z5
N50 G01 Z-2 F50
N60 G01 X50 Y0 F150
N70 G01 X50 Y20
N80 G03 X40 Y30 R10
N90 G01 X0 Y30
N100 G01 X0 Y0
N110 G00 Z5
N120 M05
N130 M30
%
- N80 is anticlockwise (G03) from (50, 20) to (40, 30) about the centre (40, 20).
- Path length: 50 + 20 + 15.71 (quarter circle) + 40 + 30 = 155.7 mm; at 150 mm/min the cut takes about 1.04 min.
In practice, use G41/G42 cutter compensation (or offset the path by the tool radius) so the finished edge is where the drawing says.
Canned cycle example
Drill four holes 10 mm deep with G81:
G81 X10 Y10 Z-10 R2 F80, then just X40 Y10, X40 Y20, X10 Y20 on the next lines, and G80 to cancel. Each line drills one hole using the same depth and feed.
CAM-generated programs
For complex parts, CAM software creates tool paths from the 3D model and a post-processor writes G-code for the particular machine. Always simulate (verify) the program and do a dry run above the part before cutting.
Exams usually ask
- Explain the structure of a part program and common G and M codes.
- Write a program for a given profile or hole pattern.
- Distinguish absolute and incremental programming.
Common mistake
Getting G02 and G03 the wrong way round. Look down the spindle onto the XY plane: G02 is clockwise, G03 anticlockwise.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Computer numerical control
(opens en.wikipedia.org in a new tab)
Wikipedia, Computer numerical control, CC BY-SA 4.0 · licence
-
G-code
(opens en.wikipedia.org in a new tab)
Wikipedia, G-code, CC BY-SA 4.0 · licence
-
NPTEL: Automation in Manufacturing (IIT Guwahati, whole course)
Design of automated systems, sensors, drives and mechanisms, hydraulics and pneumatics, CNC technology. Video lectures, many hours in all: watch on Wi-Fi where you can.
(opens nptel.ac.in in a new tab)
NPTEL, NPTEL: Automation in Manufacturing (IIT Guwahati, whole course), CC BY-NC-SA 4.0 · licence
Watch
-
Best pick Basic Movements with G-Code
9 min · ≈ 41 MB · about ₦23
(opens youtube.com in a new tab)
-
G & M Code - Titan Teaches Manual Programming on a CNC Machine.
27 min · ≈ 122 MB · about ₦69
(opens youtube.com in a new tab)
-
CNC G Code Programming: A CNC Mill Tutorial explaining G Codes
25 min · ≈ 113 MB · about ₦63
(opens youtube.com in a new tab)
-
Basic G-Code programming for CNC routers
24 min · ≈ 108 MB · about ₦61
(opens youtube.com in a new tab)
-
What Is G Code and M Code? | CNC Programming Basics for Engineers
4 min · ≈ 18 MB · about ₦10
(opens youtube.com in a new tab)
-
CAM Lecture 1 Need for Numerical Control
1 h 1 min · ≈ 275 MB · about ₦154
(opens youtube.com in a new tab)
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.