School of Engineering · Playlist

CNC Fundamentals

CNC controls, axes and offsets, positioning modes, program structure, toolpaths, and proving a program.

  1. CNC Control Fundamentals
  2. CNC Axes and Offsets
  3. Absolute and Incremental Positioning
  4. CNC Program Structure
  5. G-code and Toolpaths
  6. CNC Programming and Prove-Out
Machining/CNC

CNC Control Fundamentals

How a control turns a program into motion, how feedback works, and what changes between milling and turning.

CNC repeats programmed motion; the operator still defines the process

CNC repeats programmed motion; the operator still defines the process

Computer numerical control (CNC) uses a program to command machine motion and functions. On a manual machine, the operator directs each move with handwheels or power-feed controls. On a CNC machine, the operator prepares the tools, workholding and coordinate references, then checks the programmed sequence.

CNC can repeat a complex path consistently. It does not remove variation from tool wear, deflection, temperature or setup errors. Programming and setup take time, so CNC is not automatically faster for every one-off job.

The machine control unit (MCU) reads program blocks, keeps track of active settings, calculates intermediate positions along a path, and sends commands to the axis drives and machine functions. The drives supply power to the motors. The control also presents positions, settings and alarms to the operator.

Feedback distinguishes open-loop and closed-loop motion

Feedback distinguishes open-loop and closed-loop motion

SystemHow position is controlledWhat that means
Open loopThe drive sends motion commands without measuring actual position back into that positioning loop.The control may not detect a missed step. A displayed commanded position is not proof of actual position.
Closed loopA sensor reports position or motion; the drive/control compares feedback with the command and corrects error.Excessive following error can produce an alarm. Feedback does not make the mechanics error-free.

A stepper motor advances through commanded angular steps and is often used in open-loop systems. A servo system uses feedback to regulate motion. Closed-loop stepper systems also exist: motor type alone does not tell you whether feedback is present.

Supporting detail: Addendum 1 — Where the sensor sits matters.

Milling rotates the cutter; turning rotates the work

Milling rotates the cutter; turning rotates the work

Basic machineCutting motionCommon programming concerns
Three-axis vertical millA rotating cutter moves relative to the work along X, Y and Z.Tool lengths, cutter radius, XY contours and hole locations.
Two-axis latheThe work rotates while a cutting tool moves along X and Z.Diameter/radius convention, tool geometry and wear offsets, tool nose radius and changing work diameter.

Machines with live tooling, extra linear axes or rotary axes extend these basic cases. A mill's tool changer and a lathe's turret do not necessarily use the same tool-selection commands. Learn the geometry in CNC Axes and Offsets, then compare Milling Operations and Lathe Operations. For cutting data use Feeds and Speeds; for milling direction use Climb and Conventional Milling.

G-code is a family of control dialects

G-code is a family of control dialects

These pages describe common Fanuc-style milling usage, with turning differences called out. G- and M-code meanings vary by control, machine type, options and configuration. Check the machine's own manual before applying a code or example. These examples teach interpretation; they are not production programs.

PathPilot is Tormach's machine control. Tormach publishes PathPilot programming documentation and post-processor guidelines. Select documentation for the actual machine and software version. A general description does not establish its installed tools, options or setup.

Continue with CNC Program Structure and CNC Programming and Prove-Out. Use G-code and Toolpaths to explore a deliberately limited teaching interpreter.

Machining/CNC

CNC Axes and Offsets

Identify mill and lathe axes, distinguish machine and work zero, and separate work offsets from tool compensation.

Describe tool motion relative to the work with a right-handed frame

Describe tool motion relative to the work with a right-handed frame

Use your right hand: thumb along +X, index finger along +Y and middle finger along +Z, with all three perpendicular. Equivalently, curling from +X toward +Y makes the thumb point along +Z. Z runs parallel to the principal spindle axis.

On a conventional vertical mill viewed from the front, +X is to the right, +Y is toward the back and +Z raises the tool away from the work. These are tool-relative-to-work directions. If the table moves instead of the tool, its physical motion is opposite the tool-relative motion.

Vertical mill: tool-relative X right, Y back, Z up. Basic lathe: Z along the spindle away from the headstock, X radially outward on the illustrated tool side.

For a basic lathe, Z is along the spindle and +Z is away from the headstock. X is radial; positive X values commonly describe the tool side of the centreline. A slant bed or rear turret changes what this looks like from the operator's position. Do not infer axis signs from screen orientation. Two-axis turning normally uses the XZ plane.

A lathe X value may describe diameter or radius; Practice

A lathe X value may describe diameter or radius

In diameter programming, X24 describes a surface 24 mm in diameter, 12 mm from the spindle centreline. In radius programming, the same surface is X12. Z distances are not halved.

For a change from diameter 30 mm to diameter 26 mm, the X coordinate changes by −4 mm in diameter mode, but the tool moves only 2 mm radially inward. Confirm the control's convention for absolute X, incremental X and arc-centre words separately; do not halve every number in a turning block.

Practice diameter and radius

Machine zero belongs to the machine; work zero belongs to the setup

Machine zero belongs to the machine; work zero belongs to the setup

Machine zero is the machine coordinate origin. A reference-return or homing procedure establishes the machine's position reference; the home position need not be the coordinate origin. Work zero is a chosen datum on the part or fixture, such as a corner, hole centre or faced end.

Common milling codes G54 through G59 select stored work coordinate systems. Selecting G54 does not measure the part, write the offset table or redefine machine zero. The setup procedure establishes the stored values.

Simplified XY translation: work zero is at machine coordinates 100,60. A work point 20,15 is at machine coordinates 120,75.

With only a translation, machine position = work-zero location in machine coordinates + work position. If the work origin is (100,60) and the program point is (20,15), the machine point is (120,75). This example omits rotation, local shifts and tool offsets.

In common Fanuc-style milling, G53 selects machine coordinates for the block containing it. It does not erase G54 or force G54 to become the next active work system. The previously selected work system remains selected afterward. Tool-offset interaction and permitted motion modes are control-specific; check your control's manual. Machine-coordinate zero is not necessarily a clearance position.

Tool length and cutter radius compensate for different dimensions

Tool length and cutter radius compensate for different dimensions

In common Fanuc-style milling, G43 H... applies positive tool-length compensation: it adds the signed value stored in the selected H register to commanded Z positions so Z can refer to the intended tool-tip position. The offset's sign, established by the touch-off convention, determines the direction of that shift. G43 does not mean an unconditional upward move. Check your control's manual for its offset and touch-off conventions.

For example, H03 selects register 3; it does not mean a length of 3 mm. T selects a tool; H selects offset data. Their numbers may match by shop convention, but the programmer must verify that relationship. G49 commonly cancels length compensation.

Supporting detail: Addendum 2 — Why positive compensation can use a negative offset.

G41 offsets a cutter to the left of the programmed path looking in the direction of travel; G42 offsets it to the right. G40 cancels it. These are not clockwise/counterclockwise commands. Moving along +X in XY, left is +Y. On many mills a D word selects cutter compensation data; check whether that register stores radius, diameter or a wear adjustment.

Compensation needs suitable entry and exit moves. Do not add a full radius correction to a CAM path that already includes that correction. Turning tool nose compensation also depends on nose radius and tool orientation; it is not simply a milling H offset.

See G-code and Toolpaths for tool-centre paths without compensation. Tormach's PathPilot guidelines describe H-based tool offset selection; CIMCO's Fanuc milling lesson illustrates left/right compensation.

Machining/CNC

Absolute and Incremental Positioning

Convert between positions and signed moves, and trace the endpoint of a program as its distance mode changes.

G90 gives a destination; G91 gives a signed change

G90 gives a destination; G91 gives a signed change

In common milling usage, G90 makes axis values absolute coordinates in the active coordinate system. G91 makes them signed changes from the current position. Neither command moves an axis by itself. Units and work offsets still matter.

Increment = next position − current position. Reverse the calculation with next position = current position + increment. Keep a separate running total for every axis.

For an ordinary G00/G01 move, an omitted axis stays in place. In G90, X0 requests X zero; in G91, X0 requests zero X movement. Do not reuse an omitted incremental value from the preceding block.

These G90/G91 meanings must not be assumed on every lathe. Some turning controls use X/Z for absolute and U/W for incremental coordinates, and use G90 for a turning cycle. Check the control before translating a mill program to a lathe.

One path can be written as points or as moves; Practice

One path can be written as points or as moves

Start at A = (6,4) mm. Visit B = (26,4), C = (26,19), then D = (11,19). Z is unchanged; these are coordinate exercises with no cutting setup implied.

MoveAbsolute destination, G90Increment, G91
A → BX26 Y4X20 Y0
B → CX26 Y19X0 Y15
C → DX11 Y19X−15 Y0

Path from A 6,4 to B 26,4 to C 26,19 to D 11,19. Signed moves are plus 20 in X, plus 15 in Y, then minus 15 in X.

Supporting detail: Addendum 3 — Check the conversion in both directions.

Practice point-list conversion

Trace the active mode before evaluating each block; Practice

Trace the active mode before evaluating each block

Assume millimetres, one unchanged work coordinate system, no compensation and an initial position (6,4,12). This is a paper trace, not a machine-ready program. F120 is an arithmetic example.

G21 G90 G94
G01 X26 Y4 F120
G91 Y15
X-15
G90 X8
M30
Motion blockModePosition afterward (mm)
G01 X26 Y4 F120Absolute(26,4,12)
G91 Y15Incremental(26,19,12)
X−15Incremental; G01 remains active(11,19,12)
G90 X8Absolute; G01 remains active(8,19,12)

M30 ends this trace; it is not a command to move to zero. For arcs, the endpoint mode and centre mode are separate questions: see G-code and Toolpaths. For a broader view of modes use CNC Program Structure.

Practice a program endpoint

Machining/CNC

CNC Program Structure

Read program identifiers, startup modes, machine functions, feed modes and drilling cycles in common milling G-code.

A block can combine motion, settings and machine functions

A block can combine motion, settings and machine functions

A word is a letter and value, such as X12 or F100. A block is a line of words. The control applies its execution rules; words are not necessarily executed in left-to-right typing order. N numbers label blocks and are often optional. Many Fanuc-style programs use an O number such as O2468 as the program identifier. File naming, percent delimiters and identifiers vary by control.

A modal command stays active until replaced or cancelled within its group. G01 can remain active while G90 changes to G91, because motion and distance mode are different groups. A startup line sets specific modes; it does not clear every stored setting or offset.

A safe-start line declares assumptions; it does not prove the setup

A safe-start line declares assumptions; it does not prove the setup

A common milling startup example is G17 G21 G90 G94 G40 G49 G80: XY plane, millimetres, absolute endpoints, feed per minute, cutter compensation cancelled, tool-length compensation cancelled and canned cycles cancelled. This is a reading example, not a universal restart line. Cancelling an offset changes the coordinate relationship; startup and restart sequences must match the actual control and tool position.

  1. Identify the program and establish required units, plane and modes.
  2. Select the intended work coordinate system and tool; apply the correct offset data.
  3. Establish spindle, feed and coolant settings for the operation.
  4. Perform positioning and machining blocks, including any cycle cancellation.
  5. Use the machine-approved retract and shutdown sequence, then end the program.

The order and motion details around tool changes and offset activation require the machine manual. See CNC Axes and Offsets and CNC Programming and Prove-Out.

Separate spindle, tool and coolant commands from motion; Practice

Separate spindle, tool and coolant commands from motion

These are common Fanuc-style meanings, not a promise for every machine.

CodeCommon meaningRead with it
M03 / M04 / M05Spindle clockwise / counterclockwise / stopS sets the speed value. Direction is conventionally viewed from the spindle toward the work; confirm machine orientation.
M06Tool change on many millsT selects a tool. The changer may be manual or automatic; offset activation is a separate issue.
M08 / M09Flood coolant on / coolant offAvailable coolant systems and auxiliary M codes depend on the machine.
M30End program and commonly reset/rewindIt does not command a return to machine or work zero, and does not mean automatically run another part.

For example, S1800 M03 requests 1800 rpm in a fixed-rpm mode; it is not a cutting recommendation. A lathe using constant surface speed interprets S differently. See Feeds and Speeds.

Practice code meanings

Units, feed mode and plane answer different questions

Units, feed mode and plane answer different questions

SettingCommon milling interpretation
G20 / G21Inch / millimetre length units.
G94 / G95Feed in units per minute / units per spindle revolution, where supported.
G17 / G18 / G19XY / XZ / YZ plane for plane-dependent operations such as arcs.
G00 / G01Rapid positioning / straight-line motion at programmed feed.
G02 / G03Clockwise / counterclockwise arc in the selected plane.

In G21 G94, F90 means 90 mm/min. In G21 G95, F0.15 means 0.15 mm/rev; at 600 rpm that corresponds to 90 mm/min. G20/G21 alone does not choose the time basis. Some lathes use G98/G99 for feed mode, while mills commonly use those codes for drilling return levels.

Rapid path shape depends on the control and can differ from G01. G01 may feed through air as well as cut. Learn the motion and arc geometry in G-code and Toolpaths, including the existing simulator; learn distance modes in Absolute and Incremental Positioning.

G81 and G83 repeat a drilling sequence at hole locations

G81 and G83 repeat a drilling sequence at hole locations

A canned cycle packages repeated motions. In common milling use, G81 feeds a drill to depth then retracts; G83 divides the depth into pecks with retracts for chip clearance. X/Y locate the hole, Z specifies the drill-tip depth, R specifies a return/approach plane, F sets feed, and Q commonly specifies peck depth for G83. Q is not the final hole depth.

With G90 on a conventional mill, Z and R are coordinates in the active work system. Incremental canned-cycle rules need separate study in the manual. G98 commonly returns to the initial level and G99 to R; choose a return level for the actual setup. G80 cancels the cycle. Modal hole cycles can drill again at subsequent position blocks.

The simulator in G-code and Toolpaths demonstrates G81, not G83. See Tormach's programming reference for control-specific modes and cycles, and the Haas lathe manual for examples of meanings that differ from milling.

Machining/Milling

G-code and Toolpaths

How a CNC mill reads a program line by line: rapid and feed moves, absolute and incremental coordinates, units, arcs and a drilling cycle. Build a program from blocks and watch it cut a simulated block.

What is G-code?

What is G-code?

A CNC mill moves its tool by reading a program from the top down, one line at a time. The language most mills read is called G-code. Each line holds a few words, and together they say where the tool goes next, how fast, and what the spindle and tool are doing.

Start with CNC Control Fundamentals for the control and machine types, CNC Axes and Offsets for coordinate references, and CNC Program Structure for common Fanuc-style milling codes. G- and M-code meanings vary by control. The simulator below uses its own documented subset; check the machine's manual for real programs.

Word
A letter and a number, such as X20, G1 or F300. The letter says what the number means: X, Y and Z are positions, F is the feed rate, S the spindle speed, T a tool number. G and M words are codes that choose what kind of move or machine action the line is.
Block
One line of the program. Machinists often call a line a block; in the simulator below, each block you snap into place is one line of G-code, with the same number.
Work zero
The point the program’s numbers count from. Here, as in Milling Operations, X 0, Y 0 is the front left corner of the block and Z 0 is its finished top face. The uncut stock starts at Z +1. Positions refer to the tip of the tool, on its centre line: Z −3 is 3 mm below work zero and 4 mm below that raw top. A pointed drill reaches its programmed Z at its tip; the full-diameter hole is shallower.
Modal
Most codes stay in force until another code from their group replaces them. After a G1, a line with only X80 is still a G1 move; a feed rate set with F remains available until changed. Not every word is modal. For ordinary G0/G1 moves, an omitted axis stays in place; it does not repeat the preceding incremental displacement.

A first cut: one slot

  1. (A first cut: a closed-ended slot)
  2. G21 G90 G17
  3. T1 M6
  4. S2500 M3
  5. G0 X10 Y30
  6. G0 Z2
  7. G1 Z-3 F100
  8. G1 X90 F300
  9. G0 Z20
  10. M5
  11. M30
05010003060XYX0 Y0startTOP VIEWback vise jawfront vise jawZ +20Z +10Z 0Z −10Z −20jaw topFRONT VIEW, CUT THROUGH THE BLOCK AT Y 30.0Cut depthZ 0−5−10−15−20throughfeed (G1, G2, G3): cutsrapid (G0): through the air
A first cut: one slot. Mill a closed-ended slot 10 mm wide to Z−3 with a Ø10 end mill. The raw top is Z+1, so the cut is 4 mm deep. Lift clear and stop. The program on the left, numbered line by line, and the block after it has run. Solid lines are feed moves, dashed lines are rapids; the darker the cut, the deeper it goes.

Read the program above from the top. Line 2 sets millimetres, absolute positions and the XY plane. Line 3 puts tool 1, a Ø10 end mill, in the spindle, and line 4 starts the spindle at 2500 rpm. Lines 5 and 6 move the tool through the air to just above the start of the slot. Line 7 feeds it to Z −3, cutting 4 mm below the raw top at Z +1. Line 8 feeds it along the closed-ended slot, and line 9 lifts it clear. Line 10 stops the spindle and line 11 ends the program.

Rapid moves put the tool in place through the air; feed moves cut

Rapid moves put the tool in place through the air; feed moves cut

  • G0 is a rapid move. The control uses its rapid positioning rate, subject to machine limits and applicable overrides. It is for getting the tool to where a cut starts, through the air, never for cutting.
  • G1 is a feed move. The tool moves in a straight line at the feed rate set by F, here in millimetres per minute. It can cut or feed through air.
  • The spindle has to be turning first. S sets its speed in revolutions per minute, M3 starts it turning clockwise seen from above, and M5 stops it. T1 M6 changes to tool 1.
  • A move goes in one straight line. G1 X80 Y40 Z-2 moves all three axes together and they all arrive at once. An axis left out of the line stays where it is: G1 X80 moves along X only.

A rapid into metal is a crash: the tool arrives at full traverse speed with nothing to say it should be cutting. The simulator stops a rapid at the point where it would touch the block and says so. It does the same if a feed move reaches the metal with the spindle stopped.

This simulator moves a rapid in one straight line, the way the LinuxCNC G-code reference describes G0. Controls differ in how they move during a rapid, so check how the one you use moves before you count on the path a rapid takes.

G90 and G91, G20 and G21: two modes that change what every number means

G90 and G91, G20 and G21: two modes that change what every number means

G90, absolute
A number is a position, measured from work zero. With the tool at X 10, G1 X30 moves it to X 30.
G91, incremental
A number is a distance from where the tool is now. With the tool at X 10, the same G1 X30 moves it 30 mm, to X 40.
G21, millimetres
X30 means 30 mm and F300 means 300 mm per minute with the simulator's G94 feed mode.
G20, inches
The same X30 means 30 inches, which is 762 mm, and, with G94, the feed rate is in inches per minute. A millimetre program read in inches asks for moves 25.4 times as long.

Because these modes change the meaning of every line after them, a program sets both near its start, before the first move. The simulator insists on it: a move before G20 or G21 and G90 or G91 have been set stops the program, and so does a change of units after the machine has started moving.

Work through a point list in Absolute and Incremental Positioning. Units and feed mode are separate settings; G95, where supported, uses feed per spindle revolution.

G2 turns clockwise and G3 counterclockwise, seen from above; Practice

G2 turns clockwise and G3 counterclockwise, seen from above

An arc move cuts along part of a circle in the XY plane (G17) at the feed rate. Its direction is the way it turns as seen looking down on the work from above: G2 clockwise, G3 counterclockwise. The line gives the arc’s end point with X and Y, and its centre in one of two ways.

  • I and J say where the centre is, measured in X and Y from the point where the arc starts. That is the usual mode, G91.1, and it holds even while G90 makes every X and Y a position. G90.1 makes I and J a position too in this simulator. Those decimal codes are not universal; check the control's centre-mode rules.
  • R gives the radius instead, and the control works out the centre. A positive R selects an arc of up to half a turn, a negative R the longer way round in the convention used here. An R arc cannot be a full circle, because a circle through one point has no single centre; a full circle uses I and J with its end point the same as its start.

Worked example. The tool is at X 72, Y 15, moving right along the bottom of an outline. G3 X80 Y23 I0 J8 puts the centre 0 in X and 8 in Y from the start, at X 72, Y 23. Turning counterclockwise about it, the tool rounds a corner of radius 8 and ends heading up the right-hand side at X 80, Y 23. The end point has to lie on the circle: change J8 to J6 and the start radius is 6 mm while the end radius is √(8² + 2²) = √68, about 8.246 mm, so the simulator stops at that line instead of guessing.

A radius-10 quarter arc from A 12,8 to B 22,18 around C 12,18 uses G03 I0 J10. Reversing from B to A uses G02 I-10 J0.

In the diagram, absolute endpoints and start-relative centres give G03 X22 Y18 I0 J10 from A to B, then G02 X12 Y8 I-10 J0 back to A. Each start point needs its own centre offsets. Radius format can instead use G03 X22 Y18 R10 for the first arc under the stated convention.

G17 uses X/Y and I/J; G18 uses X/Z and I/K; G19 uses Y/Z and J/K. I, J and K correspond to centre components along X, Y and Z. Judge arc direction looking from the positive normal axis toward the plane: +Z for XY, +Y for XZ, +X for YZ. The simulator supports XY arcs only.

Practice quarter arcs

Arcs: a rounded outline

  1. (Groove around a rounded rectangle)
  2. G21 G90 G17
  3. T2 M6
  4. S3000 M3
  5. G0 X28 Y15
  6. G0 Z2
  7. G1 Z-1.5 F80
  8. G1 X72 F250
  9. G3 X80 Y23 I0 J8
  10. G1 Y37
  11. G3 X72 Y45 I-8 J0
  12. G1 X28
  13. G3 X20 Y37 I0 J-8
  14. G1 Y23
  15. G3 X28 Y15 I8 J0
  16. G0 Z20
  17. M5
  18. M30
05010003060XYX0 Y0startTOP VIEWback vise jawfront vise jawZ +20Z +10Z 0Z −10Z −20jaw topFRONT VIEW, CUT THROUGH THE BLOCK AT Y 15.0Cut depthZ 0−5−10−15−20throughfeed (G1, G2, G3): cutsrapid (G0): through the air
Arcs: a rounded outline. With a Ø6 end mill, follow a 60 × 30 rounded rectangle with R8 corners at Z−1.5. The groove is 2.5 mm below the raw top, Z+1. Four G3 arcs turn the corners. The program on the left, numbered line by line, and the block after it has run. Solid lines are feed moves, dashed lines are rapids; the darker the cut, the deeper it goes.
A drilling cycle packs a whole hole into one line

A drilling cycle packs a whole hole into one line

G81 X15 Y15 Z-8 R2 F120 drills a hole at X 15, Y 15. The tool moves there at rapid, comes down at rapid to R, the height just above the work where feeding begins, feeds down to Z, the drill-tip depth, and rises back up at rapid.

  • How high it rises. In this simulator G99 rises to R between holes, and G98 rises to the height the tool was at when the cycles began, or to R if that is higher. The simulator needs one of the two before the first G81.
  • The cycle is modal. After a G81, a line with only X or Y drills another hole with the same depth, R and feed. G80 ends the cycle; after it, a line with only X or Y is an error until a G0 or G1 says how to move.
Without cutter compensation, program the tool centre path

Without cutter compensation, program the tool centre path

With cutter compensation off, as in this simulator, X and Y describe where the centre of the tool goes. The metal is cut by its edge, one radius further out. A Ø10 end mill fed along Y 30 cuts a slot from Y 25 to Y 35. To leave a wall at X 80 with the metal beyond it cut away, the centre runs along X 85. Milling Operations works through the same rule for a shoulder and a pocket.

Controls can do that offset for you with cutter radius compensation, G41 and G42. The simulator does not model it, so every program here is written as the path of the centre, and a line with G41 or G42 stops with a message. CNC Axes and Offsets explains left/right compensation and tool-length offsets.

Simulator: build a program from blocks and watch it run; Interactive

Simulator: build a program from blocks and watch it run

Pick a program, change it, and run it on a simulated block of metal in a vise. Every block is one line of G-code; the same interpreter reads it whether you build it from blocks or type it, and the machine runs exactly what it reads.

How to drive it. Press a block in the program to open it and change its numbers; leave a number empty to leave that word out of the line. Add a block from the row above the program, either by pressing it, which puts it after the open block, or by dragging it into place. Drag a block by its handle to move it; with the keyboard, focus the handle and press Alt with ↑ or ↓. Play runs the program, Step runs one block and stops, Back goes back one block and Restart starts again with fresh stock. The block that is running is outlined in gold, and its move is drawn in gold on the views; press a move in the top view to open the block that makes it. Any change to the program puts the simulation back to its start, so it always shows the program as it now is.

Holes: a drilling cycle

  1. (Four holes with a drilling cycle)
  2. G21 G90 G17
  3. T3 M6
  4. S1500 M3
  5. G0 X15 Y15
  6. G0 Z10
  7. G98 G81 X15 Y15 Z-8 R2 F120
  8. X85
  9. Y45
  10. X15
  11. G80
  12. G0 Z20
  13. M5
  14. M30
05010003060XYX0 Y0startTOP VIEWback vise jawfront vise jawZ +20Z +10Z 0Z −10Z −20jaw topFRONT VIEW, CUT THROUGH THE BLOCK AT Y 45.0Cut depthZ 0−5−10−15−20throughfeed (G1, G2, G3): cutsrapid (G0): through the air
Holes: a drilling cycle. Drill four Ø6 holes with the tip reaching Z−8: 9 mm below the raw top, Z+1. Full-diameter depth is shorter because of the drill point. G81 drills the first hole; X or Y lines repeat it until G80. The program on the left, numbered line by line, and the block after it has run. Solid lines are feed moves, dashed lines are rapids; the darker the cut, the deeper it goes.
Things to try in the G-code simulator; Checklist

Things to try in the G-code simulator

  • Step through the slot program one block at a time. Watch the machine state change at blocks 2, 3 and 4 before anything moves.
  • Make the slot deeper and shorter, then run it again. Which numbers did you change?
  • Drag the Spindle on block below the first feed move, and read why the machine stops.
  • Open block 7 of the slot program and switch it from G1 to G0. What does a rapid do when it meets the metal?
  • Change the slot program to G91. Before you press Play, work out where its first move will go.
  • In the arcs program, swap one G3 for a G2, and see which way that corner turns now.
  • In the holes program, try G99 instead of G98, then add a fifth hole.
  • In the G-code text, type a line the simulator does not read, such as G41 or M7, and read what it says.
What the simulator reads, and what it leaves out

What the simulator reads, and what it leaves out

The simulator reads a small part of G-code, modelled on the way the LinuxCNC control reads it. Any other code, or a line that is not G-code at all, stops the program at that line with a message saying what is wrong. Nothing is skipped.

Motion
G0 rapid, G1 feed, G2 and G3 arcs in the XY plane, G81 drilling cycle and G80 to end it.
Modes
G17 XY plane, G20 inches, G21 millimetres, G90 absolute, G91 incremental, G90.1 and G91.1 for I and J, G94 feed per minute, G98 and G99 for the drilling cycle. G40, G49 and G54 are read as the settings the simulator always has: no cutter compensation, no tool length offset, and its one work offset.
Machine
M3 spindle on, M5 off, M6 tool change, M8 and M9 coolant on and off (shown, with no effect on the cut), M2 or M30 program end: stops spindle and coolant, restores G90 and G1, and leaves the tool at its last position.
Words
X Y Z positions, I J arc centre, R arc radius or drilling R plane, F feed rate, S spindle speed, T tool, N line number, and comments in brackets or after a semicolon.
Tools
T1 Ø10 end mill, T2 Ø6 end mill, T3 Ø6 drill, T4 Ø12 spot and chamfer tool, T5 Ø50 face mill: the tools of Milling Operations, with the same rules about what each can cut.
  • Some rules are the simulator’s own. It needs units and distance mode set before the first move, a speed before M3, G98 or G99 before a drilling cycle, and, for a tool change, the spindle stopped and the tool at Z +20 or higher. A real control may be less strict, or strict about different things.
  • Only straight down and straight across, through metal. The block is modelled as a height above each point, so the tool can cut moving along Z alone, or in X and Y at one height. A move in X or Y and Z at once is followed exactly through the air, but stops if it would reach the metal: ramping and helical moves are not modelled.
  • Arcs are cut as short straight chords, each within 0.01 mm of the true arc. They are drawn as true arcs.
  • Simple timing. Feed moves run at their F and rapids at 5000 mm per minute, with no acceleration, no blending of one move into the next, and no time for tool changes.
  • Not a check of a real program. The speeds and feeds in the examples are round teaching numbers, not cutting recommendations; Feeds and Speeds is about choosing them. A program that runs here has met only this simulator’s rules. Controls differ in the codes they accept, in their starting modes and in how they change tools, so a program for a real machine is checked against the manual for its control. See CNC Programming and Prove-Out for graphics, dry run, single block and overrides; follow Equipment Operating Procedure for machine use.

Supporting detail: Addendum 4 — How the simulator reads and runs a program.

Machining/CNC

CNC Programming and Prove-Out

Follow the CAD-to-CAM-to-post chain and use graphics, dry run, single block and overrides to check a program against its setup.

CAD describes the shape; CAM plans how to cut it

CAD describes the shape; CAM plans how to cut it

CAD supplies design geometry and drawings. CAM uses geometry plus the programmer's stock, tool, workholding, operation and cutting-data choices to calculate toolpaths. Depending on the operation, CAM may work from 2D profiles or a 3D model; a solid model is not always required.

CAD geometry and dimensions flow to CAM operations and tools, then to a machine-specific post-processor, then to G-code reviewed against the actual setup.

A post-processor translates CAM output into the syntax and conventions for a particular machine/control combination. Selecting the wrong post can change tool calls, arc format, offsets or startup behavior. Review the posted code as well as the CAM preview.

Supporting detail: Addendum 5 — Other ways to create a program.

Each prove-out aid answers a different question

Each prove-out aid answers a different question

Prove-out compares the intended operation, posted code and actual setup. Follow Equipment Operating Procedure and Machine Hazards and Housekeeping for safety requirements; this page explains program-checking concepts, not a machine operating procedure.

AidUseful forLimit
Graphics or simulationInspecting path shape, endpoints, sequence and modeled interference.A missing clamp, wrong tool model or incorrect offset can make the preview disagree with the machine.
Dry runObserving a trial cycle under the control's defined test conditions.It may substitute feed rates; the name does not guarantee no motion or no contact. Use the manual's procedure.
Single blockAdvancing through blocks while comparing position and active modes with expectations.One canned-cycle block may contain several motions. Not every internal action stops separately.
Feed overrideAdjusting eligible feed motions during observation.It need not affect rapids, tool changes or synchronized operations. Rapid override may be a separate control.
Review the program against the setup before a supervised trial; Checklist

Review the program against the setup before a supervised trial

  • Match the posted file and revision to the intended part, machine and post-processor.
  • Identify the active units, plane, distance mode and feed mode at each operation.
  • Compare work offsets, tool numbers and offset registers with the documented setup.
  • Trace the first approach, tool changes, cycle returns and final retract against the modeled stock and fixtures.
  • Check that the actual setup matches what the preview includes; resolve any discrepancy with the instructor before proceeding.
  • Identify the manual's dry-run, single-block and override behavior before using those functions in a supervised trial.
  • After an edit, repeat the affected checks; compare the first part's measured features with the drawing.

Practise interpretation with G-code and Toolpaths and explore the existing 3D/WebGL milling lab in Milling Operations. A successful simulation only establishes behavior within that model. It does not approve a program for a real machine.

Supporting detail

Addendum

Additional evidence, standards context, and background referenced from the main text.

  1. Addendum 1. Where the sensor sits matters

    A motor encoder measures the motor, while a linear scale can measure the slide directly. Screw error, backlash and elastic deflection between the sensor and the cutting point may remain. Homing establishes a reference; repeating homing is not a general cure for lost motion. See Oriental Motor's closed-loop stepper overview for an example of feedback used with steppers.

    Back to reference 1

  2. Addendum 3. Check the conversion in both directions

    Subtract endpoints: (26−6,4−4) = (20,0); (26−26,19−4) = (0,15); (11−26,19−19) = (−15,0). Add those changes to A: (6+20+0−15,4+0+15+0) = (11,19). The net move is (5,15), not the final absolute position.

    Back to reference 3

  3. Machining/Milling/G-code and Toolpaths

    Addendum 4. How the simulator reads and runs a program

    Each line is read in the order a control carries out the parts of a line: feed rate, spindle speed and tool first, then the tool change, the spindle, coolant, the modes, the move, and last the program end. So S2500 M3 G1 X20 F100 starts the spindle before it moves. Two codes from one group on a line, such as G0 G1, are an error.

    The interpreter first reads the whole program, and a second machine runs it at once to find its path, its time and the first place it would stop; that is the path drawn before you press Play. Pressing Play runs the program again on the block, move by move. The metal, the vise and the tools are those of the simulator in Milling Operations: every cut is kept as the space the tool swept, and a move that would break a tool rule or hit the vise stops where it would happen.

    An arc’s end point has to be on its circle to within 0.005 mm or 0.1 % of the radius, whichever is larger. A rapid, or a feed with the spindle stopped, stops a hair short of the first metal it would touch. The volume removed is an estimate from a 0.25 mm grid.

    Back to reference 4

  4. Addendum 5. Other ways to create a program

    A short program can be written directly in a text editor. Conversational programming asks for feature dimensions at the control. Manual data input (MDI) lets the operator enter commands at the control, often for immediate execution. These routes still require correct modes, geometry and setup data; they do not bypass prove-out. Tormach's post-processor guidelines identify control-specific requirements.

    Back to reference 5