Exercises & Assessment
Reading and understanding code is the skill that prevents crashes. These 20 exercises test coordinate systems, G-code, offsets, cycles, compensation, and program structure. Work through them without looking at the answers first.
Part 1 — Knowledge Check (Questions 1–8)
- What does G01 do, and how is it different from G00?
Answer
G01 is linear interpolation at a controlled feed rate F — the tool cuts in a straight line at the programmed feed. G00 is rapid positioning at machine maximum speed, used for non-cutting moves, and does not use F for cutting.
- What is G54?
Answer
G54 is the first work coordinate system offset (work zero). It shifts the coordinate origin from machine zero to the workpiece datum, so the programmer can use part coordinates instead of machine coordinates.
- What is the difference between G90 and G91?
Answer
G90 = absolute programming: every coordinate is measured from the work zero. G91 = incremental programming: every coordinate is measured from the current tool position. G90 X50 means "go to X50"; G91 X50 means "move 50 mm in X."
- What does G41 do?
Answer
G41 activates cutter radius compensation to the left of the programmed direction. The machine offsets the tool center by the radius stored in the D code, so you program the part outline rather than the tool center path.
- On a lathe, what does X40 mean?
Answer
X40 means the tool is positioned at a 40 mm diameter, not 40 mm radius. The actual radial position is 20 mm from center. Radial depth of cut = (X_start − X_end) / 2.
- What does G80 do?
Answer
G80 cancels all canned drilling cycles. It stops the modal cycle mode; after G80, subsequent X/Y/Z motion is explicitly controlled by G00/G01 rather than by an active cycle. Note: G80 does not retract Z — write G00 Z50 explicitly. On Haas, a G00 or G01 motion also cancels the cycle, but writing G80 explicitly makes the intent clear.
- What is the difference between G98 and G99 in a drilling cycle?
Answer
G98 retracts to the initial Z plane (the height before the cycle was called). G99 retracts only to the R plane. Use G99 for holes with no obstructions between them; use G98 when there is a boss, clamp, or feature to clear.
- Why program G21 G17 G90 G40 G49 G80 at the start of a program?
Answer
To establish a known machine state: G21 = metric units, G17 = XY plane, G90 = absolute programming, G40 = cancel compensation, G49 = cancel tool length offset, G80 = cancel cycles. It prevents inherited modal states from a previous program.
Part 2 — Code Reading (Questions 9–12)
9. Trace this program. Where does the tool end up at the end?
G90 G54 G00 X20. Y20.
G43 H01 Z50. M03 S2000
G01 Z-2. F100.
G01 X80. F300.
G00 Z50.
G00 X0 Y0
M30
Trace
1. Rapid to XY (20,20). 2. Spindle on at S2000, rapid to Z50 with tool length offset H01. 3. Feed down to Z−2 at 100 mm/min. 4. Feed to X80 (Y stays at 20) at 300 mm/min. 5. Rapid up to Z50. 6. Rapid to X0 Y0. 7. Program end. Tool ends at X0 Y0 Z50.
10. What does this subprogram call do? How many times does it run?
M98 P2000 L5
Answer (Haas)
P2000 calls subprogram O2000; L5 repeats it five times. If O2000 drills one hole at the current XY, this line calls O2000 five times at the same XY — repeat count alone does not create five different hole positions. The caller must reposition XY before each call to drill at different locations.
11. Read the turning program. What diameter does it end at?
G00 X50. Z2.
G01 Z0 F0.2
X45.
Z-30.
X52.
Trace
Approach at X50 Z2. Feed to Z0. Step to X45 (now cutting Ø45). Turn along Z to Z−30 at Ø45. Step out to X52. The turned diameter is Ø45 over the length Z0 to Z−30.
12. After this line, what mode is the machine in?
G99 G83 R2. Z-15. Q3. F120.
Answer
Peck drilling cycle (G83) is active, modal. Retract mode is G99 (return to R2 after each hole). The cycle stays active until G80 or another documented cancelling motion command (such as G00/G01 on Haas). The next X/Y line will peck-drill at that position.
Part 3 — Find the Error (Questions 13–16)
13. This program has a bug. What happens?
G90 G54 G00 X0 Y0
G43 H01 Z50.
G01 Z-5. F100.
G01 X50.
G41 D05
G01 X80. Y30.
G00 Z50.
M30
Diagnosis
G41 is engaged at Z−5 while already inside material, without a lead-in move from outside the part. There is no G40 at the end to cancel compensation. There is also no startup block (G21, G17, G94, G80, G49). G41 must be engaged on a lead-in move from outside the stock, not mid-cut.
14. On a Haas, after the last hole at (50,50), this program uses G00 Z50. without writing G80. Does the machine continue drilling? How can the exit state be made clearer?
G90 G54 G00 X10. Y10.
G43 H01 Z50. M03 S1500
G81 R2. Z-15. F100.
X50. Y10.
X50. Y50.
G00 Z50.
M30
Diagnosis
On Haas, the G00 Z50 motion itself cancels the G81 cycle — the machine will not continue drilling. However, writing an explicit G80 before the Z retract makes the program's intent unambiguous and protects against controller differences. Best practice: add G80 before G00 Z50. This is a clarity issue, not a crash bug.
15. This turning program cuts the wrong diameter. Why?
G00 X30. Z2.
G01 Z0 F0.2
Z-30.
X40.
Diagnosis
The tool starts at X30 (Ø30 diameter) and turns along Z to Z−30 without changing X — it cuts a Ø30 shaft, not the intended Ø40. If the goal is to turn from Ø50 to Ø40, the X should start at X50 and step to X40 before the Z move.
16. This tapping program will strip the threads. Why? Assume G94 (feed per minute) is active.
G84 R5. Z-15. F500.
(S500, M10x1.5 tap)
Diagnosis
In G94 mode, F must = pitch × RPM. For M10×1.5 at S500, F = 1.5 × 500 = 750 mm/min, not 500. The feed is too slow for the spindle speed, so the tap does not follow the thread pitch and strips the threads. If G95 were active instead, F would be in mm/rev and F1.5 would be correct — always know which feed mode is active.
Part 4 — Write the Program (Questions 17–20)
17. Drill one Ø8 hole at X30 Y20 to depth Z−12 in aluminum. S1500, F100. Write the program.
Example
O0017
G21 G17 G90 G40 G80 G49
G54
T01 M06 (O8 DRILL)
S1500 M03
G00 X30. Y20.
G43 H01 Z50. M08
G99 G81 R2. Z-12. F100.
G80
G00 Z50. M09
M3018. Turn a raw Ø50 bar to Ø40 over Z−40. Assume mild steel, a CNMG insert, G97 S1000, G99 F0.20 mm/rev. Show layered roughing passes and finishing.
Example
Four roughing passes remove 1.0 mm radially each; the fifth removes 0.8 mm, leaving 0.4 mm on diameter for the finishing pass:
| Pass | Diameter X | Radial depth | Length |
|---|---|---|---|
| Rough 1 | X48 | 1.0 mm | Z2 to Z−40 |
| Rough 2 | X46 | 1.0 mm | Z2 to Z−40 |
| Rough 3 | X44 | 1.0 mm | Z2 to Z−40 |
| Rough 4 | X42 | 1.0 mm | Z2 to Z−40 |
| Rough 5 | X40.4 | 0.8 mm | Z2 to Z−40 (finish stock) |
| Finish | X40.0 | 0.2 mm | S1200, F0.10 |
After each OD pass to Z−40: first retract radially to X52 (clear of the cut), then retract Z to Z2. Never move X and Z simultaneously in a G00 sweep across uncut material.
O0018
G21 G97 G99
T0101 (OD tool, r0.4)
S1000 M03
G00 X52. Z2.
(FACE - ESTABLISH Z0)
G01 Z0 F0.2
X-1.0 F0.15
G00 Z2.
G00 X52.
(ROUGH 1 - O48, 1.0mm radial)
G00 X48. Z2.
G01 Z-40. F0.2
G00 X52.
Z2.
(ROUGH 2 - O46)
G00 X46. Z2.
G01 Z-40.
G00 X52.
Z2.
(ROUGH 3 - O44)
G00 X44. Z2.
G01 Z-40.
G00 X52.
Z2.
(ROUGH 4 - O42)
G00 X42. Z2.
G01 Z-40.
G00 X52.
Z2.
(ROUGH 5 - O40.4, leave 0.4mm dia / 0.2mm radial)
G00 X40.4 Z2.
G01 Z-40.
G00 X52.
Z2.
(FINISH - O40.0)
S1200 M03
G00 X40.0 Z2.
G01 Z0 F0.1
Z-40.
G00 X52.
Z100.
M30
Note: 1.0 mm radial per pass is a teaching assumption. Real depth-of-cut limits depend on insert grade, material hardness, machine rigidity, and chip evacuation.
Clearance model (classroom geometry): final face at Z0, original face at Z+1, chuck jaw front at Z−60, raw stock projection 61 mm. Toolholder extends 8 mm behind the tip, so at Z−40 the tool body reaches Z−48, leaving 12 mm axial clearance to the jaw. The X52 retract position must also clear the toolholder body radially outside the chuck and workholding. These values are teaching assumptions, not production recommendations.
19. Four Ø6 holes on a 40 mm square centered at (0,0), at (−20,−20), (20,−20), (20,20), (−20,20). Through holes in 6 mm plate: Z−8. S2000, F120. Write the program.
Example
O0019
G21 G17 G90 G40 G80
G54
T01 M06 (O6 DRILL)
S2000 M03
G00 X-20. Y-20.
G43 H01 Z50. M08
G99 G81 R2. Z-8. F120.
X20. Y-20.
X20. Y20.
X-20. Y20.
G80
G00 Z50. M09
M3020. Milling project: face mill a 60×40 mm rectangular block (X0–60, Y0–40) to Z−2, then drill two Ø5 holes at (15,20) and (45,20) to Z−10. Use Ø10 end mill (T01) and Ø5 drill (T02). S2000 F300 for mill, S1500 F100 for drill. Z0 is the unfinished top surface; after facing, the new top is Z−2.
Example
O0020
G21 G17 G90 G40 G80 G49
G54
T01 M06 (O10 END MILL)
S2000 M03
G43 H01 Z50. M08
(FACE: 5 PASSES TO COVER Y0-40, tool radius 5)
G00 X-6. Y4.
G01 Z-2. F100.
G01 X66. F300. (pass 1: covers Y[-1,9])
G00 Z50.
G00 X-6. Y12.
G01 Z-2. F100.
G01 X66. F300. (pass 2: covers Y[7,17])
G00 Z50.
G00 X-6. Y20.
G01 Z-2. F100.
G01 X66. F300. (pass 3: covers Y[15,25])
G00 Z50.
G00 X-6. Y28.
G01 Z-2. F100.
G01 X66. F300. (pass 4: covers Y[23,33])
G00 Z50.
G00 X-6. Y36.
G01 Z-2. F100.
G01 X66. F300. (pass 5: covers Y[31,41])
G00 Z50. M09
T02 M06 (O5 DRILL)
S1500 M03
G00 X15. Y20.
G43 H02 Z50. M08
G99 G81 R2. Z-10. F100.
X45. Y20.
G80
G00 Z50. M09
M30
The 5 passes at Y=4,12,20,28,36 with a Ø10 tool cover Y0–40 with overlap. A single pass at Y=-5 would only tangent the bottom edge and leave the entire block unmilled.