Chapter 3

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 X,Y,ZX,Y,Z axes for tool motion relative to the stationary workpiece. ZZ is parallel to the principal spindle; positive ZZ increases tool–work separation in the usual setup. A,B,CA,B,C are rotations about X,Y,ZX,Y,Z. 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, XX 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.

WordMeaningCommon pitfall
NBlock/sequence numberNot a motion coordinate
GPreparatory functionSets motion or machining mode
X, Y, ZAxis coordinate/displacementMeaning follows distance mode
I, J, KArc-centre data along X, Y, ZCentre mode can differ from endpoint mode
RArc radius or canned-cycle retract planeContext changes its meaning
FFeedUnit follows feed mode
SSpindle speed commandUsually rev/min in fixed-speed mode
TTool selectionTool selection and tool change may be separate
H, DTool-length/radius offset selection in common milling dialectsUsually register numbers, not literal lengths
MMiscellaneous machine functionSpindle, coolant, program control
G codesCommon milling meaning
G00; G01Rapid positioning; straight interpolation at feed
G02; G03Clockwise; anticlockwise circular interpolation
G04Dwell; time-word units depend on controller
G17; G18; G19XY; XZ; YZ plane selection
G20; G21Inch; millimetre units
G90; G91Absolute; incremental endpoints
G40; G41; G42Cancel; left; right cutter-radius compensation
G43; G49Apply positive tool-length compensation; cancel length compensation
G54–G59Select stored work coordinate systems
G94; G95Feed per minute; feed per spindle revolution
G96; G97Constant surface speed; fixed spindle speed (where supported)
G80Cancel canned cycle
G98; G99Canned-cycle return to initial plane; return to R plane
M codesCommon meaning
M00; M01Unconditional program stop; optional stop when enabled
M02; M30Program end; end/reset (rewind behaviour is controller-dependent)
M03; M04; M05Spindle clockwise; anticlockwise; stop
M06Tool change
M07; M08; M09Mist coolant; flood coolant; coolant off

3.3 Circular interpolation and chord error

For G17, view the XY plane from +Z+Z 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 180∘180^\circ. 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.

CycleTypical action
G81Drill: feed in, rapid out
G82Feed in, dwell at bottom, rapid out
G83Peck drilling with intermediate withdrawals
G84Tapping with coordinated spindle/feed reversal
G85Bore/ream: feed in and feed out
G86Bore, stop spindle, rapid out
G80Cancel 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 ideaCommon statement formMeaning
Point definitionP1 = POINT/12,8,0Name a geometric point
Initial referenceFROM/P1Establish starting cutter location
Explicit destinationGOTO/P2Move to a named location
Relative displacementGODLTA/5,0,0Incremental displacement
Auxiliary dataFEDRAT/..., SPINDL/..., COOLNT/...Feed, spindle and coolant requirements
EndFINITerminate 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.

Revise offline: the whole CAD/CAM and Automation handbook as one PDF

40 pages · 1.8 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections