Chapter 50

Numerical Control

Numerical control is the brain of the modern machine tool: it reads a program made up of letters and numbers and translates it into movements accurate to a thousandth of a millimeter. In this chapter, we’ll look at the structure of a CNC machine, the names of its axes, where the zero points are located, how to write an ISO program, and how to test it before cutting the first workpiece. The examples use Fanuc syntax—the most common in machine shops—with Siemens equivalents where necessary.

50.1 From Traditional Machines to Numerical Control

On a parallel lathe or a traditional milling machine, the operator does everything: turns the handwheels, reads the vernier scales, decides when to stop, and adjusts the speed with the levers. The precision of the workpiece depends on the operator’s skill and attention, and no two workpieces are ever exactly alike. To enable mass production, cams were first invented (automatic cam-driven lathes, which repeat the same cycle over and over) along with copy machines (a probe follows a template, and the tool copies its shape). They worked well, but to switch to a different workpiece, the cams or templates had to be remade: they were only suitable for large batches.

The idea behind numerical control (NC) is to describe the workpiece using numbers—the coordinates of points—and let a machine handle the task of moving the axes from one point to another. The main steps are as follows:

  • Late 1940s and 1952: In the United States, to machine the complex profiles of helicopter blades and wings, the aerospace industry and MIT built the first numerically controlled milling machine. The program was stored on punched tape, and the control system consisted of valves and relays: a cabinet as big as a room;
  • The 1960s: Control systems shifted to transistors and integrated circuits, but the logic was still hardwired: each function was a circuit, and changing it required changing the hardware. The address-based program format (G, M, X, Y...) that we still use today was introduced and later standardized by the EIA RS-274 and ISO 6983 standards;
  • The 1970s: first a computer was introduced into the control system, then the microprocessor. This is CNC, or Computerized Numerical Control: the functions are programs; the workpieces are entered and edited using the machine’s keyboard and then stored; the tape disappears;
  • From the 1980s to the present: graphic display, path simulation, CAM on the engineering department's computer, networked program transfer, digital drives, five continuous axes, probes for zeroing and measuring on the machine, and PC-based controls.
WhatTraditional machineCNC Machine
Axis Movementhandwheels and levers, operated manually or with automatic feedsservomotors controlled by the control system
Curved Profiles and ConesDifficult: copier, inclined slide, skillEasy interpolation of two or more axes
RepeatabilityIt depends on the operatorHigh: The program is always the same
Workpiece Changefast for a single workpieceYou need the program; it's fast even for just a few workpieces.
Operator's Workguides each passprepare, reset, check, correct
Cost of the carlowhigher, offset by productivity

The lathe operator’s craftsmanship hasn’t disappeared: it has evolved into the ability to select tools, parameters, and fixtures, and to read and correct a program. That is why Chapters 24–28 on technology remain the foundation even for those who work exclusively on CNC machines.

50.2 How a CNC Machine Is Built

A CNC machine is a mechatronic system: mechanics, electronics, motors, and software all work together. The main components are:

  • the operator panel (HMI): screen, keyboard, cycle buttons, override selectors, electronic handwheel. From here, you load programs, enter zeros and correction values, and start and stop the cycle;
  • numerical control Full-fledged (NC or NCK): reads the program block by block, calculates the path, and divides it into many small steps (this is theinterpolator, paragraph 50.13) and sends each axis the position it must reach, hundreds or thousands of times per second;
  • The PLC: controls everything other than interpolated motion, namely the spindle, tool changer, coolant, doors, buttons, limit switches, and lubrication. It receives the M, S, and T codes from the program and converts them into commands for the machine (Chapter 49);
  • servo drives: the power electronics that supply power to the motors and close the current, speed, and often position control loops (Chapter 48);
  • the axes servomotors and the spindle motor, along with their drive systems: ball screws, belts, racks, or linear motors (Chapters 39 and 40);
  • position transducers: the encoder on the motor and, on higher-precision machines, the optical scales on the slides (Chapter 47).
Operator Panel(screen, buttons, handwheel) Numerical control(interpreter, interpolator) PLC(machine logic) Program(CAM, network, USB drive) Servo drive(current and speed) Servomotorwith encoder Recirculating ball screw and slide Inputs and outputsspindle (inverter)Tool changercoolantDoors and buttonslimit switches, pressure switches position signals current encoders optical encoder (closed-loop)
Figure 50.1 · Block diagram of a single-axis CNC machine. The feedback signals are shown in red: the encoder to the drive, and the optical encoder (if present) to the controller.

Semi-closed ring and closed ring

The controller must know the position of each axis at all times. If the position is read using the encoder on the motor, the loop is said to be semi-closed: the controller knows the motor’s revolutions and converts them into millimeters using the lead screw’s pitch. The controller is unaware of anything that happens downstream of the motor (clearance, thermal expansion of the lead screw, wear). With an optical scale mounted on the slide, the loop is closed: the slide’s position is measured directly, and transmission errors are corrected. Optical scales are expensive and must be protected from chips and coolant, which is why they are installed on precision machines.

Semi-closed-loop system: encoder on the motor CNC slide motor recirculating ball screw encoder Measures the motor's revolutions: it does not detect clearance, expansion, or wear on the screw Closed-loop system: scale on the carriage CNC slide motor optical scale measures the actual position of the slide: corrects screw errors
Figure 50.2 · On the left, the position is read on the motor (encoder, shown in yellow); on the right, on the slide, with the read head (shown in yellow) moving along the scale.
Resolution and Speed of an Axis with a Recirculating Ball Screw
Δ = pN · k v = nm · p
Δ displacement corresponding to one encoder increment, in mm · p lead of the lead screw in mm · N number of lines (pulses) of the encoder per revolution · k electronic multiplication factor (4 for quadrature signals, Chapter 47) · v: carriage speed in mm/min · nm: motor speed in rpm, with the motor directly connected to the lead screw
Example 50.1 · How far does the sled move when it receives an impulse?

An axis has a 10-mm-pitch ball screw connected directly to the motor. The encoder has 2,500 lines per revolution, read in quadrature (k = 4). The motor reaches 3,000 rpm.

increments per revolution = 2,500 × 4 = 10,000
Δ = 1010 000 = 0.001 mm = 1 µm
v = 3,000 × 10 = 30,000 mm/min = 30 m/min
Resolution: 1 µm; maximum speed: 30 m/min

Modern servomotor encoders can reach millions of increments per revolution: resolution is no longer an issue. The limit to precision lies in the mechanics, as the following example shows.

Example 50.2 · The screw gets hot

After one hour of operation, the screw from the previous example heated up by 10 °C in the 500-mm section that was under the greatest load. The coefficient of thermal expansion of steel is α = 11.5 × 10−6 1/°C. How much does the axis deviate with the semi-closed ring?

ΔL = α · L · Δt = 11,5 · 10−6 · 500 · 10 = 0.0575 mm
About 0.06 mm over 500 mm: the encoder doesn't detect it, but the scale does

Six centesimi is enough to cause an IT7 dimension (Chapter 14) to go out of tolerance. Without guideways, the machines partially compensate for this through initial warm-up (the machine is run idle before machining) and through the control system’s thermal compensation.

50.3 Axes and Their Directions (ISO 841)

To ensure that a program can be read on any machine, the names and directions of the axes are specified by the ISO 841 standard. There are only a few rules, and they apply to all machine tools:

  • The reference system is a right-handed Cartesian system: the thumb, index finger, and middle finger of the right hand, held at right angles to one another, define the positive directions of the X, Y, and Z axes (Figure 50.3; the Cartesian plane is explained in Chapter 7);
  • the axis Z It runs parallel to the spindle axis, which provides the cutting motion. The positive direction is the one that Move the tool away from the workpiece: a program that moves into negative Z penetrates the material;
  • the axis X It is perpendicular to Z and, whenever possible, horizontal. On a lathe, it is radial, and the positive direction extends away from the workpiece axis; on a vertical milling machine, when looking from the spindle toward the column, positive X extends to the right;
  • the axis Y It completes the right-hand trio: once Z and X are fixed, its direction is not chosen—it is determined by the hand rule;
  • The rotational axes A, B, and C rotate around the X, Y, and Z axes. The positive direction is that of a right-hand screw advancing in the positive direction of the axis: with the thumb of the right hand pointing along the positive axis, the other fingers curled inward indicate positive rotation;
  • The secondary linear axes, which are parallel to the X, Y, and Z axes, are called U, V, W (For example, the sleeve of a boring machine that moves parallel to the Z-axis is the W-axis.) Other axes are called P, Q, and R;
  • The standard always describes the motion of the tool relative to the workpiece, even when the workpiece is the one moving. If the table is moving, its positive direction is opposite and is indicated with an apostrophe: a positive X' moves to the left when a positive X moves to the right. Programmers don’t need to worry about this: they should always write the code as if the tool were moving.
Linear axes (right-hand) X+ (thumb) Y+ (index finger) Z+ (middle finger) O Rotary axes (right-hand thread) X+ Y+ Z+ C+ A+ B+
Figure 50.3 · On the left, the right hand’s three fingers: thumb X, index finger Y, middle finger Z. On the right, the positive rotations A, B, C around X, Y, Z: with the thumb on the positive axis, the closed fingers indicate the direction.

The Lathe

There are two main axes on the lathe: Z, along the spindle axis, positive as it moves away from the spindle, and X, radial, positive as it moves away from the axis. The lathe does not need a Y-axis because the workpiece is a solid of revolution; lathes with powered tools add the axis C (the spindle that is positioned at an angle like an axis) and sometimes the axis Y. An important point: on lathes, the X dimension is almost always written as by diameter. X60. This means that the tip of the tool is located on a 60-mm diameter, that is, 30 mm from the axis. Thus, the dimensions in the program are the same as those in the drawing, which specifies the diameters (Chapter 13).

X60. = Ø60 C W tool spindle Z+ X+
Figure 50.4 · The axes of the lathe, drawn with the tool positioned above the axis, as in slant-bed lathes with the turret at the rear. The positive Z axis extends away from the spindle, and the positive X axis extends away from the axis; the X dimension is the diameter.
Example 50.3 · How far does the tool with X penetrate the diameter?

The tool is positioned on the Ø80 bar (X80.), and the program specifies G01 X74.2. How far does the cross slide move? How do you write the same movement in incremental form?

displacement along the radius = 80 − 74,22 = 2.9 mm
incremental (on Fanuc lathes with the U address, always at the diameter): U−5.8
The slide moves in 2.9 mm: this is the cutting depth (ap) described in Chapter 26

The Vertical Milling Machine

On a vertical milling machine and a vertical machining center, the spindle is vertical, so Z It is vertical and directed upward (the tool moves away from the workpiece). Looking at the machine from the front, as the operator does, X positive goes to the right and Y The positive direction is toward the column, that is, away from the operator. If the machine has a table that rotates around the Z-axis, that is the axis C; a table that tilts around X is the axis A, a head that tilts around the Y-axis B. On horizontal machining centers, the spindle is horizontal, and therefore the Z-axis is horizontal; the rotary table, which rotates around the vertical Y-axis, is the B-axis.

View from the front, from the operator's side upright (rear) table workpiece spindle X'+ (table motion) Z+ X+ Y+ toward the column C+ A+ B+
Figure 50.5 · The axes of the vertical milling machine. If the table moves along the X-axis, its positive direction is reversed (X'); however, the programmer specifies the tool's motion relative to the workpiece.

50.4 Reference Points and Workpiece Origins

A coordinate means nothing unless you know where it is measured from. On a CNC machine, there are several fixed points, indicated on the manufacturer’s drawings with standardized symbols:

  • M, machine zero: the origin of the machine's coordinate system, set by the manufacturer. On a lathe, it is usually located on the spindle axis, at the contact face of the self-centering chuck; on a milling machine, it is often located at one end of the travels, so all machine coordinates within the work area are negative;
  • R, reference point: a specific point along the travels, marked by a cam switch and the encoder’s zero pulse. With incremental encoders, when the system powers on, the controller does not know where the axes are: a zero search must be performed (known in technical jargon as “zeroing” or “homing”), which means moving the axes to R. From there, the controller knows the distance to M, and only then do the software-defined extended travels apply. With absolute encoders, the position remains in memory even when the machine is turned off, so homing is not necessary;
  • W, work zero: the origin selected by the programmer, usually a point on the workpiece from which the drawing dimensions are measured (Chapter 13). All program coordinates are referenced to W;
  • The tool reference point: on a lathe, the turret mounting point (often designated by F or T); on a milling machine, the point on the spindle nose, on the reference line of the taper (designated by N or the manufacturer’s code). Tool lengths and stick-outs are measured from this point;
  • the cutting edge: the point that actually cuts—the theoretical tip P of the insert on a lathe, or the tip and radius of a milling cutter. The difference between the tool reference point and the cutting edge is the offset (paragraph 50.5).
M machine zero · W work zero · R reference point F turret reference · P tool tip turret F P X-axis position Z axis R M W Work zero offset in Z
Figure 50.6 · Lathe reference points. The program refers to W and P; the machine recognizes M, R, and F. The work zero and offsets serve as a bridge.
spindle reference line L (H offset) W M machine zero (often coincides with R) G54 X (negative) G54 Z (negative) table
Figure 50.7 · Reference points on the vertical milling machine, as seen from the front. G54 contains the position of W as measured from M; the tool length L is entered into the H offset.

The Origins of Workpieces G54–G59

The position of W relative to M is entered into a control table as workpiece offsets. On Fanuc machines, there are six of these, called by the program using G54, G55, G56, G57, G58, and G59, plus many other optional ones (G54.1 P1, P2...). On Siemens machines, the first ones are named the same way (G54–G57, then G505–G599), and programmable offsets can be added using TRANS and ATRANS. Having multiple origins allows, for example, mounting four clamps on the table and machining four workpieces with the same program, simply by changing the origin.

To determine the values to be entered, reset the workpiece using one of the following methods:

  • By light contact: With the tool rotating, approach the workpiece slowly until it just touches it (you’ll see the first mark or a very thin chip), or use a sheet of paper or a feeler gauge between the tool and the workpiece. Read the machine coordinate and add or subtract the tool radius or the thickness;
  • with an edge detector: a small eccentric cylinder that, when rotated, stops oscillating when it touches the edge, or an electronic edge detector that lights up upon contact;
  • With the probe mounted in the spindle: an automatic cycle touches the workpiece, calculates the zero point, and automatically enters it into the table (Chapter 37). This is the fastest method and the least prone to transcription errors.
X+ touch: Machine X −412.350 Y+ coordinate: Y machine −238.120 W (G54) 60 40 X+Y+
Figure 50.8 · Top view: 120 × 80 plate zeroed using a Ø6 ball probe (drawn larger). Two probes touch the edge; the W zero is centered.
Work zero with touching an edge
XW = Xc ± r + a
XW Work zero machine coordinate, to be entered as G54, in mm · Xc coordinate of the tool center (or ball) at the point of contact · r tool radius or effective ball radius: + if the contact occurs while moving in the positive direction, − if the contact occurs while moving in the negative direction · a distance, with a sign, from the edge to the point chosen as W. The same applies to Y.
Example 50.4 · Zero at the center of a plate using a probe

A 120 × 80 plate is clamped in a vise. The probe has an effective radius of 3,000 mm. When it touches the left side while moving in the X+ direction, the control reads X = −412.350; when it touches the front side while moving in the Y+ direction, it reads Y = −238.120. The zero point is at the center of the plate.

edge at X: −412.350 + 3.000 = −409.350 · center: −409.350 + 60 = −349.350
Edge coordinate: −238.120 + 3.000 = −235.120 · center: −235.120 + 40 = −195.120
G54: X −349,350 · Y −195,120

On Fanuc machines, the probe cycle is entered as a block such as G10 L2 P1 X-349.35 Y-195.12; manually, you go to the origin page and enter the values. The “+3” is due to the fact that, upon contact, the center of the ball is still 3 mm before the side.

Example 50.5 · Zero in Z using the block method

Use a milling cutter of known length L = 150,000 mm (measured on the presetting bench from the spindle reference line to the tip). Place a 10.000 mm-high reference block on the top surface of the workpiece and lower the spindle until the block passes just below the end mill. The control displays Z = −151.455 for the spindle reference line.

milling cutter tip: −151.455 − 150.000 = −301.455
face of the workpiece: −301.455 − 10.000 = −311.455
G54: Z −311.455 (and in the H offset of the milling cutter, L = 150.000)

The work zero on the lathe

On the X0 lathe, it’s always the spindle axis, so only the Z axis needs to be set. The most common method on Fanuc is to set the work zero directly in the geometric offsets for each tool: face the workpiece, then—without moving the Z axis—go to the offsets page and enter “Z0 measure”; turn a diameter, measure it with a micrometer, and enter “X” followed by the measured diameter. The control calculates the values automatically. Alternatively, you can use a common offset in G54 (or G50 on older controls), leaving only the lengths of the tools in the offsets.

Example 50.6 · Zeroing the First Tool on the Lathe

Using tool T01, the workpiece is face-milled: on the face, the control reads Z = −512.300 relative to the turret reference. Next, a section of the diameter is turned; the tool is retracted only in the Z axis, and Ø47.86 is measured; in that position, the control reads X = −183.420 (at the diameter).

correction factor Z = −512.300 − 0 = −512.300 (the face becomes Z0)
correction factor X = −183.420 − 47.860 = −231.280
Correction 01: X −231.280 · Z −512.300

Counterexample: If the program specifies X47.86, the control moves the turret to −231.280 + 47.86 = −183.42, exactly where the tool turned that diameter.

50.5 Tool Adjusters

Each tool has its own length and radius. If the program were to take these into account, it would have to be rewritten every time the milling cutter or insert is changed. The controls solve the problem with the correctors (offset): tables in which the dimensions of each tool are entered, which the control automatically adds to the program dimensions. Thus, the program describes the workpiece, not the tool.

Milling: Length with G43 H

On Fanuc machines, the length compensation is activated with G43 H.., where H is the table row number (usually equal to the tool number), and is canceled with G49. From that point on, the Z dimension in the program is that of the tool tip, not the spindle nose. On Siemens machines, the correction activates automatically with the number D following the tool change (T1 D1).

Z0 workpiece face Z20. Programmed T01 · H01 L = 150.0 T02 · H02 L = 95.8 reference line
Figure 50.9 · With G43, the two tips move to the same Z20 dimension, even if the tools are of different lengths: the controller raises or lowers the spindle by the difference.
Spindle Position with Length Correction
ZM = ZG54 + Zprog + L
ZM: Machine-coordinated spindle reference line, in mm · ZG54: Work zero in the Z axis · Zprog: Z dimension specified in the program · L: Tool length specified in the H offset
Example 50.7 · Where does the spindle go with G43?

With the zero point from Example 50.5 (G54 Z = −311.455), the program specifies G43 H01 Z50. using cutter T01 (L = 150.000), and then G43 H02 Z50. using drill T02 (L = 95.800).

T01: ZM = −311,455 + 50 + 150,000 = −111,455
T02: ZM = −311,455 + 50 + 95,800 = −165,655
Both drill bits stop 50 mm above the workpiece; the spindle is 54.2 mm lower with the short drill bit

If you forget to enter G43, the CNC moves the spindle nose to Z50, and the 150-mm-long tool plunges 100 mm into the workpiece. This is one of the most serious and common errors: for this reason, G43 H... is always entered in the first block that moves the Z-axis after a tool change, and the H number must match the T number.

Milling: Radius with G41 and G42 D

The cutter radius is entered in the D offset. With G41 D.. or G42 D.., the controller shifts the center of the cutter by one radius to the left or right of the programmed profile; G40 cancels this. This is discussed in detail in section 50.9.

The lathe: X and Z offsets, radius, and tool direction

There are no G43 or H codes on the lathe: the offset number is included in the T function. T0303 means tool 3 (first two digits) with offset 3 (last two). Each row of the table has four columns: X and Z, the distances from the tip to the turret reference (Figure 50.6), R, the nose radius of the insert, and T, the tip direction: a number from 0 to 9 that tells the control which side the theoretical tip P is on relative to the center of the radius. R and T are used to compensate for the nose radius with G41 and G42 (Chapter 6, Section 6.9).

26170 · 95384 Z+X+ Tool extending toward the spindle: P at the bottom left → direction 3 C P feed
Figure 50.10 · Tip direction (T column of Fanuc offsets), with X+ upward and Z+ to the right: the red dot is the theoretical tip P relative to the center C of the radius. When set to 0 or 9, the reference point is the center. On the actual machine, always consult the manufacturer’s table, as it depends on how the axes are oriented.

Geometry and Wear Compensators

Almost all inspections have two tables: geometry, with the measurements of the new tool, and wear, with the minor corrections made after measuring the workpiece. The inspection adds these values together. Corrections are always made based on wear, so the geometry value remains the one measured, and it is clear how much the tool has worn down.

Example 50.8 · Wear Allowance for Lathes

The T0303 finishing tool (R = 0.8, T direction = 3) must produce a diameter of 40.00 mm and a shoulder 25.00 mm from the face. When measured with a micrometer, the diameter is 40.06 mm; when measured with a depth gauge, the shoulder is 24.95 mm.

Diameter error: 40.06 − 40.00 = +0.06 → Wear X = −0.06 (on the diameter)
The shoulder is 0.05 mm too close to the face: the tool stopped at Z−24.95 instead of Z−25 → wear Z = −0.05
In row 03 of the wear data: X −0.060 · Z −0.050
Example 50.9 · Radius Wear Compensation in Milling

A Ø16 milling cutter (correction factor D01 = 8.000) mills the outer contour of a 100.00 × 60.00 mm island using G41. When measured with a caliper, the island measures 100.06 × 60.06 mm.

allowance on each side: 0.06 / 2 = 0.03 mm
To bring the cutter closer to the profile, the radius must be reduced: 8.000 − 0.030 = 7.970
Wear D01 = −0.030 (effective radius 7.970 mm)

For a pocket (internal profile), the reasoning is the same: if the pocket is too narrow, the cutter was too far from the wall, and the radius must be reduced.

50.6 The ISO Program: Blocks, Words, and Coordinates

A CNC program is a text file, read from top to bottom. Each line is a block and contains one or more words; each word consists of an address (a letter) followed by a number. The format is described by the ISO 6983 standard and its predecessor, EIA RS-274, which is why it is referred to as ISO programming or G-code.

%
O5000 (ESEMPIO DI STRUTTURA)
N10 G21 G90 G40 G80 (BLOCCO DI SICUREZZA)
N20 T01 M06 (FRESA D16)
N30 G54 G00 X-75. Y-50. S2980 M03
N40 G43 H01 Z50. M08
N50 G01 Z-5. F300
/N60 M00 (SALTO BLOCCO: SI ESEGUE SOLO SE IL TASTO E SPENTO)
N70 G00 Z50. M09
N80 M30
%
  • Start and end: The % character delimits the file during transmission. On Fanuc machines, the program has a number, O5000; on Siemens machines, it has a name (PERNO.MPF). It ends with M30 (end and return to the beginning) or M02.
  • Sequence Number N..: optional; this helps you locate the blocks and start again from a specific point. Many people write it in increments of ten so they can insert blocks in between.
  • Terms: G preparatory functions, M auxiliary functions, X Y Z A B C coordinates, I J K center of the arc, R radius or return plane, F feed rate, S revolutions or cutting speed, T tool, H and D offsets, P and Q parameters.
  • Comments: On Fanuc, comments are enclosed in round parentheses, which must always be closed (FRESA D16); the controller ignores them. On Siemens, comments come after the semicolon. Many older controllers only accept uppercase letters and no accented letters in comments.
  • Skip block: A slash (/) at the beginning skips the block if the "Skip block" button on the panel is enabled.
  • The decimal point: On Fanuc X20., it is 20 mm, but on the X20 without a decimal point, using the factory settings, it is read in thousandths, i.e., 0.020 mm. Placing a decimal point after whole numbers is a good practice on all controls.

Modal and Non-modal Codes

A modal code remains active until it is replaced by another code from the same group: after G01, all subsequent blocks are linear movements in operation—even if they do not repeat it—until G00, G02, or G03 is encountered. F, S, and coordinates are also modal. A non-modal code is valid only in the block in which it is written: for example, G04 (dwell), G28 (return to reference), and G10. Only one G-code per group may be written in a single block: G00 G01 in the same block is an error (the controller executes the last one or triggers an alarm). At the beginning of each program, a safety block is written to reset the modal codes to a known state (G21 G17 G40 G49 G80 G90), because the previous program may have left them in a different state.

Absolute coordinates G90 and incremental coordinates G91

With G90 (absolute), each coordinate represents the position of the point relative to the workpiece zero (W). With G91 (incremental), each coordinate represents the displacement from the tool's current position. Absolute coordinates are the most commonly used because any error is confined to the incorrect block; incremental coordinates are convenient for repeating the same movement (for example, a series of holes at a constant pitch in a subprogram). On Fanuc lathes, G91 is not used: absolute coordinates are written with X and Z, while incremental coordinates are written with U (based on dimensions) and W, and they can even be mixed within the same block. On Siemens machines, you can choose between the two for each dimension: X=IC(20) is incremental, while X=AC(20) is absolute.

From absolute to incremental
ΔXi = Xi − Xi−1 ΔYi = Yi − Yi−1
Xi, Yi: absolute coordinates of the destination point · Xi−1, Yi−1: coordinates of the starting point · ΔX, ΔY: dimensions, with signs, in mm. On a closed path, the sum of all dimensions is zero: this is a good verification.
XY 1030 5070 1020 3040 50 G91: X−20. Y20. W A (10; 10) B (70; 10) C (70; 30) D (50; 50) E (10; 50)
Figure 50.11 · The profile from Example 50.10 (dimensions in mm, 10-mm grid). The segment from C to D is shown in red: in absolute mode, point D is specified; in incremental mode, the displacement is specified.
Example 50.10 · The Same Profile in Absolute and Incremental Coordinates

The milling cutter starts at A and follows the path A, B, C, D, E, and returns to A (without compensation, for simplicity). Write the blocks in both ways.

SectionG90 (absolute)AccountG91 (incremental)
A → BG01 X70. Y10.70 − 10 = 60 · 10 − 10 = 0G01 X60. Y0
B → CY30.0 · 30 − 10 = 20Y20.
C → DX50. Y50.50 − 70 = −20 · 50 − 30 = 20X-20. Y20.
D → EX10.10 − 50 = −40 · 0X-40.
E → AY10.0 · 10 − 50 = −40Y-40.
Verification: X: 60 + 0 − 20 − 40 + 0 = 0 · Y: 0 + 20 + 20 + 0 − 40 = 0 ✓
Both versions follow the same path; in G91, the closed path returns to zero sum.

With G90, repeated dimensions (Y in A → B) can be omitted because they are modal; in G91, an omitted dimension is considered zero. Be careful not to forget that G91 is active: a G00 Z50. command written with absolute values in mind would raise the tool another 50 mm (no big deal), but a G00 Z-50. command would lower it 50 mm from its current position.

50.7 The G and M codes and the S, F, and T functions

The codes G (preparatory functions) tell the controller how to move and how to interpret the dimensions. Many have the same meaning on all controllers; others vary between lathes and milling machines and from one manufacturer to another. The table lists the main ones, in Fanuc syntax (System A for lathes).

CodeMeaningModalNotes on Lathes/Milling Machines and Siemens
G00rapid positioningyesat the maximum speed of the axes; the path may not be a straight line
G01linear interpolation during machining, feed rate Fyesthe same everywhere
G02 / G03Circular interpolation clockwise / counterclockwiseyeswith R or with I, J, K (paragraph 50.8); Siemens radius with CR=
G04dwellnoG04 P500 (ms) or X0.5 (s) milling cutter; G04 X0.5 lathe; Siemens G4 F0.5
G17 G18 G19XY plane, ZX plane, YZ planeyesThe milling cutter is usually G17; the lathe operates in G18
G20 / G21dimensions in inches / in millimetersyesOn Siemens machines, they are G70 and G71: Note that on Fanuc lathes, G70 and G71 are cycles
G28Return to the reference pointnoMove through the intermediate point as specified: G91 G28 Z0, move straight up; lathe G28 U0. W0.; Siemens G74
G40 G41 G42radius compensation: off, left, rightyesmilling cutter with D; lathe with R and T for the compensators
G43 / G49Active/Canceled Length Correctionyesmilling cutter only (G43 H..); on the lathe, the length is specified in T
G50lathe: maximum speed limit with G50 S..yesOn older lathes, with X and Z axes, set the workpiece zero; on a milling machine, it has a different meaning; Siemens LIMS=
G54...G59origins of the workpieceyesthe same on Siemens (G54-G57, then G505...)
G70...G76lathe: multiple cyclesnoG70 finishing, G71 longitudinal roughing, G72 face milling, G76 threads (section 50.10)
G80...G89milling cutter: canned drilling cycles; G80 cancels themyesG81 drilling, G83 milling, G84 tapping... (Chapter 28); Siemens CYCLE81...
G90 / G91milling cutter: absolute / incremental coordinatesyesOn the Fanuc G90 lathe, this is the simple cylindrical turning cycle; incremental turning is performed using the U and W commands
G94 / G95milling cutter: feeds in mm/min / mm/revyesOn the Fanuc lathe, G94 is the simple facing cycle; Siemens machines also use G94/G95 on the lathe
G96 / G97Constant cutting speed (S in m/min) / constant RPMyesespecially lathes (Chapter 26); with G96, the speed limit is always required
G98 / G99lathe: feeds in mm/min / mm/revyesOn the milling machine in canned cycles: return to the starting level / to the R plane

The M codes (auxiliary or miscellaneous functions) control the machine: they are executed by the PLC. Here, too, each manufacturer adds its own codes, but the main ones are common to all.

CodeMeaningNotes
M00scheduled stopThe cycle stops; press the start button to resume: to take a measurement, rotate the workpiece, and remove the chips
M01optional stopIt stops only if the “optional stop” button on the panel is lit: useful for the first workpiece
M03horizontal spindleLooking from the spindle toward the workpiece; for right-hand end mills and standard lathe tools
M04counterclockwise spindlefor inverted tools, left-hand taps, and certain lathes with tools mounted upside down
M05spindle stopbefore changing the tool, before measuring
M06tool changeMilling cutter: T05 M06—install tool 5; on the lathe, just use T
M08 / M09Coolant On / OffM07 is also often used for atomization or as an internal coolant
M30End of program and return to the beginningTurns off the spindle and coolant and counts the workpiece; M02 is the end point with no return
M98 / M99subprogram call / end of subprogramM98 P5003 calls O5003; Siemens calls by name and ends with M17 or RET

The S, F, and T Functions

  • S is the spindle speed: in rpm with G97, in m/min with G96. It must be entered before or together with M03. The values are calculated using the formulas in Chapters 26, 27, and 28.
  • F is the feed rate: in mm/min with G94 (milling) or G98 (Fanuc lathe), in mm/rev with G95 or G99. It is modal and applies to G01, G02, and G03, but never to G00, which always uses rapid traverse.
  • T is the tool. On the T05 milling machine, tool 5 is retrieved from the tool magazine, and M06 mounts it; on chain-type magazines, the next T can be entered immediately after the change, so the magazine retrieves it while the machine is running. On the T0505 lathe, the turret rotates to tool 5 and activates offset 5.
Example 50.11 · From the cutting data to S and F

A solid-carbed Ø16 milling cutter with 3 cutting edges must operate at Vc = 150 m/min and fz = 0.06 mm/tooth (Chapter 27). Next, on the lathe, a finishing tool operates at f = 0.25 mm/rev at 1200 rpm: what is the feed rate of the carriage in mm/min? And with the command `G96 S180`, what is the spindle speed on a Ø40 spindle?

n = 1000 · 1503,1416 · 16 = 2,984 rpm → S2980
F = fz · z · n = 0.06 · 3 · 2980 = 536.4 mm/min → F536 (in G94)
lathe: vf = 0.25 × 1200 = 300 mm/min (G99 F0.25 is equivalent to G98 F300 as long as the speed remains at 1200)
G96 S180 on Ø40: n = 180,000 / (3.1416 × 40) = 1,432 rpm
S2980 F536 on the milling machine; 300 mm/min and 1,432 rpm on the lathe

50.8 Linear and Circular Interpolation

Moving one axis at a time is easy; the real challenge of control is moving multiple axes together so that the tool follows a straight line or an arc exactly. This is called interpolation. With G01, the axes move at speeds proportional to their displacements, and the tool travels in a straight line at speed F, measured along the path. With G00, on the other hand, each axis moves at its own rapid traverse speed: on many controls, the path is not a straight line but a polyline, and you should never count on a precise trajectory during rapid traverse near the workpiece or the clamps.

The arches: G02, G03, and the working plane

An arc always lies in a plane, chosen with G17 (XY), G18 (ZX) or G19 (YZ). G02 It is the arch in the sense of schedule, G03 in the sense that counterclockwise, looking at the floor plan on the positive side of the perpendicular axis: In G17, the view is from Z+ downward, as if looking at the table of a vertical milling machine. The block contains the end point and, in addition, the radius R or the center with I, J, K.

G17 · XY plane, viewed from Z+ X+ Y+ G02 G18 · ZX plane, viewed from Y+ Z+ X+ G02 G19 · YZ plane, viewed from X+ Y+ Z+ G02
Figure 50.12 · When viewing each plane from the positive side of the third axis, G02 is clockwise and G03 is counterclockwise. In G18, the Z-axis is to the right and the X-axis is upward, as shown in the lathes' drawings in this manual.
  • With R: G03 X10. Y30. R20. Between two points, with the same radius, there are two arcs: a smaller one of half a turn and a larger one. With a positive R, the controller draws the smaller arc; with a negative R, it draws the larger one. With R, it is not possible to draw a full circle (the start and end points coincide, and the center is not defined). Siemens: CR=20.
  • With I, J, K: these are the distances, with signs, from the starting point of the arc at the center, along the X, Y, and Z axes. In G17, I and J are used; in G18, I and K; and in G19, J and K. On the lathe, I is always set to the radius, even when X is set to the diameter. I, J, and K are also used to machine full circles.
Arc Center Parameters (Milling Cutter, G17 Plane)
I = XC − XS J = YC − YS R = √(I² + J²)
XC, YC: coordinates of the center · XS, YS: coordinates of the starting point (Start) · I, J: signed distances, in mm · R: radius. The radius calculated from the end point must be the same; otherwise, the control triggers an alarm (code 020 on Fanuc).
XY I = −20 · J = 0 S (30; 10) E (10; 30) C (10; 10) G03 R+ (short arc) R− (long arc) start end
Figure 50.13 · On the left is the arc from Example 50.12: I and J extend from the starting point S to the center C. On the right, between the same two points and with the same radius, the symbol R indicates either the short arc or the long arc; the two centers are the dots.
Example 50.12 · A quarter circle with R and I J

The milling cutter is at point S (30; 10) and must move to point E (10; 30) along an arc with a radius of 20 and center C (10; 10), on plane G17.

direction: as seen from Z+, S is to the right of center (0°) and E is above (90°): the angle increases, so counterclockwise → G03
I = 10 − 30 = −20 · J = 10 − 10 = 0 · R = √(20² + 0²) = 20
Check using the end point: √((10 − 10)² + (30 − 10)²) = 20 ✓
G03 X10. Y30. R20. or G03 X10. Y30. I-20. J0
Example 50.13 · A Full Circle

You must trace a circle with a radius of 15 and center at (25, 0) in a clockwise direction, starting from the point (40, 0).

I = 25 − 40 = −15 · J = 0 − 0 = 0
end point = start point: X and Y can be written as equal or omitted
G02 X40. Y0 I-15. J0 (this isn't possible with R)
Example 50.14 · Three-quarters of a circle: Negative R

Center (0; 0), radius 20: from (20; 0) to (0; −20) counterclockwise, passing through (0; 20) and (−20; 0).

Path angle: from 0° to 270° counterclockwise = 270°, more than half a turn → negative R
I = 0 − 20 = −20 · J = 0
G03 X0 Y-20. R-20. Or, to be on the safe side, G03 X0 Y-20. I-20. J0

With a positive R20., the check would result in a short 90° arc passing through (14.14; −14.14), and the profile would be incorrect without triggering an alarm. For arcs longer than half a turn, I J K is safer.

💡
The bows on the lathe. The lathe operates in G18, and the direction shown on the drawing is Z to the right and X upward (Figure 50.12). The fillet and chamfer points are calculated as described in Chapter 6 (sections 6.7 and 6.8), which includes examples with I and K on the radius.

50.9 Radius Compensation

The center of the milling cutter cannot pass over the workpiece’s contour; it must remain at a certain radius, on the correct side. It is possible to calculate this equidistant path by hand (example 50.15), but this method has two drawbacks: the program applies only to that specific milling cutter, and you cannot adjust the workpiece dimension by changing a single number. With radius compensation, you program the workpiece profile, and the controller automatically calculates the center’s path:

  • G41: left-hand milling cutter relative to the profile, as viewed in the direction of motion. With a clockwise spindle (M03), this results in face milling, the most commonly used method on machining centers (Chapter 27);
  • G42: right-hand milling cutter on the profile, as viewed in the direction of motion; with M03, it performs counter-rotation milling;
  • G40: Cancel compensation;
  • The radius is specified in the offset indicated by D: G41 D01. On the lathe, G41 and G42 use the nose radius R and the direction T of the offset referenced by T (Chapter 6).

Attachment and Detachment

Compensation cannot be enabled suddenly on the profile. It is enabled with an approach movement: a G01 (or G00) block, moving away from the workpiece, during which the controller gradually moves the center of the end mill from the programmed point to a position shifted by one radius. Similarly, at the end, it is turned off with a retraction movement using G40, moving away from the workpiece. Practical rules:

  • Approach and withdrawal are performed using linear movements, never in an arc (on Fanuc, G41 and G42 in a G02 or G03 block trigger an alarm);
  • The approach path must be longer than the cutter's radius and must start from a point where the cutter, when moved by one radius, does not touch the workpiece;
  • It's best to reach the contour line along the extension of the first segment (or with a tangent arc, after the start), and leave a small overlap so that no entry mark remains;
  • Between the start and end points, no blocks are written without movement in the plane (more than one or two in a file, depending on the control): the control would not know in which direction to move the cutter.
S G41 connection A B E G40 retraction milling cutter center programmed profile the control filletsthe edge
Figure 50.14 · The program defines the red profile (A, edge, B). With G41, the milling cutter remains to the left in the direction of motion: during the approach from S, the center shifts by one radius; during the withdrawal toward E, it returns to the programmed point.
Equidistant path (without compensation)
straight segments shifted by r outer arcs: Rc = R + r inner arcs: Rc = R − r
r: radius of the end mill · R: radius of the workpiece arc · Rc: radius traced by the center of the end mill, with the same center as the workpiece arc · all in mm. On an internal arc, R must be greater than r; otherwise, the end mill will not fit: Rc would be zero or negative.
Example 50.15 · The path of the center calculated by hand

A 100 × 60 island with R8 filleted edges, centered on W, is to be contoured with a Ø16 end mill (r = 8). Without compensation, what coordinates should the center of the end mill follow?

Profile: X-axis = ±50 and Y-axis = ±30, R8 arcs with centers at (±42; ±22)
milling center: X-axis = ±(50 + 8) = ±58 and Y-axis = ±(30 + 8) = ±38
External arcs: Rc = 8 + 8 = 16, with the same centers (±42; ±22)
For example, top-left corner: G01 X-58. Y22. Then G02 X-42. Y38. R16.
The center follows a 116 × 76 rectangle with R16 arcs; with G41, however, the profile of the workpiece is defined

If the island also had a pocket with internal R5 fillets, a Ø16 end mill would not be able to machine them: 5 − 8 = −3 mm. The simulation would trigger a collision alarm, and you would need to choose an end mill with a radius smaller than 5 mm—in practice, Ø8 or smaller.

Common Errors

a) inner radius too small milling cutter The cutter radius is larger: material remains or an alarm is triggered b) Shank too short S shank shorter than the radius: the control cannot move the cutter c) wrong side G41 is correct G42 instead of G41: the end mill enters the workpiece by one diameter
Figure 50.15 · Three common errors: the cutter radius is larger than the internal fillet radius, the approach stroke is shorter than the radius, and compensation is applied on the wrong side. In c), the red profile moves to the right, and the workpiece is positioned below it.
  • G41 and G42 swapped: the milling cutter cuts into the workpiece. On the outer contours, one diameter of material is lost (Figure 50.15 c); in the pockets, the milling cutter remains away from the wall.
  • Incorrect or empty D corrector: D00 or a D with the radius of another milling cutter. The workpiece is processed incorrectly without any alarm.
  • Internal radii smaller than the milling cutter and grooves narrower than the diameter: interference alarm, or (if the alarm is disabled) notches in the profile.
  • Attach it directly to the profile or using a brace: a mark on the wall, an alarm, or the first section installed incorrectly.
  • Clearance within the workpiece: If the point after G40 is too close, the end mill will cut into an edge during the clearance pass.

50.10 Canned Cycles, Subprograms, and Parametric Programming

Many machining operations are always the same: a hole, a lathe roughing operation, a thread. The controls group them into cycles: one or two blocks contain the data, and the control generates all the movements on its own. The milling machine’s canned drilling cycles (G81, G82, G83, G73, G84, G85, canceled by G80) are explained in Chapter 28, Section 28.7, with figures and examples. Here we’ll briefly review the lathe cycles.

Multiple lathe cycles: G71, G70, and G76

With G71, the finished profile is described only once, in a series of numbered blocks, and the controller roughs it out in passes parallel to the Z-axis, leaving an allowance for finishing. Then, G70 passes over the same profile just once, for finishing. On the most common Fanucs, the syntax consists of two blocks:

G00 X82. Z2. (PUNTO DI PARTENZA DEL CICLO)
G71 U2.5 R1. (PROFONDITA DI PASSATA SUL RAGGIO, RITORNO)
G71 P100 Q200 U0.5 W0.1 F0.3 (PROFILO DA N100 A N200, SOVRAMETALLI)
N100 G00 X40.
G01 Z-30.
X60.
Z-70.
N200 X82.
G70 P100 Q200 (FINITURA DEL PROFILO)

In the first block, U is the depth of cut on the radius and R is the retraction at the end of the pass; in the second block, P and Q are the numbers of the first and last blocks of the profile, U is the allowance in the X direction (at the diameter), and W is the allowance in the Z direction. Cycle G72 performs the same operation for passes, for short and wide workpieces. On Siemens machines, roughing a profile is done with CYCLE95 or CYCLE952; on Heidenhain machines, it is done with their turning cycles.

starting point Δd roughing passes finished profile (from N100 to N200) allowance U, W blank
Figure 50.16 · The G71 cycle: the controller cuts in passes of depth Δd (shown in light red) up to the shifted allowance profile (red dashed line); then G70 finishes the final profile. Cross-section above the axis.

The G76 threading cycle performs all the passes of a thread, with decreasing depths as described in Chapter 26 (Section 26.11), typically entering along the flank. In the Fanuc two-block format: the first block contains the number of finishing passes, the exit chamfer, and the thread angle (P); the minimum pass depth (Q, in µm); and the finishing allowance (R); the second contains the root diameter X, the thread end Z, the thread height P, and the depth of the first pass Q—both on the radius in micrometers—and the pitch F. On Siemens machines, CYCLE99 (or CYCLE97) is used.

Example 50.16 · The G76 block for the M20 × 2.5 screw

Let’s revisit the screw from Example 26.13: P = 2.5 mm, h3 = 0.6134 · P, 8 passes, thread length 30 mm, two finishing passes, minimum depth 0.1 mm, allowance 0.05 mm.

h3 = 0.6134 × 2.5 = 1.534 mm → P1534
bottom diameter: 20 − 2 × 1.534 = 16.93 mm → X16.93
First pass: 1.534 · √(1/8) = 1.534 · 0.3536 = 0.542 mm → Q542
G97 S1590 M03 (GIRI COSTANTI, MAI G96 IN FILETTATURA)
G00 X22. Z5. (PARTENZA QUALCHE PASSO PRIMA DEL PEZZO)
G76 P020060 Q100 R0.05 (2 FINITURE, SMUSSO 0, 60 GRADI)
G76 X16.93 Z-30. P1534 Q542 F2.5 (FONDO, LUNGHEZZA, ALTEZZA, 1A PASSATA, PASSO)
G76 X16.93 Z-30. P1534 Q542 F2.5: the controller calculates the number of passes automatically

Note the difference: on the Fanuc G76 milling machine, it refers to fine boring (Chapter 28). The same number, on two different machines, means different things.

Subprograms

A subprogram is a section of code written once and called whenever needed: an outline to be machined during roughing and finishing, or a series of holes to be repeated on multiple workpieces. On Fanucs, it is called with M98 P.. (for example, M98 P5003 executes O5003; M98 P35003 on most common models executes it three times) and is terminated with M99, which returns to the block following the call. On Siemens machines, the subprogram has a name; it is called by typing the name (with P3 to repeat it three times) and ends with M17 or RET. An example is provided in section 50.11.

Parametric Programming

In parametric programming, variables are used instead of numbers, along with operations, trigonometric functions, conditions, and cycles. On Fanucs (B-macros), variables are written as #1, #2..., while on Siemenss, parameters such as R1, R2... or named variables are used. This is used for families of workpieces (a single program for multiple sizes), for shapes calculated using a formula, and for custom cycles: the probing cycles in Chapter 37 are macros written in this way.

Example 50.17 · Six holes on a circle

Six equally spaced holes on a pitch diameter of 80 mm, with the center at W, the first at 0°. Calculate the coordinates and write the same thing using a macro.

angular increment: 360° / 6 = 60° · radius 40 mm · X = 40 · cos α, Y = 40 · sin α
ForumαX (mm)Y (mm)
10°40,0000,000
260°20,00034,641
3120°−20,00034,641
4180°−40,0000,000
5240°−20,000−34,641
6300°20,000−34,641
G99 G81 X40. Y0 Z-12. R2. F110 (PRIMO FORO, CICLO ATTIVO)
#1=1 (CONTATORE)
WHILE[#1LT6]DO1
#2=#1*60 (ANGOLO IN GRADI)
X[40*COS[#2]] Y[40*SIN[#2]] (IL CICLO SI RIPETE QUI)
#1=#1+1
END1
G80
Coordinates in the table; with the macro, simply change 6, 60, and 40 for another drilling

Many CNC systems also have a dedicated cycle for circumferential holes (Siemens HOLES2), and the CAM software calculates the coordinates on its own. The macro is still useful for understanding the process and for cases not covered by the cycles.

50.11 Two Complete Programs

Let's put together the chapter on two workpieces: one on the lathe and one on the milling machine. The programs are written in Fanuc syntax; the coordinates are calculated in the examples, and the cutting parameters are taken from Chapters 26, 27, and 28.

The spindle on the lathe

This is the pin from Example 26.14: a C45 bar with a diameter of 80, a pin with a diameter of 62 and a length of 120 mm, with a surface roughness of Ra 1.6 µm, to which we add a 1 × 45° chamfer on the edge. The blank protrudes 1 mm beyond the finished face, which is the work zero (Z0). Two tools: T01 roughing tool with a nose radius of 0.8 for facing and roughing, and T03 finishing tool with a nose radius of 0.8 and tip direction 3.

dashed line: roughing at Ø74.2 · Ø68.4 · Ø62.6 down to Z−119.8 red: finishing with G42, P1 → P2 → P3 → P4 P1 P2 P3 P4 120 Ø62 · C45 · Ra 1.6 chamfer1 × 45° W
Figure 50.17 · Half-section view of the pin to scale (1 mm = 4 px): the 1-mm chamfer is really small. The section between the face of the blank and W (1 mm) is removed by facing.
Example 50.18 · The coordinates of the pivot

Facing: The tool starts outside the workpiece blank at X84 Z0 and moves into the workpiece until it passes beyond the center of the nose radius, to avoid leaving a “bump”: X = −2 × 0.8 = −1.6.

Roughing (example 26.6): three passes of 2.9 mm on the radius, resulting in diameters of 80 − 5.8 = 74.2, then 68.4 and 62.6. In the Z-axis, leave 0.2 mm on the shoulder for finishing: end pass at Z−119.8. At the end of the pass, the tool moves up 6.8 mm along the diameter (X81, X75, X69)—that is, just above the diameter of the previous pass—and retracts without touching the workpiece.

Finishing: The 1 × 45° chamfer runs from X60 Z0 to X62 Z−1. The starting point is taken on the extension of the chamfer, 2 mm before the face: at 45°, for every millimeter in the Z-axis, the radius changes by 1 mm and the diameter by 2 mm.

P1: Z = +2 → X = 60 − 2 · 2 = 56 → (X56; Z2)
P2: end of the chamfer (X62; Z−1) · P3: end of the cylinder (X62; Z−120)
P4: on the shoulder, beyond the blank: (X82; Z−120)
Chamfer control: from P1 to P2, ΔX = 6 of the diameter, i.e., 3 of the radius, and ΔZ = 3 → 45° ✓
Facing at X−1.6; roughing at X74.2, X68.4, X62.6 down to Z−119.8; finishing P1 (56; 2), P2 (62; −1), P3 (62; −120), P4 (82; −120)
%
O5001 (PERNO C45 D62 L120 SMUSSO 1X45)
G21 G18 G40 G99 (MM, PIANO ZX, NIENTE COMPENSAZIONE, MM/GIRO)
T0101 (SGROSSATORE R0.8)
G50 S4000 (LIMITE GIRI)
G96 S180 M03 (VC 180 PER LA SFACCIATURA)
G00 X84. Z0 M08
G01 X-1.6 F0.2 (SFACCIATURA OLTRE IL CENTRO)
G00 Z2.
X74.2
G96 S200 (VC 200 PER LA SGROSSATURA)
G01 Z-119.8 F0.3 (1A PASSATA)
X81.
G00 Z2.
X68.4
G01 Z-119.8 (2A PASSATA)
X75.
G00 Z2.
X62.6
G01 Z-119.8 (3A PASSATA)
X69.
G00 Z2. M09
G28 U0. (X AL RIFERIMENTO)
G28 W0. (POI Z)
T0303 (FINITORE R0.8 DIREZIONE 3)
G96 S250 M03 (VC 250 PER LA FINITURA)
G00 G42 X56. Z2. M08 (ATTACCO SUL PROLUNGAMENTO DELLO SMUSSO)
G01 X62. Z-1. F0.1 (SMUSSO)
Z-120. (CILINDRO D62)
X82. (SPALLAMENTO)
G00 G40 X90. (DISTACCO)
G28 U0. M09
G28 W0.
M30
%

A few observations. The G50 S4000 limit is specified before G96: from the facing position, toward the center, the RPM would rise indefinitely (example 26.3). The finishing operation uses G42 because the chamfer is angled: without nose radius compensation, the radius would be nearly halved (example 6.13), while on straight sections nothing would change. The return to the reference point is done first in the X-axis and then in the Z-axis, so the tool moves away from the workpiece before moving toward the tailstock or turret. With the G71 cycle, the roughing operation would be written in three blocks plus the profile (paragraph 50.10); here, the passes are written out in full so the coordinates are visible.

The plate with the island on the milling machine

On a 116 × 76 × 20 mm C45 blank, leave an island measuring 100 × 60 mm with R8 edges, 5 mm high, and drill four Ø8.5 through-holes spaced 80 × 40. The W zero is at the center of the top face (which remains the face of the island, Z0). The workpiece rests on two parallel supports that do not lie beneath the holes. Three tools: T01, a solid-body Ø16 end mill with 3 cutting edges; T02, a Ø10 center drill at 90°; T03, a Ø8.5 HSS drill.

S A E F W 4 through holes, Ø8.5 at X ±40, Y ±20 island 100 × 60, R8, height 5 blank 116 × 76 × 20 X+Y+
Figure 50.18 · Top view. The contour rotates clockwise (red arrow) with G41: alignment. Entry from S to A, exit from F to E; the red dashed line indicates the center of the milling cutter (which coincides with the edge of the blank).
Example 50.19 · The coordinates and parameters of the plate

Island outline: sides at X = ±50 and Y = ±30; the R8 fillets have centers at (±42; ±22), so the points of tangency are (±50; ±22) on the short sides and (±42; ±30) on the long sides.

Entry and exit: The cutter exits the blank at point S (−75; −50); the edge of the blank is at point X −58, and the cutter has a radius of 8, leaving a clearance of 9 mm. The approach with G41 reaches point A (−50; −40), on the extension of the left side below the island (27 mm long, longer than the radius). The contour ends at F (−50; −10), after a 12-mm overlap on the first segment, and the retract with G40 goes to E (−75; −10).

Is the entire blank machined? With the 8.3 mm roughing cutter, the center is 8.3 mm from the island, and the cutter covers up to 8.3 + 8 = 16.3 mm: the blank protrudes 8 mm on each side ✓. At the corners, the distance from the center of the fillet to the corner of the blank is √(16² + 16²) = 22.6 mm, and the cutter reaches 8 + 8.3 + 8 = 24.3 mm ✓.

Ø16 end mill: roughing Vc 150 → S2980, fz 0.06 → F536 (example 50.11); finishing, Vc 180 → n = 180,000 / (3.1416 × 16) = 3,581 → S3580, fz 0.04 → F = 0.04 × 3 × 3,580 = 429.6 → F430
Centering: 90° drill bit, Ø9.6 chamfer on Ø8.5 hole → depth 9.6 / 2 = 4.8 mm; Vc 20 → n = 20,000 / (3.1416 × 10) = 637 → S640, F = 0.1 × 640 = 64 → F60
Drilling: Vc 25 → n = 25,000 / (3.1416 × 8.5) = 936 → S940; f = 0.12 → F = 0.12 × 940 = 112.8 → F110
depth: thickness 20 + protrusion 1 + tip cone 0.3004 × 8.5 = 2.55 → Z = −(20 + 1 + 2.55) = −23.55 → Z−23.6
Tangents (±50; ±22) and (±42; ±30); S (−75; −50), A (−50; −40), F (−50; −10), E (−75; −10); holes at Z−23.6
%
O5002 (PIASTRA C45 ISOLA 100X60 R8 E 4 FORI D8,5)
G21 G17 G40 G49 G80 G90 G94 (BLOCCO DI SICUREZZA)
T01 M06 (FRESA INTEGRALE D16 Z3)
G54 G00 X-75. Y-50. S2980 M03 (FUORI DAL GREZZO)
G43 H01 Z50. M08
G00 Z2.
G01 Z-5. F300 (DISCESA FUORI DAL PEZZO)
G01 G41 D11 X-50. Y-40. F536 (ATTACCO, D11 = 8,3: SGROSSATURA)
M98 P5003 (CONTORNO DELL ISOLA)
G01 G40 X-75. Y-10. (DISTACCO)
G00 Y-50.
S3580
G01 G41 D01 X-50. Y-40. F430 (ATTACCO, D01 = 8,0: FINITURA)
M98 P5003
G01 G40 X-75. Y-10.
G00 Z50. M09
M05
G91 G28 Z0 (MANDRINO AL RIFERIMENTO IN Z)
G90
T02 M06 (PUNTA A CENTRARE D10 90 GRADI)
G54 G00 X-40. Y-20. S640 M03
G43 H02 Z50. M08
G99 G81 X-40. Y-20. Z-4.8 R2. F60 (CENTRATURE CON SMUSSO D9,6)
X40.
Y20.
X-40.
G80 G00 Z50. M09
M05
G91 G28 Z0
G90
T03 M06 (PUNTA HSS D8,5)
G54 G00 X-40. Y-20. S940 M03
G43 H03 Z50. M08
G99 G83 X-40. Y-20. Z-23.6 R2. Q8. F110 (FORI PASSANTI A SCARICO)
X40.
Y20.
X-40.
G80 G00 Z50. M09
M05
G91 G28 Z0
M30

O5003 (CONTORNO ISOLA 100X60 R8, SENSO ORARIO)
G01 Y22.
G02 X-42. Y30. R8.
G01 X42.
G02 X50. Y22. R8.
G01 Y-22.
G02 X42. Y-30. R8.
G01 X-42.
G02 X-50. Y-22. R8.
G01 Y-10. (SOVRAPPOSIZIONE)
M99
%

The contour rotates clockwise with G41 and M03: this is concentric milling, as in the plate in Chapter 27 (Section 27.14). The same subprogram is used for both roughing and finishing: only the offset changes—D11 with a radius increased by 0.3 mm and D01 with the actual radius. After the first workpiece, measure the island and correct for wear on D01 as in Example 50.9. The tool change point is reached with G91 G28 Z0: in incremental mode, the intermediate point is the current position, so the spindle moves straight up; immediately afterward, return to G90.

🖥️
Try them out in CNC Code. Load O5001 into the lathe simulator and O5002 (with the subprogram) into the milling machine simulator, set the blank and offsets as shown in the examples, and view the toolpath. Then try making a mistake on purpose: remove G42 from the pin finishing operation and look at the chamfer, or enter G42 instead of G41 for the plate. How to load programs and tools is explained in the CNC Code manual.

50.12 From CAD to the Machine: CAM, simulation, and fine-tuning

The programs described in the previous paragraph can be written by hand in just a few minutes. A workpiece with curved surfaces, complex pockets, or five axes, on the other hand, requires thousands of points: that’s where CAM (Computer-Aided Manufacturing) comes in. The complete process is as follows:

  • CAD: The 3D model of the workpiece is drawn (or received from the customer, often in STEP format);
  • CAM: The blank, clamping, tools, and machining operations (planing, roughing, finishing, drilling) are defined; the program calculates the toolpaths in a neutral format that is independent of the machine;
  • post-processor: a small program—unique to each combination of machine and control system—converts neutral paths into that machine’s G-code: correct codes, number formatting, tool changes, cycles, and axis limits. An incorrect post-processor produces incorrect programs even when used with a perfect CAM system;
  • program simulation and verification;
  • Transfer to the machine (network, USB flash drive, memory card; for very long programs, continuous transmission, DNC) and setup.
CAD3D model CAMtoolpaths Post-processorG-code SimulationCollisions and Dimensions MachineSetup If something goes wrong, it’s corrected in the CAM software, not on the machine
Figure 50.19 · The path of a program created with CAM. Simulation is the stage where errors are least costly.

Why Do People Pretend?

An error detected on the screen costs one minute; the same error detected on the machine can cost a tool, a workpiece, or a spindle. Simulation allows you to see this in advance:

  • Collisions: tool or tool holder against clamps, vise, chuck, or tailstock; rapid movements that cross the workpiece; a tool that is too short to reach the bottom of a pocket;
  • dimension errors: a wrong sign, one coordinate too many or too few, a G91 command that remained active, a missing decimal point, an arc drawn in the wrong direction, compensation applied to the wrong side;
  • the remaining material and the empty cuts, by comparing the simulated workpiece with the model;
  • machining operations, for the estimate and for planning (Chapter 30).

Simulation is performed in the CAM software, on the machine’s control panel (displaying the toolpath graphics while the machine is stopped), or using a separate simulator that reads the actual G-code—the code output by the post-processor. This is the role of a simulator like CNC Code: you write or load the program, set the blank stock, tools, zero points, and offsets just as you would on the machine, and watch the workpiece take shape, block by block. It’s also the most cost-effective way to learn: you can intentionally make mistakes with G41 and G42, forget G43, or reverse an arc and see what happens—all without breaking anything.

Machine Tuning

Even a simulated program should be tested with caution the first time, because the simulation doesn't account for zeroing errors, incorrectly entered correction values, or misaligned brackets. The typical sequence:

  • Data verification: tools mounted in the correct positions, length and radius offsets, workpiece zero; a tool is moved in MDI to a position above zero (for example, G54 G00 X0 Y0, followed by G43 H01 Z50.) and visually checked to see where it stops;
  • dry run: the program runs without a workpiece, or with the zero point shifted upward by 50–100 mm, at a fixed feed rate; this allows for checking paths and clearance dimensions;
  • Single block: The controller executes one block at a time and then pauses; the screen displays the next block and the “distance to travel” before pressing Start. With the optional stop feature enabled, the controller also pauses at M01 points;
  • override: the feed selector (usually from 0 to 150%, sometimes up to 200%) and the rapid traverse selector (often in steps: F0, 25%, 50%, 100%) reduce speeds without changing the program; during the initial approaches, keep rapid traverse at 25% and your hand near the feed hold button. A selector also adjusts the spindle speed, usually from 50 to 120%;
  • First workpiece: Work the part with an allowance of a small amount of excess material; for example, with the finisher’s wear set to +0.2 mm on the diameter or radius. Measure the workpiece, correct for wear (examples 50.8 and 50.9), and repeat the finishing process. The first acceptable workpiece is inspected in its entirety, using the measurement report (Chapter 38).
Actual Speed with Override
Feff = F · o100
Feff: actual speed in mm/min · F: programmed speed (or machine rapid traverse) in mm/min · or percentage from the override selector
Example 50.20 · First attempt with the override

For the first workpiece on the plate, roughing the outline (F536) is tested with a 50% override; the machine has a rapid traverse speed of 30 m/min, and the rapid traverse override is set to 25%. What are the actual speeds? And how much space is needed to stop the axis during rapid traverse, with a deceleration of 3 m/s²?

Work: Feff = 536 × 50 / 100 = 268 mm/min
Quick calculation: 30,000 · 25 / 100 = 7,500 mm/min = 7.5 m/min = 0.125 m/s
Braking distance from reduced speed: s = 0.125² / (2 × 3) = 0.0026 m = 2.6 mm (from full speed, 0.5 m/s: 41.7 mm, Chapter 9)
268 mm/min during machining, 7.5 m/min in rapid traverse: the axis stops in less than 3 mm instead of 42

50.13 Five axes, multitasking, interpolator, and look-ahead

Five-axis machines

In addition to the three translations X, Y, Z, two rotations are added—for example, a rotating table C and a tilting table A (“table-table” machine), or a tilting head B and a rotating head C (“head-head”), or one rotation on the head and one on the table. There are two ways to work:

  • 3+2 (five axes positioned): The rotary axes orient the workpiece or tool and remain stationary, after which machining is performed on three axes on a tilted plane. Five sides of a workpiece are machined in a single setup, using short, rigid tools. The control rotates the coordinate system on the tilted plane: on Fanucs using G68.2, on Siemens using CYCLE800, and on Heidenhains using PLANE;
  • Five continuous axes: All five axes move together, and the tool changes its angle as it cuts. They are used for impellers, blades, deep-drawn dies, and complex surfaces, almost always with CAM.

When a rotary axis rotates, the tool tip shifts because it is offset from the center of rotation. The RTCP (Rotation Tool Center Point, also known as TCP or TCPM) function causes the control to compensate for this offset by moving the X, Y, and Z axes: the program specifies the tip position and the tool’s orientation, and the machine calculates the rest. On Fanuc machines, it is activated with G43.4 (or G43.5); on Siemens machines, with TRAORI; and on Heidenhain machines, with M128 or FUNCTION TCPM. Without RTCP, the program would have to be recalculated for each tool length.

Without RTCP: the tip moves with RTCP: the tip remains stationary 30° ΔX = 125 mm ΔZ = 33.5 O-pin X and Z move the pin by −125 and −33.5 mm
Figure 50.20 · Head tilted 30° with 250 mm between the pivot pin and the tip (scale: 1 mm = 0.8 px). Without RTCP, the drill bit comes off the workpiece; with RTCP, the control moves the pivot, and the drill bit remains on the workpiece.
Moving the tip by rotating the head
ΔX = Lp · sin β ΔZ = Lp · (1 − cos β)
Lp distance from the center of rotation of the head to the tip of the tool (length of the head plus length of the tool), in mm · β angle of inclination · ΔX lateral displacement of the tip · ΔZ tip rise, in mm
Example 50.21 · How far does the tip move when tilted 30°?

On a head-to-head setup, the distance between the center of rotation B and the tool tip is 250 mm. The head is tilted by 30°.

ΔX = 250 · sin 30° = 250 · 0.5 = 125.0 mm
ΔZ = 250 · (1 − cos 30°) = 250 · (1 − 0.8660) = 33.5 mm
Without RTCP, the tip ends up 125 mm to the side and 33.5 mm higher; with RTCP, the controller moves the X and Z axes by the same amount in the opposite direction

Multitasking Machines

Multitasking machines (or lathes-milling machines) perform turning, milling, and drilling operations on the same workpiece, often from all sides. They feature a C-axis on the spindle, powered tools, sometimes a Y-axis and a tilting milling machine (B-axis), a sub-spindle that re-clamps the workpiece to machine the second side, and two or more turrets that operate together. The control system has multiple channels, one per axis group, each with its own program; the channels are synchronized using wait codes (on Fanuc, M-codes selected by the manufacturer; on Siemens, WAITM codes). The workpiece emerges as a finished part from the bar in a single cycle: no repositioning, fewer positioning errors, but more complex programs, where collision simulation becomes essential.

Interpolator, Look-Ahead, and Accelerations

The interpolator is the part of the control system that transforms each block into a sequence of positions. At each interpolation cycle—which, in modern control systems, lasts a millisecond or less—it calculates the next point along the path and sends the new positions to the actuators, which track them using their control loops (Chapter 48). A straight line or an arc thus becomes a sequence of very small steps.

Interpolator Step Size and Short Block Limit
Δs = F · Tipo60 Fmax = Lb · Nb · 60
Δs distance traveled during an interpolation cycle, in mm · F feed rate in mm/min · Tipo interpolation cycle duration in s · Fmax maximum feed rate that the control system can maintain, in mm/min · Lb Length of each block, in mm · Nb blocks that the controller processes in one second. The 60 changes from minutes to seconds.
Example 50.22 · Blocks Too Short for Feed

A control unit has an interpolation cycle of 1 ms and can process 1,000 blocks per second. The CAM software has divided a surface into 0.05-mm segments, and the program calls for F6000.

interpolator step size: Δs = 6000 × 0.001 / 60 = 0.1 mm per millisecond
Required blocks: At F6000 = 100 mm/s, 100 / 0.05 = 2,000 blocks/s are needed
Possible feed rate: Fmax = 0.05 × 1000 × 60 = 3000 mm/min
The machine does not exceed F3000: the machining time is twice as long as calculated

That is why CAM systems for mold machining have adjustable calculation tolerances and can generate arcs or splines instead of numerous segments, and high-speed controls process tens of thousands of blocks per second.

Furthermore, each movement must accelerate and decelerate within the acceleration limits permitted by the mechanics, as discussed in Chapter 9 (Section 9.4): on short segments, the axis never reaches the programmed speed. If the control system were to stop at the end of every block, a profile consisting of a thousand segments would be a sequence of a thousand decelerations. Look-ahead reads ahead by tens or hundreds of blocks, identifies where the path is nearly straight and where there are edges or tight curves, and decelerates only where necessary, while adhering to the specified acceleration and jerk (the rate of change of acceleration). On Fanucs, it is activated using the contour control functions (G05.1 Q1 or G08 P1, depending on the model); on Siemenss, it is activated using G64 and CYCLE832. The trade-off is that sharp edges are slightly rounded within a set tolerance: where an exact edge is required, precise stopping is used (G09 or G61 on Fanuc machines, G60 on Siemens machines).

50.14 Alarms, Common Errors, and Safety

The control system continuously monitors itself, the drives, and the machine. When something goes wrong, it stops the cycle and displays an alarm with a number and a message; the numbers vary from one manufacturer to another, so the table lists the most common families.

AlarmWhat does that mean?What do you do?
Program error (format, unknown code)A block cannot be interpreted: two Gs from the same group, missing address, R and I J togetherRead the block number and correct the program
Radius Out of Tolerance (Fanuc 020)With I, J, and K, the radius from the starting point and the ending point does not match.Check the points of tangency and the center again (example 50.12)
Interference in CompensationWith G41/G42, the milling cutter cannot follow the profile without cutting into itSmaller cutter, longer shank, profile needs to be revised
OvertravelAn axis has reached its software limit or end stopCheck the workpiece number, offsets, and dimensions; exit the limit in manual mode
Return to reference not executedAfter power-up, the axes with incremental encoders don't know where they areA zero search is performed
Excessive tracking errorThe axis remains too far behind the commanded position: impact, friction, brake, actuationCheck for mechanical or electrical causes before trying again (Chapter 48)
Door open, low air or oil pressure, lubricationPLC alarms: A safety or operational condition has not been metThe condition is restored (Chapter 49)
Absolute encoder battery is deadIf it discharges, the absolute position is lostYou change the battery while the machine is running, as stated in the manufacturer's manual

Many of the most dangerous errors, however, do not trigger an alarm: the control simply executes what is written. The most common ones include a wrong sign for a dimension or a zero, a missing decimal point, a missing G43 or one with the “H” code from another tool, G91 remaining active, G41 mistaken for G42, a positive R value on an arc exceeding half a revolution, G96 without a rotation limit, M03 instead of M04 with a tool mounted upside down, or a rapid feed that crosses a bracket. Simulation and debugging (section 50.12) are specifically designed to detect these errors early on.

CNC Machine Safety

A CNC machine moves on its own, quickly and with great force: safety is designed in multiple layers, as we will see in Chapter 51.

  • Guards and interlocked doors: The cycle does not start automatically when the door is open, and if the door opens, the axes and the spindle stop. In setup mode, with the door open, the machine operates only at reduced speed and with a enable button held down. The door windows are made of polycarbonate and are designed to catch a loose insert or set of jaws; they must not be replaced with just any type of glass.
  • Emergency stop: The red button reduces engine power through safety circuits that are independent of the software.
  • Software overtravel: limits specified in the parameters. The control checks these limits in advance and does not execute a movement that would exceed them: the axis stops first, smoothly. These limits apply only after zero search (or with absolute encoders).
  • Hardware overtravel: electric limit switches beyond the software limits (Chapter 47). If an axis reaches these limits, the drive stops in an emergency. Beyond that are the mechanical stops (stops), the last line of defense.
  • Secure Surveillance Drive systems: safe reduced speed, safe stop, safe torque disengagement, manufactured with certified electronics (Chapter 48).
travel (programmable) software limit limit switch electric stop mechanical ≥ braking distance
Figure 50.21 · The limits of an axis, from the softest to the hardest. There must be at least the axis's braking distance at maximum speed between the electrical limit switch and the mechanical stop.
Braking distance of an axis
s = v²2 · a
s = stopping distance in m · v = axis speed in m/s · a = deceleration in m/s² (Chapter 9)
Example 50.23 · How much space after the limit switch

An axis has a rapid traverse speed of 30 m/min and brakes at 3 m/s² in an emergency. How much space must remain between the electric limit switch and the mechanical stop? How long does the braking last?

v = 30 / 60 = 0,5 m/s
s = 0.5² / (2 × 3) = 0.25 / 6 = 0.0417 m = 41.7 mm
t = v / a = 0,5 / 3 = 0,17 s
You need at least 42 mm, basically with a margin: that's why the limit switches are positioned a few centimeters before the stops.
⚠️
Never disable a safety feature just to make your work more comfortable. Bypassing the door switch, holding the workpiece with your hand while the axis is moving, or getting too close to a rotating spindle while wearing loose gloves or open sleeves are classic causes of injuries involving machine tools. The machine is safe only if all safety guards are functioning properly.

50.15 The Formulas in This Chapter

What Are You Looking For?FormulaUnits
Resolution of an axis with an encoderΔ = p / (N · k)mm
Sled Speed Based on Engine RPMv = nm · pmm/min
Screw ExpansionΔL = α · L · Δtmm
Work zero, one-touchXW = Xc ± r + amm
Spindle Position with G43ZM = ZG54 + Zprog + Lmm
Depth of cut with X as the diameterap = (X0 − X1) / 2mm
Incremental dimensionΔXi = Xi − Xi−1mm
Center of the Arc (G17)I = XC − XS · J = YC − YS · R = √(I² + J²)mm
Radius of the center of the milling cutter along an arcRc = R + r (external) · Rc = R − r (internal)mm
Milling Feed RateF = fz · z · nmm/min
Speed with the overrideFeff = F · o / 100mm/min
Moving the tip by rotating the headΔX = Lp · sin β · ΔZ = Lp · (1 − cos β)mm
Interpolator step sizeΔs = F · Tipo / 60mm
Maximum feed rate with short blocksFmax = Lb · Nb · 60mm/min
Braking distances = v² / (2 · a)m

50.16 Exercises

Try to solve them on your own before looking at the solution. For the block-writing problems, if possible, check your answer using a simulator.

Exercise 1. An axis has a 5-mm-pitch lead screw connected directly to the motor and a 2048-line encoder read in quadrature. What is the resolution? How many revolutions must the motor make to achieve a rapid traverse of 24 m/min?
Solution

Increments per revolution = 2048 × 4 = 8192; Δ = 5 / 8192 = 0.00061 mm (approximately 0.6 µm). Revolutions: 24,000 / 5 = 4,800 rpm.

Exercise 2. A horizontal machining center has a horizontal spindle and a table that rotates around a vertical axis. What are the spindle axis and the table axis called? And what is the name of the shaft that extends from the spindle, parallel to its axis?
Solution

The spindle axis is always Z, so here Z is horizontal. The vertical axis is Y, and the table that rotates around Y is the B axis. The axis parallel to Z is the W axis.

Exercise 3. Using a probe with an effective radius of 2.000 mm, touch the left side of a workpiece while moving in the X+ direction, and read X = −250.480. The W zero must be 30 mm to the right of the edge. What value should be entered for G54 X? And if the right side were touched while moving in the X− direction, reading X = −186.520, how wide is the workpiece?
Solution

Left edge: −250.480 + 2 = −248.480; G54 X = −248.480 + 30 = −218.480. Right edge: −186.520 − 2 = −188.520. Width: −188.520 − (−248.480) = 59.960 mm.

Exercise 4. G54 Z is −400.000. The T05 end mill is 120.500 mm long (offset H05). The program specifies G43 H05 Z100.: to what machine coordinate is the spindle reference line set? Where would the tip go if “G43” were omitted?
Solution

ZM = −400 + 100 + 120.5 = −179.500. Without G43, the control would move the spindle nose to Z100 (i.e., −300 machine), and the tip would be at 100 − 120.5 = −20.5 mm: 20.5 mm inside the workpiece.

Exercise 5. On the lathe, a diameter set to 30.00 mm measures 30.08 mm, and a length from the face to the shoulder set to 18.00 mm measures 18.03 mm. What values should be entered in the compensator?
Solution

X-axis wear = −0.08 (for diameters). The shoulder is 0.03 mm too far from the face: the tool reached Z−18.03, so it must be moved back: Z-axis wear = +0.03.

Exercise 6. A lathe contour passes through the points (X20; Z0), (X30; Z−5), (X30; Z−20), and (X40; Z−30). Write the three movements in incremental form using U and W.
Solution

G01 U10. W-5. · W-15. · U10. W-10.. Verification: Total U 20 = 40 − 20, Total W −30 ✓. The first section is a 45° chamfer (5 mm on the radius and 5 in the Z-axis).

Exercise 7. Find the errors in this milling program (for each line, if there is an error, state what it is and how to correct it):
O0001
G21 G17 G90 G40
T01 M06
G54 G00 X0 Y0 S2000 M03
G00 Z5.
G01 Z-2. F100
G41 G02 X20. Y20. R20. D01
G01 X50 Y20.
G03 X60. Y30. R10. I10.
M30
(FINE
Solution

Line 5: The length correction is missing; enter G43 H01 Z5. (Without it, the tool will get stuck in the workpiece.) Line 7: Compensation does not activate on an arc; first enter a linear approach G41 D01 G01 X.. Y.., then the arc. Line 8: X50 without a decimal point; on a Fanuc with factory settings, this equals 0.050 mm; write X50. Line 9: R and I together; use only R10. or only I.. J.. (here the center is (50; 30), so I0 J10.). Before M30, the clearance with G40 and the Z-axis exit are also missing. Line 11: comment not closed; write (FINE); furthermore, it is not needed after M30.

Exercise 8. The milling cutter is at (0, 0) and must move to (20, 20) along an arc with a radius of 20 and center at (20, 0), G17 plane. Write the block using R and I J.
Solution

Viewed from the center, the starting point is at 180° and the ending point at 90°: the angle decreases, so the direction is clockwise. I = 20 − 0 = 20, J = 0 − 0 = 0. G02 X20. Y20. R20. or G02 X20. Y20. I20. J0.

Exercise 9. A solid-carbed Ø10 end mill with 3 cutting edges is to be used at Vc = 120 m/min and fz = 0.05 mm/tooth. Determine S and F.
Solution

n = 120,000 / (3.1416 × 10) = 3,820 rpm → S3820; F = 0.05 × 3 × 3,820 = 573 mm/min → F573.

Exercise 10. Write the blocks to mill a clockwise contour, with left offset and D02 correction, for a radius 25 pivot with center at W. The cutter is already at the working dimension at point (−45; −30). Start at the point (−25; −15), move to the circle at (−25; 0), complete a full circle, retrace 5 mm, and exit toward (−45; 5).
Solution

The line X = −25 is tangent to the circle at the point (−25; 0): approaching from below along this line, you enter the contour without marks. G01 G41 D02 X-25. Y-15. (approach, along √(20² + 15²) = 25 mm, greater than the radius of the end mill) · Y0 (on the circle) · G02 X-25. Y0 I25. J0 (entire circle: I = 0 − (−25) = 25) · G01 Y5. (overlap along the tangent) · G01 G40 X-45. Y5. (withdrawal). Clockwise with G41 and M03: contouring along an outer contour.

Exercise 11. A control system has an interpolation cycle time of 2 ms. How far does the tool travel in one cycle at F3000? If it processes 500 blocks per second, what is the maximum feed rate for blocks that are 0.1 mm long?
Solution

Δs = 3000 · 0.002 / 60 = 0.1 mm. Fmax = 0.1 · 500 · 60 = 3000 mm/min.

Exercise 12. Write the second G76 block for an M12 × 1.75 screw that is 20 mm long, with 6 passes (h3 = 0.6134 · P, first pass h3 · √(1/6)).
Solution

h3 = 0.6134 × 1.75 = 1.074 mm → P1074; base 12 − 2 × 1.074 = 9.853 mm → X9.853; first pass 1.074 × 0.4082 = 0.438 mm → Q438. Block: G76 X9.853 Z-20. P1074 Q438 F1.75.

Exercise 13. Four holes on a pitch diameter of 60 mm, with the center at W; the first hole is at 45°. Calculate the coordinates.
Solution

Radius 30; 30 · cos 45° = 30 · 0.7071 = 21.213. Holes: (21.213; 21.213), (−21.213; 21.213), (−21.213; −21.213), (21.213; −21.213).

Exercise 14. For the first workpiece, a contour programmed at F800 is tested with a 70% override, and the machine’s rapid traverse (24 m/min) is tested with a 25% override. What are the resulting speeds?
Solution

Work feed: 800 · 70 / 100 = 560 mm/min. Rapid feed: 24 · 25 / 100 = 6 m/min.

Exercise 15. An axis has a rapid traverse speed of 36 m/min and performs an emergency stop with a deceleration of 4 m/s². What is the minimum distance that must be maintained between the electric limit switch and the mechanical stop? With a 20° tilt and 200 mm between the center of rotation and the tip, how far would the tip move without RTCP?
Solution

v = 36 / 60 = 0.6 m/s; s = 0.6² / (2 · 4) = 0.36 / 8 = 0.045 m = 45 mm. Head: ΔX = 200 · sin 20° = 200 · 0.3420 = 68.4 mm; ΔZ = 200 · (1 − cos 20°) = 200 · 0.0603 = 12.1 mm.