UNIHIVE

Study Hub UNIPORT MEG 403

MEG 403 · Computer-Aided Design & Manufacturing

Programming numerically controlled machines

Program structure, G and M codes, absolute and incremental coordinates, tool compensation and a worked milling program.

Our notes

2 min read

Program structure

A part program is a list of blocks (lines); each block has words made of a letter address and a number:

AddressMeaning
Nblock (sequence) number
Gpreparatory function (type of move or mode)
X, Y, Zcoordinates
I, J, K or Rarc centre offsets or radius
Ffeed rate
Sspindle speed
Ttool number
Mmiscellaneous function (spindle, coolant, program end)

Common G codes

CodeMeaning
G00rapid positioning
G01linear interpolation (cutting)
G02 / G03circular interpolation clockwise / anticlockwise
G17XY plane
G20 / G21inch / mm units
G40 / G41 / G42cutter compensation off / left / right
G43tool length compensation
G54work coordinate system (work zero)
G90 / G91absolute / incremental coordinates
G81-G89canned 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

Watch

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.

All MEG 403 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.