With this free G0/G1 basic moves simulator and NC code generator you can enter the stock and target diameters, length and pass depth, and watch a longitudinal turning program written with ONLY G0 and G1 — no canned cycles — in a line-by-line live simulation. Each block is highlighted in the code window as it executes, making it ideal for learning G0/G1 logic, modal commands and safe retraction. For the theory see CNC Lathe Training Lesson 6: Basic Programming (G and M Codes), and for the same job done with canned cycles the G90 Turning Simulator and G71 Rough Turning Simulator.
G0 and G1: the two building blocks of CNC lathe programming
Whatever control you use, ninety percent of a CNC lathe program is made of two commands. G0 (G00) moves the tool from one point to another at the machine's maximum traverse rate without cutting; F is ignored, which is why G0 is used only outside the material. G1 (G01) moves the tool in a straight line at the feed rate given by F and removes material. Canned cycles such as G71, G90 and G94 are combinations of these two commands running in the background; the simulator lifts that cover and shows a job that turns a Ø50 bar down to Ø30 using nothing but G0 and G1, line by line, highlighting each block as it runs. Starting CNC turning programming here is what makes the canned cycles understandable later. For the complete code list see CNC Lathe Training Lesson 6 and the FANUC G and M code list.
G0, G1 and canned cycles: which one when?
| Command | Motion | Needs F? | Where it is used |
|---|---|---|---|
| G0 | Rapid, no cutting | No | Approaching the part, retracting, going to the tool change position |
| G1 | Linear at feed | Yes (modal) | Facing, turning, chamfers, tapers |
| G2 / G3 | Circular | Yes | Radii and arcs |
| G90 / G94 | Single cycle (four moves in one block) | Yes | Steps and faces with few passes |
| G71 / G72 / G73 | Multiple repetitive roughing cycle | Yes | Profile roughing, many passes |
The five-pass job in this tool takes five blocks with G90 and two blocks with G71. Even so, an explicit G0/G1 program is indispensable in three situations: while learning, when a special move is needed that no canned cycle supports, and when a block has to be corrected by hand at the machine.
Using the simulator step by step
- Stock Ø and target Ø: turning a Ø50 bar down to a Ø30 shaft is the default example. The tool places the safe start point 6 mm outside on diameter (X56).
- Length: the length to be turned; with 40 the cut ends at Z-40.
- Pass Δr: depth of cut on the radius. 2 mm means 4 mm on diameter per pass; a 20 mm difference in diameter becomes five passes.
- f and S: feed in mm/rev, spindle speed in rpm. The tool writes G97 constant RPM; while learning, a fixed RPM makes the arithmetic easier to follow.
- The machining sequence panel lists the face cleanup and the passes; press Start Simulation and the active block is highlighted in the code window while the toolpath is drawn on the canvas.
- Copy the code or download the .nc file; the bracketed notes at the end of each block are FANUC-style comments, the control does not read them.
Reading the generated program line by line
With the default values (Ø50 → Ø30, length 40, Δr 2, f 0.2, S 800) the first part of the program and one pass look like this:
O0001
G21 G99 (METRIC, MM/REV)
G97 S800 M03 (SPINDLE ON, CONSTANT RPM)
T0101 M08 (TOOL AND COOLANT ON)
G0 X56. Z10. (SAFE START)
(---- FACE CLEANUP ----)
G0 X56. Z0.5 (APPROACH FACE)
G1 X-2. F0.200 (FACE CUT, PASS CENTRE)
G0 X56. Z1. (RETRACT - SAFE)
(---- PASS 1/5 - D46 ----)
G0 X46. Z1. (PASS 1 - APPROACH)
G1 Z-40. F0.200 (TURN ALONG Z)
G0 X47. Z1. (SAFE RETRACT - X+1MM, Z FORWARD)
(---- PASS 2/5 - D42 ----)
G0 X42. (PASS 2 - APPROACH, Z=1)
G1 Z-40. F0.200 (TURN ALONG Z)
G0 X43. Z1. (SAFE RETRACT - X+1MM, Z FORWARD)
...
(---- PASS 5/5 - D30 ----)
G0 X30. (PASS 5 - APPROACH, Z=1)
G1 Z-40. F0.200 (TURN ALONG Z)
G0 X31. Z1. (SAFE RETRACT - X+1MM, Z FORWARD)
G0 X100. Z200. (END, SAFE POSITION)
M09 (COOLANT OFF)
M05 (SPINDLE STOP)
M30 (PROGRAM END)
%| Block | What it does |
|---|---|
O0001 | Program number: O and four digits on FANUC; the % sign at the start and end of the file is the transmission marker. |
G21 G99 | Metric units and feed per revolution. Without these two, F0.2 could be interpreted as 0.2 mm per minute. |
G97 S800 M03 | Constant 800 rpm, clockwise rotation. At Ø50 the cutting speed is π·50·800/1000 ≈ 126 m/min. |
T0101 M08 | Tool 1 with offset 1; coolant on. |
G0 X56. Z10. | Safe start: 6 mm outside on diameter, 10 mm in front of the face. Both axes move in one block; the machine drives X and Z simultaneously and the path is not necessarily a straight line. |
G1 X-2. F0.200 | Face cleanup: the tool passes centre by 1 mm so no nub is left. F is written once here; the following G1 blocks run at the same F. |
G0 X46. Z1. → G1 Z-40. → G0 X47. Z1. | One pass: approach, cut, retract. On the retract X is first increased by 1 mm so the tool comes back in Z without rubbing the machined surface. |
G0 X42. | From the second pass on, Z is not written; the tool is already at Z1. Modal logic: an axis that is not written stays where it is. |
G0 X100. Z200. … M30 | Retract to the tool change position, coolant off, spindle stop, program rewinds. |
Modal commands and the decimal point: two critical details
On FANUC, G0, G1, F, S and T are modal: once written they stay in effect until changed. That is why, after the second pass, writing just Z-40. instead of G1 Z-40. still moves the tool at cutting feed; the tool writes G0/G1 explicitly on every block for teaching purposes. Within the same group (group 01: G0, G1, G2, G3) a new code cancels the previous one. The second detail is the decimal point: X30. and X30 are not the same thing. Depending on a parameter, a value without a decimal point can be read in the least input increment (microns); X30 would mean 0.030 mm and the tool would plunge into the part. This is why the habit of writing every coordinate with a point exists, and why the tool generates all values as X46., Z-40..
Is X a diameter or a radius? When to use U and W
On a lathe the X axis is programmed as a diameter: when you write X46 the tool tip is 23 mm from the centre line. The depth of cut, on the other hand, is thought of on the radius; a 2 mm pass means X drops by 4. This pair is what beginners mix up most often, and it is why the "Pass Δr" field in the tool is labelled as a radius. Incremental U/W can be used instead of absolute X/Z: G1 W-40. means 40 mm along Z from the current position, G0 U-4. means 4 mm inwards on diameter. Incremental programming looks shorter for repeated passes, but one mistake propagates into every following block; absolute coordinates are the safer choice while learning. The axes and zero points lesson is a good companion for coordinate systems.
Safe approach and retract rules
Three habits built into the tool prevent crashes on a real machine. First, when approaching the part with G0, bring X to a value outside the stock diameter before moving Z towards the face; when both axes are written in one block the path the tool takes can cross the chuck or the tailstock, which is why the tool makes its first approach to a point completely outside, such as X56 Z10. Second, clean the face before the longitudinal passes; until the face is flat the Z0 reference is not reliable. Third, at the end of every cut increase X by 1 mm before pulling back in Z; returning straight to Z1 with G0 leaves a rubbing mark on the machined surface. When you run a new program for the first time, single-block mode with the rapid override at 25% shows you where you skipped one of these rules without a crash.
Alarms and problems seen on the shop floor
| Symptom | Cause | Fix |
|---|---|---|
| PS0011 FEED ZERO (COMMAND) | No F given before the first G1 block | Add F to the first G1 block |
| Tool plunged into the part | Decimal point forgotten (X30 = 0.030 mm) or a radius value written as a diameter | Write every coordinate as X30.; X is a diameter |
| Tool crashed into the part under G0 | G0 used inside the material, or a two-axis G0 path crosses the part | X out first, then Z in; always G1 in the cutting zone |
| OT0500/0501 overtravel | End point (X100 Z200) exceeds the machine stroke | Reduce the end point relative to the reference position |
| Spiral rubbing mark on the surface | Retract made in Z without increasing X first | X+1 mm on retract, then Z |
| Size drifts every pass | One faulty block in U/W incremental programming | Use absolute X/Z or correct the block |
| Feed far too slow or too fast | G98 (mm/min) mixed up with G99 (mm/rev) | Write G99 at the start of the program |
Six common mistakes
- Writing F on a G0 block; harmless, but it shows you do not know G0 ignores F. The rapid move does not slow down.
- Leaving out G21 G99 at the start; the machine remembers the last state, and the previous program's G98 turns your F0.2 into 0.2 mm per minute.
- Skipping the face cleanup and turning straight away; if the raw face is uneven the length dimension will be wrong.
- Writing comments after a semicolon; on FANUC ";" is the end-of-block character, comments go inside parentheses.
- Moving Z first when going to the tool change position; on a large-diameter part the tool can rub the tailstock or the part, so X first, then Z, or both together on a safe path.
- Not checking M03/M04 against the way the tool is mounted; reversed rotation breaks the insert.
Frequently asked questions
Is there a difference between G0 and G00?
No. FANUC ignores leading zeros; G0, G00 and G000 are the same command, and the same applies to G1/G01 and M3/M03. Some older controls and some Siemens/Heidenhain systems expect the two-digit form; writing G00/G01 is harmless and more portable.
Why is a G0 move not necessarily a straight line?
Under G0 each axis is driven independently at its own rapid rate; because X and Z run at different speeds the path can be a dog-leg (unless linear interpolation for rapids is selected with parameter 1401). G1 is always a straight line. So when passing the part with G0, assume you do not know where the path goes and approach in two steps.
Why does the facing cut go to X-2?
The tool tip has a nose radius; stopping exactly at X0 leaves a small nub at the centre. Passing centre by twice the nose radius (X-1.6 for a 0.8 mm nose, rounded to X-2 in the tool) removes it. If G96 were used, limiting the RPM with G50 would be essential here; the tool uses G97 constant RPM, so there is no problem.
Can I run this program on a real machine?
Structurally yes, but first verify the tool offsets, the workpiece zero, that the end point lies within the machine stroke and that the cutting data suits your material; then dry-run it and machine the first part in single-block mode. The tool writes general teaching values; catalogue data always takes priority.