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.
| What | Traditional machine | CNC Machine |
|---|---|---|
| Axis Movement | handwheels and levers, operated manually or with automatic feeds | servomotors controlled by the control system |
| Curved Profiles and Cones | Difficult: copier, inclined slide, skill | Easy interpolation of two or more axes |
| Repeatability | It depends on the operator | High: The program is always the same |
| Workpiece Change | fast for a single workpiece | You need the program; it's fast even for just a few workpieces. |
| Operator's Work | guides each pass | prepare, reset, check, correct |
| Cost of the car | low | higher, 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).
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.
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.
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.
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?
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.
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).
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?
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.
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).
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.
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.
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.
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.
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.
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).
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).
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).
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).
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.
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.
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.
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 withM30(end and return to the beginning) orM02. - 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 theX20without 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.
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.
| Section | G90 (absolute) | Account | G91 (incremental) |
|---|---|---|---|
| A → B | G01 X70. Y10. | 70 − 10 = 60 · 10 − 10 = 0 | G01 X60. Y0 |
| B → C | Y30. | 0 · 30 − 10 = 20 | Y20. |
| C → D | X50. Y50. | 50 − 70 = −20 · 50 − 30 = 20 | X-20. Y20. |
| D → E | X10. | 10 − 50 = −40 · 0 | X-40. |
| E → A | Y10. | 0 · 10 − 50 = −40 | Y-40. |
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).
| Code | Meaning | Modal | Notes on Lathes/Milling Machines and Siemens |
|---|---|---|---|
G00 | rapid positioning | yes | at the maximum speed of the axes; the path may not be a straight line |
G01 | linear interpolation during machining, feed rate F | yes | the same everywhere |
G02 / G03 | Circular interpolation clockwise / counterclockwise | yes | with R or with I, J, K (paragraph 50.8); Siemens radius with CR= |
G04 | dwell | no | G04 P500 (ms) or X0.5 (s) milling cutter; G04 X0.5 lathe; Siemens G4 F0.5 |
G17 G18 G19 | XY plane, ZX plane, YZ plane | yes | The milling cutter is usually G17; the lathe operates in G18 |
G20 / G21 | dimensions in inches / in millimeters | yes | On Siemens machines, they are G70 and G71: Note that on Fanuc lathes, G70 and G71 are cycles |
G28 | Return to the reference point | no | Move through the intermediate point as specified: G91 G28 Z0, move straight up; lathe G28 U0. W0.; Siemens G74 |
G40 G41 G42 | radius compensation: off, left, right | yes | milling cutter with D; lathe with R and T for the compensators |
G43 / G49 | Active/Canceled Length Correction | yes | milling cutter only (G43 H..); on the lathe, the length is specified in T |
G50 | lathe: maximum speed limit with G50 S.. | yes | On older lathes, with X and Z axes, set the workpiece zero; on a milling machine, it has a different meaning; Siemens LIMS= |
G54...G59 | origins of the workpiece | yes | the same on Siemens (G54-G57, then G505...) |
G70...G76 | lathe: multiple cycles | no | G70 finishing, G71 longitudinal roughing, G72 face milling, G76 threads (section 50.10) |
G80...G89 | milling cutter: canned drilling cycles; G80 cancels them | yes | G81 drilling, G83 milling, G84 tapping... (Chapter 28); Siemens CYCLE81... |
G90 / G91 | milling cutter: absolute / incremental coordinates | yes | On the Fanuc G90 lathe, this is the simple cylindrical turning cycle; incremental turning is performed using the U and W commands |
G94 / G95 | milling cutter: feeds in mm/min / mm/rev | yes | On the Fanuc lathe, G94 is the simple facing cycle; Siemens machines also use G94/G95 on the lathe |
G96 / G97 | Constant cutting speed (S in m/min) / constant RPM | yes | especially lathes (Chapter 26); with G96, the speed limit is always required |
G98 / G99 | lathe: feeds in mm/min / mm/rev | yes | On 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.
| Code | Meaning | Notes |
|---|---|---|
M00 | scheduled stop | The cycle stops; press the start button to resume: to take a measurement, rotate the workpiece, and remove the chips |
M01 | optional stop | It stops only if the “optional stop” button on the panel is lit: useful for the first workpiece |
M03 | horizontal spindle | Looking from the spindle toward the workpiece; for right-hand end mills and standard lathe tools |
M04 | counterclockwise spindle | for inverted tools, left-hand taps, and certain lathes with tools mounted upside down |
M05 | spindle stop | before changing the tool, before measuring |
M06 | tool change | Milling cutter: T05 M06—install tool 5; on the lathe, just use T |
M08 / M09 | Coolant On / Off | M07 is also often used for atomization or as an internal coolant |
M30 | End of program and return to the beginning | Turns off the spindle and coolant and counts the workpiece; M02 is the end point with no return |
M98 / M99 | subprogram call / end of subprogram | M98 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 withG96. It must be entered before or together withM03. The values are calculated using the formulas in Chapters 26, 27, and 28. - F is the feed rate: in mm/min with
G94(milling) orG98(Fanuc lathe), in mm/rev withG95orG99. 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
T05milling machine, tool 5 is retrieved from the tool magazine, andM06mounts 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 theT0505lathe, the turret rotates to tool 5 and activates offset 5.
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?
S2980F536 (in G94)G99 F0.25 is equivalent to G98 F300 as long as the speed remains at 1200)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.
- 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.
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.
G03G03 X10. Y30. R20. or G03 X10. Y30. I-20. J0
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).
G02 X40. Y0 I-15. J0 (this isn't possible with R)
Center (0; 0), radius 20: from (20; 0) to (0; −20) counterclockwise, passing through (0; 20) and (−20; 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.
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; withM03, it performs counter-rotation milling;G40: Cancel compensation;- The radius is specified in the offset indicated by D:
G41 D01. On the lathe,G41andG42use 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.
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?
G01 X-58. Y22. Then G02 X-42. Y38. R16.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
- 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.
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.
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.
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.
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.
| Forum | α | X (mm) | Y (mm) |
|---|---|---|---|
| 1 | 0° | 40,000 | 0,000 |
| 2 | 60° | 20,000 | 34,641 |
| 3 | 120° | −20,000 | 34,641 |
| 4 | 180° | −40,000 | 0,000 |
| 5 | 240° | −20,000 | −34,641 |
| 6 | 300° | 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 G80Coordinates 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.
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.
% 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.
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 ✓.
% 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.
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.
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 byG43 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
M01points; - 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).
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²?
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 usingCYCLE800, and on Heidenhains usingPLANE; - 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.
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°.
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.
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.
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.
| Alarm | What 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 together | Read 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 Compensation | With G41/G42, the milling cutter cannot follow the profile without cutting into it | Smaller cutter, longer shank, profile needs to be revised |
| Overtravel | An axis has reached its software limit or end stop | Check the workpiece number, offsets, and dimensions; exit the limit in manual mode |
| Return to reference not executed | After power-up, the axes with incremental encoders don't know where they are | A zero search is performed |
| Excessive tracking error | The axis remains too far behind the commanded position: impact, friction, brake, actuation | Check for mechanical or electrical causes before trying again (Chapter 48) |
| Door open, low air or oil pressure, lubrication | PLC alarms: A safety or operational condition has not been met | The condition is restored (Chapter 49) |
| Absolute encoder battery is dead | If it discharges, the absolute position is lost | You 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).
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?
50.15 The Formulas in This Chapter
| What Are You Looking For? | Formula | Units |
|---|---|---|
| Resolution of an axis with an encoder | Δ = p / (N · k) | mm |
| Sled Speed Based on Engine RPM | v = nm · p | mm/min |
| Screw Expansion | ΔL = α · L · Δt | mm |
| Work zero, one-touch | XW = Xc ± r + a | mm |
| Spindle Position with G43 | ZM = ZG54 + Zprog + L | mm |
| Depth of cut with X as the diameter | ap = (X0 − X1) / 2 | mm |
| Incremental dimension | ΔXi = Xi − Xi−1 | mm |
| 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 arc | Rc = R + r (external) · Rc = R − r (internal) | mm |
| Milling Feed Rate | F = fz · z · n | mm/min |
| Speed with the override | Feff = F · o / 100 | mm/min |
| Moving the tip by rotating the head | ΔX = Lp · sin β · ΔZ = Lp · (1 − cos β) | mm |
| Interpolator step size | Δs = F · Tipo / 60 | mm |
| Maximum feed rate with short blocks | Fmax = Lb · Nb · 60 | mm/min |
| Braking distance | s = 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.
Solution
Increments per revolution = 2048 × 4 = 8192; Δ = 5 / 8192 = 0.00061 mm (approximately 0.6 µm). Revolutions: 24,000 / 5 = 4,800 rpm.
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.
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.
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.
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.
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).
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.
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.
Solution
n = 120,000 / (3.1416 × 10) = 3,820 rpm → S3820; F = 0.05 × 3 × 3,820 = 573 mm/min → F573.
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.
Solution
Δs = 3000 · 0.002 / 60 = 0.1 mm. Fmax = 0.1 · 500 · 60 = 3000 mm/min.
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.
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).
Solution
Work feed: 800 · 70 / 100 = 560 mm/min. Rapid feed: 24 · 25 / 100 = 6 m/min.
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.
