So far we have covered the CNC lathe’s structure, axes, coordinate system, cutting tools, cutting values, workholding, tool offsets and workpiece zero. Now we can move on to programming. CNC lathe programming is not just writing G and M codes one after another; the programmer first brings together the drawing, the X–Z coordinates, the tools, the operation sequence, the cutting speed and feed, the tool offsets and the safe approach/retract points, then turns this information into a program the control unit understands.
In this course, programming examples are mostly explained with FANUC-based ISO programming logic, because FANUC systems are common. But the aim is not to memorize every key of a panel; it is to teach the logic of the program: G00, G01, G02, G03, X, Z, S, F, T and many basic M codes work with the same or very similar logic on other control systems too. However, some canned-cycle formats, the tool-call scheme, the G-code groups, the chuck/tailstock/conveyor M codes and the work-zero method can vary by control unit and machine builder; the exact usage must be verified from the machine’s manual.
1. What Is a CNC Program? Program, Block, Word
A CNC program is the set of commands that tells the control unit in what order and under what conditions the part is machined. It contains the program number, line numbers, unit/coordinate system, tool number, speed/cutting speed, spindle direction, coolant, motion commands, X–Z coordinates, feed and program-end commands. Three basic concepts: the program (all commands that machine the whole part), the block (each command line, e.g. G01 X40.0 Z-30.0 F0.20;) and the word (a letter + numeric value, e.g. G01, X40.0, F0.20). A block can consist of the N sequence number, G preparatory function, axis addresses, F feed, S speed, T tool and M auxiliary-function words.
A simple CNC lathe program can look like this:
% O1001 ; G21 ; (metric) G40 ; (comp. cancel) G99 ; (feed per rev) G50 S2500 ; (max speed) T0101 ; (tool + offset) G97 S900 M03 ; (constant speed, spindle CW) M08 ; (coolant on) G00 X52.0 Z2.0 ; (safe approach) G01 Z0 F0.20 ; X0 ; (facing) G00 X42.0 Z2.0 ; G01 X40.0 F0.25 ; Z-30.0 ; G00 X100.0 Z100.0 ; (safe retract) M09 ; M05 ; M30 ; %
2. Basic Addresses
In a CNC program each letter has a specific meaning:
| Address | Meaning | Example |
|---|---|---|
| O | Program number (identity) | O1001 |
| N | Line / sequence number | N10 |
| G | Preparatory function (motion/mode) | G01 |
| X | Diameter-direction coordinate (absolute) | X40.0 |
| Z | Length-direction coordinate (absolute) | Z-30.0 |
| U | Incremental move in X | U-4.0 |
| W | Incremental move in Z | W-20.0 |
| F | Feed (mm/rev or mm/min) | F0.20 |
| S | Spindle speed (rpm/cutting speed) | S900 |
| T | Tool and offset call | T0101 |
| M | Auxiliary function | M03 |
O is the program identity; two programs cannot be saved with the same number on one control. N numbers make the program easier to read, help find a line and mark start/end in cycles; usually given in tens (N10, N20, N30) so a line like N15 can be inserted later. X–Z are absolute, U–W incremental. F is read by the active feed mode (mm/rev in G99, mm/min in G98). S is speed or cutting speed by the active G96/G97. T0101 in the common scheme is station 1 + offset 1 (the exact structure varies by machine).
3. Block End, Percent Sign and Decimal Point
Program lines usually end with ; (block end). In some FANUC programs a % at the start and end marks the program limits in data transfer. The decimal point is very important: X40.0 = 40 mm; in some systems X40 is also read as 40 mm, but in some old parameter setups, without a decimal point the value is read in the smallest input unit. So as a safe habit, dimensions are written explicitly (X40.0, Z-30.0, F0.20); a decimal-point error causes very large coordinate mistakes.
4. Safe Start Line and Modal Codes
A safe start line is used at the beginning to cancel modes left from the previous program; e.g. G21 G40 G99; (metric, comp. cancel, feed per rev). G codes are of two kinds: modal (once written, effective until another code of the same group comes) and one-shot (effective only in the block where written). For example:
G01 X40.0 Z-20.0 F0.20 ; Z-40.0 ; (G01 still active) X50.0 ; (G01 still active)
G01 is written on the first line; even if not repeated on the next lines, the G01 mode stays active, so the moves continue as linear cutting. The absence of a G code on a line does not mean there is no motion mode. Codes in the same modal group replace each other: G00/G01/G02/G03 are one motion group; G96/G97, G98/G99, G40/G41/G42 are their own groups.
5. Basic G Codes
| G Code | Function |
|---|---|
| G00 | Rapid positioning (non-cutting) |
| G01 | Linear cutting move |
| G02 | Clockwise circular move (arc) |
| G03 | Counter-clockwise circular move |
| G04 | Dwell |
| G18 | X–Z working plane |
| G20 / G21 | Inch / Metric unit system |
| G28 | Reference return |
| G40 / G41 / G42 | Nose radius comp. cancel / left / right |
| G50 | Maximum spindle-speed limit |
| G96 / G97 | Constant cutting speed / constant speed |
| G98 / G99 | Feed per minute / per revolution |
G21 is metric (common in Turkey), G20 inch; accidentally running in G20 creates a serious size/crash risk, so it is stated clearly at the start. G18 is the lathe base plane X–Z; G02/G03 arc directions and compensation are read relative to it (usually the default on most lathes).
6. G00 — Rapid Positioning
G00 moves the tool rapidly from one point to another (non-cutting repositioning). Absolute: G00 X50.0 Z5.0;; incremental: G00 U10.0 W5.0;. G00 is not used for cutting: its purpose is not to remove material but to go to a safe point outside the raw stock (e.g. G00 X52.0 Z2.0;), and G01 is used when cutting starts. Entering the part with G00 can cause the tool to crash at high speed, the tip to break, the part to slip and the turret to be damaged.
Motion path: the physical path G00 follows can vary by control/parameter; the X and Z axes may move at different speeds and form a broken path. So it is not enough for only the start/end to be safe; the path between the two points must also be checked (chuck, part, tailstock, holder). Especially with a long boring bar/drill, moving X and Z on the same line rapidly can be risky; the safe method is sometimes to separate the axes:
G00 X100.0 ; G00 Z100.0 ;
Which axis moves first must be decided by the real machine geometry.
7. G01 — Linear Cutting (Straight, Facing, Taper, Chamfer)
G01 moves the tool linearly at the given feed. Format: G01 X... Z... F...;. With G01 you machine straight OD, facing, shoulders, tapers and chamfers.
(Straight OD: from X42 Z2, Ø40 x 30 mm) G01 X40.0 F0.20 ; (plunge to Ø40) Z-30.0 ; (cut to Z-30) (Facing: from X52 Z0, raw Ø50) G01 X0 F0.15 ; (OD to center) (Taper: X30 Z-20 → X40 Z-50) G01 X40.0 Z-50.0 F0.15 ; (two axes synced) (Chamfer: 2x45°, X36 Z0 → X40 Z-2) G01 X36.0 Z0 F0.12 ; G01 X40.0 Z-2.0 ;
In a taper, X and Z change at the same time; the control synchronizes the two axes. In a chamfer, due to diameter programming, a 2 mm radial chamfer corresponds to a 4 mm diameter change in X. Since G01 is modal, it may not be repeated on consecutive lines; in training it can be written explicitly on important moves for readability.


Automatic chamfers and corner radii (FANUC 0i-F)
In the chamfer example above, the start and end points of the chamfer were calculated by hand. FANUC lathe controls can do this calculation themselves: you program the corner as if it were sharp and add the chamfer or radius amount to the block. The FANUC 0i-F lathe manual (B-64604EN-1) offers two ways to do this. Which one is active depends on how the machine builder has set the parameters.
Method 1: chamfer with I/K, corner radius with R. This works only on 90° corners, where a single-axis Z move meets a single-axis X move. Bit 2 (CCR) of parameter 8134 must be 1.
| Corner | Format | Sign follows |
|---|---|---|
| Chamfer from a Z move into X | G01 Z(W)_ I±i ; | Direction of the next X move (I+ for +X, I- for -X) |
| Chamfer from an X move into Z | G01 X(U)_ K±k ; | Direction of the next Z move (K+ for +Z, K- for -Z) |
| Corner radius from Z into X | G01 Z(W)_ R±r ; | Direction of the next X move |
| Corner radius from X into Z | G01 X(U)_ R±r ; | Direction of the next Z move |
I, K and R are radius values; K1. means a 1×45° chamfer. If bit 4 of parameter 3405 is 1, the chamfer is given with address C instead of I/K.
(Ø40 x 30 mm, 1x45 chamfer at the end, R2 at the shoulder, 1x45 chamfer on Ø60)
G00 X34.0 Z2.0 ;
G01 Z0 F0.20 ;
X40.0 K-1.0 ; (chamfer on the Ø40 corner, next move -Z)
Z-30.0 R2.0 ; (R2 at the shoulder, next move +X)
X60.0 K-1.0 ; (chamfer on the Ø60 corner, next move -Z)
Z-50.0 ;The block after a chamfer or radius block must be a single-axis G01 move along the other axis. In incremental programming (U, W), the next block is measured from the imaginary sharp corner, not from the end of the chamfer.
Method 2: direct drawing dimension programming (,C ,R ,A). Here chamfers and radii can also be placed between two lines at any angle, and a line’s angle can be given with ,A. It is available when bit 2 (NDD) of parameter 8137 is 0 and works only in memory operation. Coordinates are written in absolute.
G00 X34.0 Z2.0 ;
G01 Z0 F0.20 ;
X40.0 Z0 ,C1.0 ;
X40.0 Z-30.0 ,R2.0 ;
X60.0 Z-30.0 ,C1.0 ;
X60.0 Z-50.0 ;The two methods cannot be used at the same time. If both are enabled, setting bit 0 (CRD) of parameter 3453 to 1 activates direct drawing dimension programming and disables Method 1.
Common alarms (Method 1):
- PS0050: a chamfer or radius was programmed in a threading block.
- PS0051 / PS0052: the block after the chamfer or radius block has no G01 move, moves along the wrong axis, or the sign points the wrong way.
- PS0054: the chamfer or radius was programmed in a block where both axes move (a taper).
- PS0055: the travel in the block is shorter than the chamfer or radius amount.
Use tool nose radius compensation (G41/G42) so that chamfers and radii come out to size. Check the tool path on the graphic screen before the first run; the dimensions in the example are for illustration only.
8. G02 and G03 — Circular Move (Arc)
G02 is clockwise, G03 counter-clockwise circular motion. To program an arc you need the end point, the radius or center info and the direction. The direction is not guessed by looking at the part from the front; it is determined by looking from start to end in the X–Z plane (the turret being front/rear and the screen drawing can mislead). The safest method: mark the start/end point and the center, follow the direction in the X–Z plane, verify with simulation.
(With R: if the radius is known) G03 X40.0 Z-25.0 R5.0 F0.12 ; (With I–K: center incremental from the start point) G02 X... Z... I... K... F... ;
The R method is easy for simple arcs; but for arcs over 180° and when there are two possible solutions, care is needed with the sign rule. I and K are the distances of the arc center from the start point in X (I) and Z (K); whether they are read as diameter or radius must be verified per control system. At the start, simple radii can be shown with R and complex arcs with I–K. Common mistakes: start/end not matching R, writing G03 instead of G02, not checking the active plane and ignoring nose radius compensation.

9. G04, G28 and G40
G04 (dwell): makes the tool/program wait a set time (G04 X1.0; or G04 P1000; — the unit is verified per control). Used for a short dwell at a groove bottom, for the spindle to reach speed or a chuck open/close delay; unnecessary long dwells increase time. G28 (reference return): G28 U0 W0; takes the current position as an intermediate point and sends the axes to reference; it is not safe in every case — if the tool is inside the part, in a hole with a long bar or near the tailstock, it can crash, so retract to a safe point first. G40 (comp. cancel): cancels any previous G41/G42 compensation at the start; G41/G42 select left/right nose radius compensation and are covered in detailed profile programming. In basic first programs, simple straight/perpendicular moves can be done in G40 mode.
10. Using Speed and Feed Codes in the Program
(Constant speed) G97 S900 M03 ; (900 rpm, spindle CW) (Constant cutting speed — limit first!) G50 S2500 ; (max 2500 rpm) G96 S180 M03 ; (180 m/min) (Feed per revolution) G99 ; G01 Z-30.0 F0.20 ; (0.20 mm/rev) (Feed per minute) G98 ; G01 Z-30.0 F150.0 ; (150 mm/min)
Setting a maximum-speed limit with G50 before using G96 is important for safety. G98 and G99 are the same modal group; writing one cancels the other.
11. Basic M Codes
| M Code | Function |
|---|---|
| M00 | Program stop (continue with cycle start) |
| M01 | Optional stop |
| M03 | Spindle clockwise |
| M04 | Spindle counter-clockwise |
| M05 | Spindle stop |
| M08 / M09 | Coolant on / off |
| M30 | Program end and rewind |
M00 stops the program (to check a part, measure); M01 stops only when optional stop is on. M03/M04 is the spindle direction — the wrong direction makes the tip enter the part with its back face and break; “clockwise” can be confused by which side you view the machine from, so the builder’s definition is used. M05 stops the spindle; do not measure the part or open the door before it fully stops. M08/M09 is coolant; on some machines M07/M08 can be different coolant types. M30 ends the program and rewinds.
Machine-specific M codes: chuck open/close, tailstock forward/back, chip conveyor, part catcher, bar feeder, driven tool and sub-spindle M codes vary by builder (M10 might be chuck clamp on one machine and different on another). So when a machine-specific M code is given, this note applies: this M code is an example; check the machine’s M-code table for the exact code.
| Typical M code | Common meaning | Note |
|---|---|---|
| M10 / M11 | Chuck clamp / unclamp | Reversed on some machines; OD/ID clamping direction is selected separately on the panel |
| M14 / M15 (M12 / M13 on some machines) | Tailstock forward / back | Long parts are not machined without tailstock support |
| M19 | Spindle orientation (stop at a fixed angle) | Used with live tooling and sub-spindle transfer |
| M23 / M24 | Thread chamfer on / off | Affects the thread pull-out in G92 and G76 cycles |
| M41 / M42 (M43, M44) | Spindle gear range (low / high) | Gearbox machines only; the available rpm range depends on the gear |
| M98 / M99 | Subprogram call / subprogram end | Standard FANUC, not builder-dependent |
| M103 / M104 / M105 | Sub-spindle CW / CCW / stop | Twin-spindle machines only |
| M110 / M111 | Parts catcher forward / back | Bar-fed production |
These are example codes you may meet on a typical FANUC lathe; everything except M98/M99 is defined by the machine builder in the PMC program, and the same number can do a different job on another machine. The first thing to do on a new machine, before writing any program, is to photograph the M-code table next to the panel.
12. General Order of a Tool Section and Safe Approach
T0101 ; (call the tool) G50 S2500 ; (limit max speed) G96 S180 M03 ; (cutting speed + spindle dir.) G99 ; (feed mode) M08 ; (coolant on) G00 X52.0 Z2.0 ; (safe approach) G01 ... F... ; (cutting moves) ... G00 X100.0 Z100.0 ; (safe retract) M09 ; M05 ; (coolant off, spindle stop)
If the raw stock is Ø50, the tool is not sent straight to G00 X40 Z2; (X40 is inside the raw stock); the safe approach is G00 X52.0 Z2.0; or G00 X55.0 Z3.0;. The retract can be G00 X100.0 Z100.0;, but it must be verified that this coordinate is truly safe (stroke, tailstock, tool length, turret indexing envelope).
13. First Basic Program: Facing + Straight OD Turning
Raw Ø50, target Ø40, length 30 mm, face Z0, tool T0101:
% O1001 ; G21 ; G40 ; G99 ; G50 S2500 ; T0101 ; G97 S900 M03 ; M08 ; G00 X52.0 Z2.0 ; (safe approach: outside raw Ø50) G01 Z0 F0.20 ; (come to the face by cutting) G01 X0 F0.15 ; (facing: OD to center) G00 X52.0 Z2.0 ; (back to a safe point) G01 X40.0 F0.20 ; (plunge to Ø40) G01 Z-30.0 F0.25 ; (cut 30 mm along the length) G00 X100.0 Z100.0 ; (safe retract) M09 ; M05 ; M30 ; %
Line by line: O1001 program number; G21 metric; G40 comp. cancel; G99 feed per rev; G50 S2500 speed limit; T0101 tool+offset; G97 S900 M03 constant speed + spindle CW; M08 coolant. G00 X52 Z2 safe approach 2 mm outside the raw diameter (1 mm radial); G01 Z0 come to the face by cutting; G01 X0 facing. Then plunge to X40 and cut along to Z-30, retract with G00 X100 Z100, end with M09/M05/M30. Warning: Ø50 to Ø40 in one pass is 5 mm radial stock; this program only shows the motion logic, in reality several roughing passes, a finishing allowance or G71 are needed.
14. Stepped-Pass and Profile Programs
Reducing Ø50 to Ø40 not in one pass but in several:
G00 X52.0 Z2.0 ; G01 X46.0 F0.25 ; Z-30.0 ; (rough pass 1) G00 X52.0 ; Z2.0 ; G01 X42.0 ; Z-30.0 ; (rough pass 2) G00 X52.0 ; Z2.0 ; G01 X40.4 ; Z-30.0 ; (final rough diameter) G00 X52.0 ; Z2.0 ; G01 X40.0 F0.12 ; Z-30.0 ; (finish)
Ø46, Ø42, Ø40.4 are roughing passes and Ø40 is finishing. This lengthens the code; later the G71 cycle will do these roughing passes automatically. But the student should first see what the tool does on each pass. Two-step and chamfered profile examples:
(Two steps: Ø40 [Z0..Z-20], Ø30 [Z-20..Z-50]) G00 X42.0 Z2.0 ; G01 X40.0 Z0 F0.15 ; Z-20.0 ; X30.0 ; Z-50.0 ; (Chamfered: 2x45° front chamfer, Ø40, Ø30) G00 X36.0 Z2.0 ; G01 Z0 F0.12 ; X40.0 Z-2.0 ; (chamfer) Z-20.0 ; X30.0 ; Z-50.0 ; (Radiused: X30 Z-20 → R5 → X40 Z-25) G01 X30.0 Z-20.0 F0.12 ; G03 X40.0 Z-25.0 R5.0 ;
These programs define the geometric profile; but as the tool enters radially from X40 to X30 it can remove 5 mm of stock, so the profile should not be machined in one pass without roughing. In the radius, the G03 direction must be checked against the real profile and not run without simulation. So programming and the machining plan are thought of together.
15. A Tidier Program and Comment Lines
% O1002 (SIMPLE OD TURNING) N10 G21 G40 G99 ; N20 G50 S2500 ; N30 T0101 ; N40 G97 S900 M03 ; N50 M08 ; N60 G00 X52.0 Z2.0 ; N70 G01 Z0 F0.20 ; N80 X0 F0.15 ; N90 G00 X52.0 Z2.0 ; N100 G01 X46.0 F0.25 ; N110 Z-30.0 ; N120 G00 X52.0 ; N130 Z2.0 ; N140 G01 X42.0 ; N150 Z-30.0 ; N160 G00 X52.0 ; N170 Z2.0 ; N180 G01 X40.4 ; N190 Z-30.0 ; N200 G00 X52.0 ; N210 Z2.0 ; N220 G01 X40.0 F0.12 ; N230 Z-30.0 ; N240 G00 X100.0 Z100.0 ; N250 M09 ; N260 M05 ; N270 M30 ; %
The (SIMPLE OD TURNING) in parentheses is a comment line; the control does not run it as a command, it makes the program easier to read. Comments can hold info like (T01 OD ROUGHING), (MATERIAL C45), (RAW DIA 50); they inform the operator and ease maintenance. Since non-Latin character support may not exist on every control, plain Latin letters are mostly used in machine programs; very long comments can waste memory on old controls.
16. In-Block Order and Multiple Commands
A block can hold commands from different groups: G97 S900 M03; (speed mode + value + spindle direction) or G01 X40.0 Z-30.0 F0.20; (motion + coordinate + feed). But conflicting G codes from the same group are not written on the same line (G00 G01 X40; is wrong). Although many controls can read words in a different order, a standard, readable order is preferred: N... G... X... Z... U... W... R... F... S... T... M... ;. Each shop may have its own programming standard.
17. Relationship Between Basic Programming and Canned Cycles
In this lesson we write the roughing passes, retract and profile move one by one, so the student sees what the tool does on each pass. Canned cycles automate these moves: for example G71 automatically creates the roughing passes with a set pass depth, following the profile. But to use G71 correctly you must know G00, G01, coordinates and profile logic; so the basic motion codes are learned before cycles.
18. Safe Programming Habits and Common Mistakes
- Write the modes explicitly at the start; do not trust G codes left from the previous program.
- Set S and F again after a tool call; a new tool must not run with the old values.
- Use a G50 limit with G96; keep G00 outside the raw stock (do not cut with G00).
- Verify M codes from the real machine (especially chuck/tailstock/conveyor).
- Check the X and Z signs; one minus error can send the tool into the part.
- Verify the tool offset number; run the first time in single block and low rapid.
Common mistakes: confusing G00/G01 (cutting with a rapid move); expecting G00 while G01 is active (being modal, it moves at cutting feed); forgetting the F value; not checking the G98/G99 mode (F0.20 vs F200 are very different); confusing G96/G97 (S180 = 180 m/min or 180 rpm); choosing the wrong M03/M04 direction; writing X as radius (X20 for Ø40); forgetting the Z minus sign; choosing the wrong G02/G03 direction; not doing a safe retract at the end.
19. Before Running the Program
No example on this page should be run without being checked on the real machine first. Before running, verify the control’s G-code system, tool/offset numbers, workpiece zero, raw diameter, chuck jaws, tailstock position, spindle direction, S and F values, safe approach points and retract paths. The first run is done with graphic check, single block, low-speed motion, low rapid override and a controlled first chip. Programming knowledge does not replace the safety check at the machine.
Video summary of this lesson

When you press play, the video is loaded from YouTube (Google) servers. Watch on YouTube ↗
This 4-minute video walks through the main topics of the lesson: program–block–word structure, basic addresses, G00/G01/G02/G03, speed and feed codes and the basic M codes. At the end, program O1002 turning a Ø50 bar down to Ø40 runs line by line in the simulator. The chapter links start the video at that point.
- 0:24 – Program, block and word
- 0:43 – Basic addresses (O, N, X, Z, U, W, F, S, T, M)
- 1:05 – Modal G codes and the decimal point
- 1:30 – G00 rapid positioning and G01 linear cutting
- 1:56 – G02 and G03 circular interpolation
- 2:17 – G97, G96, G50 and G98 / G99
- 2:41 – Basic M codes
- 3:01 – Example program: O1002 simulation
- 3:40 – Three common mistakes
Lesson Summary
- Program = blocks, block = words (letter + value). Basic addresses: O, N, G, X/Z (absolute), U/W (incremental), F, S, T, M.
- G00 rapid positioning (not cutting), G01 linear cutting, G02/G03 arc; G18 X–Z plane, G21 metric.
- Modal codes stay active until a new code comes; the decimal point and signs are critical.
- G50/G96/G97 and G98/G99 set the speed-feed modes; basic M codes manage the spindle, coolant and program flow.
- A tool section: call → speed/direction → coolant → safe approach → cut → safe retract. An example program is only run under control.
Assessment Test
- Which G code moves the tool rapidly (non-cutting) and is not used for cutting? A) G01 B) G00 C) G02 D) G04
- (True/False) G01 is modal; even without a G code on the next line, the linear-cutting mode stays active.
- Which unit system does
G21select? A) Inch B) Metric C) Feed per revolution D) Constant cutting speed - Which M code stops the spindle? A) M03 B) M08 C) M05 D) M30
- In which direction is G03 circular motion? A) Clockwise B) Counter-clockwise C) Linear D) Rapid positioning
- (True/False) When using G96, the max speed is limited with G50 to prevent a dangerous speed near the center.
- What is the
(SIMPLE OD)in parentheses for? A) A cutting command B) A comment line, not run C) Calls a tool D) Stops the program
Show Answer Key
1) B – G00 is rapid positioning, not used for cutting. 2) True – G01 is modal. 3) B – G21 is the metric system. 4) C – M05 stops the spindle. 5) B – G03 is counter-clockwise. 6) True – G96 needs a G50 speed limit. 7) B – Text in parentheses is a comment; the control does not run it.
Open-Ended Questions
- Explain the concepts of program, block and word with an example.
- Explain the difference between G00 and G01 and why G00 is not used for cutting.
- What does a modal G code mean? Explain with an example.
- Write the general order of a tool section.
- Write a simple program draft that reduces Ø50 raw to Ø40 (roughing + finishing).
Summary and Next Lesson
In this lesson we learned manual programming with basic G and M codes: addresses, the block/word structure, G00/G01/G02/G03, speed-feed modes, M codes and full program examples. You can now turn coordinate, tool, cutting-value and setup knowledge into a real program. In the next lesson we move on to canned cycles (G71, G76, G74) and learn how to automate, with a single command, the roughing passes and thread/groove operations we wrote out one by one here.
Frequently Asked Questions About CNC Lathe Programming
Where should the tool retract at the end of a program: G28 U0 W0, G30, G53 or a fixed G00 point?
All four are used; the differences matter. G28 U0 W0 sends the tool to the machine reference position; U0 W0 makes the intermediate point the current position. If X/Z are written instead of U/W, the tool first moves to that point and then to reference, and that intermediate move can hit the chuck or tailstock. G30 U0 W0 goes to the second reference position, which is stored in a parameter (No. 1241 on the 0i series) and on most lathes is set up as the tool-change position. G53 X_ Z_ moves directly to a machine-coordinate position; it is independent of the work zero but requires G90 and cancelled compensation, and on some controls it is effective only in the block where it is written. A fixed point such as G00 X200. Z200. is relative to the work zero, so its real position on the machine changes whenever the part length or work offset changes. Whichever method you choose, keep the order X out first, then Z back; behaviour varies by control, and the machine manual is the authority.
What is the difference between G28 and G30, and where is the second reference position defined?
G28 returns to the machine’s primary reference position (the zero found with the limit switch). G30 works the same way but its target is the second reference position stored in a parameter; G30 P3 and P4 select the third and fourth reference positions. The second reference is usually the tool-change position where the turret can stand at a safe distance from the chuck and tailstock. The position is set by the machine builder during commissioning; the operator writes G30 U0 W0 in the program and does not change the parameter. On a machine that has not been referenced since power-on, G28 or G30 raises an alarm, which is why the machine is sent to reference first.
What is the G21 G40 G99 G97 block at the start of a program for, and is it mandatory?
This line is called a safety block. Its purpose is to reset modal states that may be left over from a previous program (inch mode, nose-radius compensation still active, feed per minute, constant surface speed) to known values at the start. The control already sets most of these as defaults at power-on, so technically it is not mandatory; but when a program is restarted mid-way, or another program was interrupted, this line prevents a crash. For the same reason it is good practice to state the feed mode (G99 or G98) and the speed mode (G97 or G96) explicitly at the start of every tool section.