CNC programming
A block is interpreted using both its words and the modal state inherited from earlier blocks. Trace the active units, plane, distance mode, work offset, compensation and feed mode before computing a path.
3.1 Axes, origins and distance modes
Use right-handed axes for tool motion relative to the stationary workpiece. is parallel to the principal spindle; positive increases tool–work separation in the usual setup. are rotations about . A moving table may physically move opposite to the programmed relative tool direction.
Machine zero is the machine coordinate reference. A work offset locates the part coordinate origin relative to it. Tool offsets account for tool dimensions. On a lathe, may specify diameter rather than radius; a programmed diameter change is twice the radial slide displacement.
3.2 Word addresses and modal functions
Past papers · ME 2020–2026 (10 papers): 1 question, 1 mark
A word consists of a letter and value. A block can contain several compatible words. Modal functions remain active until replaced/cancelled; a nonmodal function applies only to its block.
| Word | Meaning | Common pitfall |
|---|---|---|
| N | Block/sequence number | Not a motion coordinate |
| G | Preparatory function | Sets motion or machining mode |
| X, Y, Z | Axis coordinate/displacement | Meaning follows distance mode |
| I, J, K | Arc-centre data along X, Y, Z | Centre mode can differ from endpoint mode |
| R | Arc radius or canned-cycle retract plane | Context changes its meaning |
| F | Feed | Unit follows feed mode |
| S | Spindle speed command | Usually rev/min in fixed-speed mode |
| T | Tool selection | Tool selection and tool change may be separate |
| H, D | Tool-length/radius offset selection in common milling dialects | Usually register numbers, not literal lengths |
| M | Miscellaneous machine function | Spindle, coolant, program control |
| G codes | Common milling meaning |
|---|---|
| G00; G01 | Rapid positioning; straight interpolation at feed |
| G02; G03 | Clockwise; anticlockwise circular interpolation |
| G04 | Dwell; time-word units depend on controller |
| G17; G18; G19 | XY; XZ; YZ plane selection |
| G20; G21 | Inch; millimetre units |
| G90; G91 | Absolute; incremental endpoints |
| G40; G41; G42 | Cancel; left; right cutter-radius compensation |
| G43; G49 | Apply positive tool-length compensation; cancel length compensation |
| G54–G59 | Select stored work coordinate systems |
| G94; G95 | Feed per minute; feed per spindle revolution |
| G96; G97 | Constant surface speed; fixed spindle speed (where supported) |
| G80 | Cancel canned cycle |
| G98; G99 | Canned-cycle return to initial plane; return to R plane |
| M codes | Common meaning |
|---|---|
| M00; M01 | Unconditional program stop; optional stop when enabled |
| M02; M30 | Program end; end/reset (rewind behaviour is controller-dependent) |
| M03; M04; M05 | Spindle clockwise; anticlockwise; stop |
| M06 | Tool change |
| M07; M08; M09 | Mist coolant; flood coolant; coolant off |
3.3 Circular interpolation and chord error
For G17, view the XY plane from towards the origin: G02 is clockwise and G03 anticlockwise. Endpoint coordinates follow G90/G91. In the common incremental-centre convention, I and J are centre offsets measured from the arc start even when endpoints are absolute.
Radius programming can give two possible arcs; many controllers use the sign of R to distinguish arcs below/above . Full circles and near-semicircle arcs are better specified by centre data when the controller permits. Do not assume that selecting G90 also selects absolute arc centres.
3.4 Cutter offsets and feed units
The part boundary and the cutter-centre path differ by the cutter radius. “Left” and “right” are seen looking along the programmed direction of travel, not from the centre of the part.
3.5 Canned cycles and block tracing
A canned cycle packages a repeated sequence. In a typical vertical drilling cycle, the tool positions at the hole XY location, rapids to R, feeds to Z depth, and retracts to the selected return level.
| Cycle | Typical action |
|---|---|
| G81 | Drill: feed in, rapid out |
| G82 | Feed in, dwell at bottom, rapid out |
| G83 | Peck drilling with intermediate withdrawals |
| G84 | Tapping with coordinated spindle/feed reversal |
| G85 | Bore/ream: feed in and feed out |
| G86 | Bore, stop spindle, rapid out |
| G80 | Cancel the active canned cycle |
Follow the state after every block: current position, units, plane, distance/feed modes, cycle and offsets. Modal repetition is why the second line drills another hole although it contains no G81 word.
3.6 Computer-assisted part programming
A geometry-based programming system defines part geometry and motion, then produces cutter-location (CL) data. The postprocessor translates that data into the selected controller's syntax and machine configuration. A simulator checks motion, reach, collisions and residual material; successful syntax alone does not verify a usable machining process.
APT means Automatically Programmed Tool. Its major statement classes are geometry definitions, motion statements, postprocessor/auxiliary commands and program-control statements.
| APT idea | Common statement form | Meaning |
|---|---|---|
| Point definition | P1 = POINT/12,8,0 | Name a geometric point |
| Initial reference | FROM/P1 | Establish starting cutter location |
| Explicit destination | GOTO/P2 | Move to a named location |
| Relative displacement | GODLTA/5,0,0 | Incremental displacement |
| Auxiliary data | FEDRAT/..., SPINDL/..., COOLNT/... | Feed, spindle and coolant requirements |
| End | FINI | Terminate the source program |
In surface-guided APT motion, the part surface supports the cutter, the drive surface guides its side, and the check surface limits the motion. TO/ON/PAST conditions describe cutter approach to the check geometry under the specified tool convention. CL data is an intermediate representation, not necessarily executable G-code.
Last-minute recall
- G90 targets coordinates; G91 adds displacements in the active frame.
- Preparatory functions use G; miscellaneous functions use M.
- In G17, view from positive Z to identify clockwise and anticlockwise motion.
- Incremental I/J centre offsets can coexist with absolute X/Y endpoints.
- G41 and G42 refer to the left/right of the travel direction.
- G80 cancels a canned cycle; G86 is a boring cycle.
- M00 always stops; M01 stops only when optional stop is enabled.
- G98/G99 return-level meanings here are milling conventions.
- A postprocessor is machine-specific; a geometric tool path is not a complete machine setup.