Tutorial

Learn ClearNC from first principles to 5-axis & mill-turn

Nine lessons in real ClearNC v1 syntax — from units and 2D geometry to 3-axis milling, lathe turning, multi-setup G68, 5-axis RTCP and mill-turn across 55 verified machines and 9 native controller dialects. Every program runs 100% locally in the browser Studio workspace.

Lesson 01 · Foundations

Program Structure, Units & Safety Assertions

Every ClearNC file starts with a version header (clearnc v1) and a program block declaring the machine flavor (mill_3axis or lathe), unit system, and workpiece material. Shared dimensions live in params and are guarded by compile-time assert invariants.

ClearNC sensor_bracket_mill3.cnc — Header, Params & Assertions
clearnc v1

program "Sensor_Bracket_VMC" {
  flavor:   mill_3axis
  units:    metric
  material: "6061-T6" (95 HB)
  author:   auto_cam
}

params {
  part_x        = 140mm
  part_y        = 90mm
  part_h        = 22mm
  stock_top_alw = 1.5mm
  carrier_tab   = 5.0mm
  pocket_depth  = 12mm
  wall_alw      = 0.25mm
  floor_alw     = 0.15mm
}

assert (part_h - pocket_depth) >= 6mm : "Pocket floor thickness must stay >= 6mm"

Physical Unit Literals

ClearNC refuses bare dimensionless numbers where physical units are required. The compiler checks dimensional algebra across expressions — so adding mm to deg or passing a mm/min feed to a lathe operation fails immediately.

Unit Literal Dimension Example Usage Where Used
mmLinear length140mm, -12mmCoordinates, depths, tool diameters, allowances
diaLathe diameterdia 24mm, dia 180mmExplicit lathe diameter coordinates & safe_index
radRadiusrad: 3mm, fillet rad 1.5mmLead-in arcs, fillets, radial clearances
degAngle90deg, ramp: 3deg, 45degTool tip angles, helical ramps, bolt-circle start angles
rpmSpindle speed (G97)8000 rpm, max_spindle: 2500 rpmMilling spindles, threading, drilling, lathe CSS clamp
m/minSurface speed (CSS G96)180 m/min, 220 m/minLathe turning, facing, grooving, boring
mm/minLinear feedrate (G94)1600 mm/min3-axis milling operations
mm/revFeed per rev (G95)0.22 mm/revLathe turning, facing, drilling, part-off
%Tool-diameter ratiostep_over: 45%, max_step_over: 75%Radial engagement & tool safety limits
Engineering Tip — Parametric Safety

Pair params with assert statements for critical wall or web thicknesses (e.g., assert (part_h - 8mm - 3mm) >= 6mm). If a future revision deepens a pocket too far, compilation halts before a single G-code line is emitted.

Lesson 02 · Model & Tooling

Stock, Tooling & Geometry

Before any cutting step runs, ClearNC needs three physical definitions: the raw stock billet (or bar), the exact tools magazine with reach & flute lengths, and reusable 2D geometry (contour for milling, profile for turning).

ClearNC Mill Stock, Tool Library & Contours
stock {
  form: block
  size: (146mm, 96mm, part_h + stock_top_alw + carrier_tab)
}

tools {
  tool face_50    { type: face_mill,     dia: 50mm, flutes: 5, reach: 40mm, max_step_over: 75% }
  tool rough_12   { type: flat_end_mill, dia: 12mm, flutes: 3, flute_len: 28mm, reach: 45mm, center_cutting: true }
  tool finish_6   { type: flat_end_mill, dia: 6mm,  flutes: 3, flute_len: 24mm, reach: 30mm, center_cutting: true }
  tool spot_10    { type: spot_drill,    dia: 10mm, angle: 90deg, reach: 30mm }
  tool drill_5    { type: twist_drill,   dia: 5.0mm, max_depth: 35mm }
  tool tap_m6     { type: rigid_tap,     spec: "M6x1.0", lead_threads: 2.5, max_depth: 20mm }
  tool chamfer_10 { type: chamfer_mill,  dia: 10mm, angle: 90deg, tip_rad: 0.2mm, reach: 25mm }
  tool probe_3d   { type: touch_probe,   tip_dia: 6mm, reach: 60mm }
}

contour outer_profile {
  rect center: (0mm, 0mm), size: (part_x, part_y), corner_rad: 8mm
}

contour center_boss {
  circle center: (0mm, 0mm), dia: 26mm
}

Lathe Round Bar Stock, Turning Tools & OD/ID Profiles

For flavor: lathe, declare round_bar stock with stick_out, turning/grooving/threading/boring/part-off inserts, and axisymmetric profile blocks with automatic inline chamfer and fillet rad corner blending.

ClearNC drive_shaft_lathe.cnc — Bar Stock, Inserts & Profiles
stock {
  form:      round_bar
  dia:       bar_dia
  stick_out: part_len + face_allow + 12mm
}

tools {
  tool od_rough  { type: od_turn,   insert: "CNMG120408", hand: right, nose_rad: 0.8mm, approach: 95deg }
  tool od_finish { type: od_turn,   insert: "VNMG160404", hand: right, nose_rad: 0.4mm, approach: 93deg }
  tool od_groove { type: od_groove, width: 3.0mm, max_depth: 10mm }
  tool od_thread { type: od_thread, form: "ISO_60", pitch_range: 1.0mm..3.0mm }
  tool bore_bar  { type: id_bore,   min_bore: 13mm, max_reach: 50mm, nose_rad: 0.4mm }
  tool cutoff    { type: part_off,  width: 3.0mm, max_dia: 50mm }
}

profile od_shaft (side: od) {
  start dia 0mm,  z 0mm
  line  dia 24mm, z 0mm    chamfer 1.5mm
  line  dia 24mm, z -26mm
  line  dia 34mm, z -26mm  fillet rad 1.5mm
  line  dia 34mm, z -58mm  chamfer 1.0mm
  line  dia 42mm, z -58mm
  line  dia 42mm, z -part_len
}

profile id_bearing_seat (side: id) {
  start dia 18mm, z 0mm    chamfer 1.0mm
  line  dia 18mm, z -32mm
  line  dia 14mm, z -32mm
}

All Supported Stock Forms (3-Axis, Lathe & 5-Axis)

Model your real billet accurately so 3D material removal and crash checks never flag air cuts or miss dovetail stubs and hollow tube walls.

Stock Form Key Parameters Typical Use Case
blocksize: (x, y, z)Standard prismatic 3-axis & 5-axis raw billet
round_bardia, stick_outCNC lathe bar stock gripped in a 3-jaw chuck
cylinderdia, height/length, optional axis: z|x|yRound pucks, flanges, and billet cylinders on a mill or 5-axis trunnion
tubeod, id, length, optional axis: z|x|yHollow pipe, rings, and impeller hubs (interior bore is modeled as empty air)
dovetail_blocksize: (x, y, z), dovetail_height, optional dovetail_angle5-axis single-setup blocks pre-prepared with a bottom dovetail grip stub
near_net_shape / from_programfrom_program, allowance / orientationCastings, forgings, or cross-machine stock handoff (e.g., lathe Op 1 → mill Op 2)

Multi-Way 2D Shape Construction (contour)

Real blueprints dimension the same shape in different ways. ClearNC lets you construct circle, rect, slot, and polygon contours directly from the callouts on your drawing — normalizing every form cleanly at compile time and catching degenerate geometry (collinear 3-point circles, zero-area rects, sides < 3) with CNC-G01.

Primitive Supported Constructors Canonical Result
circle center + dia  |  center + rad  |  center + through  |  p1 + p2 (2-pt diameter)  |  p1 + p2 + p3 (3-pt circumcircle) Exact circle center + diameter (CNC-G01 if collinear/coincident)
rect center + size (+ corner_rad, angle)  |  from + to (or p1 + p2)  |  corner / origin + size  |  p1 + p2 + p3 or p1 + p2 + width Axis-aligned rect or rotated/angled 4-corner polygon with optional corner fillets
slot from + to + width  |  center + length + width (+ angle) Closed obround slot contour (works in pocket, profile_inside, and edge_break)
polygon points: [(x1, y1), ...]  |  center + sides + across_flats (+ angle)  |  center + sides + dia / rad (+ angle) Closed vertex polygon (ideal for hex wrench seats, octagons, and custom cavities)
ClearNC Multi-Way 2D Contour Constructors
// Circles: radius, through-point, 2-point diameter, or 3-point circumcircle
contour front_port   { circle center: (0mm, 0mm), rad: 12mm }
contour pitch_bore   { circle center: (0mm, 0mm), through: (15mm, 20mm) }
contour span_circle  { circle p1: (-20mm, 0mm), p2: (20mm, 0mm) }
contour circum_bore  { circle p1: (0mm, 18mm), p2: (-18mm, 0mm), p3: (18mm, 0mm) }

// Rectangles: 2 opposite corners, corner+size, angled, or 3-point
contour bbox_pocket  { rect from: (-40mm, -20mm), to: (40mm, 20mm), corner_rad: 5mm }
contour datum_pocket { rect corner: (10mm, 10mm), size: (60mm, 30mm), corner_rad: 4mm }
contour tilted_pad   { rect center: (0mm, 0mm), size: (48mm, 22mm), corner_rad: 4mm, angle: 25deg }
contour rib_pocket   { rect p1: (0mm, 0mm), p2: (40mm, 15mm), width: 14mm }

// Obround slots & regular polygons (e.g. 24mm hex valve seat)
contour side_gallery { slot center: (0mm, 0mm), length: 34mm, width: 12mm, angle: 0deg }
contour diag_slot    { slot from: (-20mm, -10mm), to: (20mm, 10mm), width: 8mm }
contour hex_seat     { polygon center: (0mm, 0mm), sides: 6, across_flats: 24mm }
contour octagon_boss { polygon center: (0mm, 0mm), sides: 8, dia: 36mm, angle: 22.5deg }
Cross-Machine Stock Handoff

Need to mill wrench flats onto a turned shaft? Reference the lathe part directly via stock { from_program: "Drive_Shaft_Op1", orientation: spindle_axis_along_x } and use inline open paths like path: line from (-30mm, 15mm) to (-56mm, 15mm) — see Drive_Shaft_Op2_Flats.

Lesson 03 · 3-Axis Milling

Your First 3-Axis Milling Setup

Every milling setup begins with three mandatory declarations — workholding (vise, strap clamps, toe clamps, or soft jaws), datum (G54..G59 origin), and safety (retract_z, clearance_z, cut_direction) — followed by named step blocks.

ClearNC Setup Header + Core Milling Operations
setup "Op 1 - Top Side in Vise" (axis: +Z) {
  workholding {
    type:      vise
    grip_z:    carrier_tab
    jaw_top_z: -(part_h + 2.0mm)
  }

  datum {
    x_zero: stock_center
    y_zero: stock_center
    z_zero: finished_top_face
  }

  safety {
    retract_z:     30mm
    clearance_z:   2mm
    cut_direction: climb
  }

  step "Face top surface to Z0" {
    face_mill {
      tool: face_50, from_z: stock_top_alw, to_z: 0mm,
      step_down: 1.5mm, step_over: 65%,
      speed: 4000 rpm, feed: 1600 mm/min, coolant: flood
    }
  }

  step "Rough central pocket around boss" {
    pocket {
      tool: rough_12, boundary: main_pocket, islands: [center_boss],
      z_top: 0mm, z_bottom: -pocket_depth,
      step_down: 3.0mm, step_over: 45%,
      entry: helix(dia: 10mm, ramp: 3deg),
      leave_wall: wall_alw, leave_floor: floor_alw,
      speed: 8000 rpm, feed: 1800 mm/min, coolant: flood
    }
  }

  step "Rest-machine tight R4 corners & finish walls" {
    rest_pocket {
      tool: finish_6, boundary: main_pocket, islands: [center_boss],
      from_tool: rough_12, z_top: 0mm, z_bottom: -pocket_depth,
      step_down: 3.0mm, leave_wall: wall_alw,
      speed: 10000 rpm, feed: 1200 mm/min, coolant: flood
    }

    profile_inside {
      tool: finish_6, contour: main_pocket,
      z_top: 0mm, z_bottom: -pocket_depth, step_down: 6.0mm,
      lead_in: arc(rad: 3mm),
      speed: 10000 rpm, feed: 1100 mm/min, coolant: flood
    }
  }

  step "Break sharp outer & pocket edges" {
    edge_break {
      tool: chamfer_10, contour: outer_profile, z_face: 0mm, size: 0.8mm,
      speed: 8000 rpm, feed: 1200 mm/min, coolant: flood
    }
  }
}
Operation Purpose Key Parameters
face_millDeck raw stock top to datum Z0from_z, to_z, step_down, step_over
pocketRough closed cavities with optional boss islandsboundary, islands, entry: helix(...), leave_wall
rest_pocketClear corner material left behind by a larger rougherfrom_tool, boundary, islands, leave_wall
profile_outside / profile_insideRough or finish outer walls, bosses, bores, or open pathscontour or path, lead_in: arc(...), datum_tag
edge_breakConsistent deburring chamfers along outer or inner contourscontour, side: inside/outside, z_face, size
Lesson 04 · Reuse & Optimization

Drilling, Macros, Transforms & Tool Batching

Instead of repeating hole sequences across dozens of coordinates, encapsulate spot_drill → drill → tap inside a parameterized macro and stamp it with climb-preserving apply transforms (mirror_x, mirror_y, bolt_circle, grid).

ClearNC Reusable Hole Macro + Symmetry & Bolt-Circle Transforms
macro m6_tapped_hole(locations, depth) {
  spot_drill {
    tool: spot_10, at: locations, z_top: 0mm, depth: 3.3mm,
    speed: 4500 rpm, feed: 350 mm/min, coolant: flood
  }
  drill {
    tool: drill_5, at: locations, z_top: 0mm, depth: depth + 4mm, peck: 5mm,
    speed: 5000 rpm, feed: 500 mm/min, coolant: flood
  }
  tap {
    tool: tap_m6, at: locations, z_top: 0mm, depth: depth,
    speed: 800 rpm, coolant: flood
  }
}

// Inside setup: expand across 4 mirrored corners + 4-hole boss bolt circle
step "Drill & tap symmetric flange holes" {
  apply mirror_x, mirror_y {
    m6_tapped_hole(locations: [(58mm, 34mm)], depth: 14mm)
  }
}

step "Drill & tap 4-hole bolt circle on central boss" {
  apply bolt_circle(center: (0mm, 0mm), dia: 18mm, count: 4, start_angle: 45deg) {
    m6_tapped_hole(locations: [(0mm, 0mm)], depth: 12mm)
  }
}

// Rectangular pattern example (from clamp_swap_plate_mill3.cnc)
step "Drill & tap inner grid" {
  apply grid(origin: (-40mm, -25mm), nx: 2, ny: 2, dx: 80mm, dy: 50mm) {
    drill { tool: drill_68, at: [(0mm, 0mm)], z_top: 0mm, depth: 18mm, peck: 4mm, speed: 1400 rpm, feed: 140 mm/min, coolant: flood }
  }
}
Dependency-Safe Tool-Change Batching

Even though you wrote readable per-feature steps (flange holes, then boss bolt circle), ClearNC's optimizer automatically batches all spot_10 hits, then all drill_5 hits, then all tap_m6 hits — slashing ATC tool changes while strictly preserving spot_drill → drill → tap order per hole and never crossing hard barriers (face_mill, clamp_swap, reclamp, locate_datum, part_off, or (order: strict)).

Lesson 05 · CNC Turning

CNC Lathe Turning Workflow

Lathe programs use explicit diameter coordinates (dia), mandatory safe_index turret positions, and max_spindle RPM clamps (G50) whenever Constant Surface Speed (m/min → G96) is used. Repeat loops make multi-groove spacing clean and bug-free.

ClearNC drive_shaft_lathe.cnc — Complete Turning Sequence
setup "Op 1 - Main Turning" {
  workholding {
    chuck:      hard_3jaw
    grip_len:   25mm
    jaw_face_z: -(part_len + 10mm)
  }

  datum { z_zero: finished_front_face }

  safety {
    safe_index:    (dia 180mm, z 50mm)
    clearance_rad: 2mm
    clearance_z:   2mm
    max_spindle:   2500 rpm
  }

  step "Face raw bar end to Z0" {
    face { tool: od_rough, from_z: face_allow, to_z: 0mm, doc: 1.0mm, speed: 180 m/min, feed: 0.22 mm/rev, coolant: flood }
  }

  step "Rough & finish turn OD profile" {
    turn_rough  { tool: od_rough,  profile: od_shaft, doc: 2.0mm, leave_dia: finish_dia_alw, leave_z: finish_z_alw, speed: 180 m/min, feed: 0.28 mm/rev, coolant: flood }
    turn_finish { tool: od_finish, profile: od_shaft, speed: 220 m/min, feed: 0.12 mm/rev, coolant: flood }
  }

  step "Cut thread undercut & two O-ring seal grooves" {
    seal_groove(at_z: -23mm, root_dia: dia 21.5mm, width: 3.0mm)
    repeat 2 times as i {
      seal_groove(at_z: -36mm - (i * groove_pitch), root_dia: dia 29.0mm, width: 3.5mm)
    }
  }

  step "Cut M24x1.5 external thread" {
    thread {
      tool: od_thread, side: od, spec: "M24x1.5", class: "6g",
      z_start: -1.5mm, z_end: -23mm, infeed: flank_29deg,
      first_pass: 0.28mm, min_pass: 0.06mm, spring_passes: 2,
      speed: 900 rpm, coolant: flood
    }
  }

  step "Drill center through-hole & finish bearing bore" {
    drill       { tool: drill_14, depth: part_len + 4mm, peck: 6mm, speed: 1100 rpm, feed: 0.16 mm/rev, coolant: flood }
    bore_rough  { tool: bore_bar, profile: id_bearing_seat, doc: 1.0mm, leave_dia: 0.3mm, speed: 140 m/min, feed: 0.16 mm/rev, coolant: flood }
    bore_finish { tool: bore_bar, profile: id_bearing_seat, speed: 170 m/min, feed: 0.09 mm/rev, coolant: flood }
  }

  step "Part off finished shaft" {
    part_off {
      tool: cutoff, at_z: -part_len, to_dia: dia 12mm,
      back_chamfer: 0.5mm, slow_feed_below: dia 18mm,
      speed: 120 m/min, feed: 0.10 mm/rev, coolant: flood
    }
  }
}
Built-In Lathe Safety Rules (CNC-L01..L09)

ClearNC automatically checks that max_spindle is present with CSS, boring bars fit inside pre-drilled pilot diameters (min_bore), groove roots stay within the blade's max_depth against the local turned OD, and every toolpath clears jaw_face_z.

Lesson 06 · Production Workholding

Multi-Setup Machining, Clamp Swaps & Datum Pickup

Real parts rarely finish in one clamping. ClearNC models mid-setup clamp_swap transitions, carrier-tab decking + reclamp reseating, datum feature handoff (datum_tag → locate_datum), and automatic two-feature G68 coordinate rotation.

ClearNC Mid-Setup Clamp Swap (clamp_swap_plate_mill3.cnc)
step "Pause to move strap clamps inward" {
  clamp_swap {
    release_clamps: ["left_strap", "right_strap"]
    pause_reason:   "Move strap clamps to center tapped holes"
  }
}

step "Drill outer edge holes under former clamp zones" {
  drill {
    tool: drill_68, at: [(-85mm, 0mm), (85mm, 0mm)],
    z_top: 0mm, depth: 18mm, peck: 4mm,
    speed: 1400 rpm, feed: 140 mm/min, coolant: flood
  }
}
ClearNC Op 2 Flip, Re-Seat & Two-Hole G68 Datum Pickup
// Tag Op 1 datum features (e.g. datum_tag: "D_HOLE_A" and "D_HOLE_B")
// Then in Op 2, reference them for exact G55 origin + G68 rotation:
setup "Op 2 - Freehand Strap Clamps (Operator Seed + Two-Hole G68)" (axis: -Z) {
  workholding {
    type: strap_clamps, from_setup: 1, flip: "180deg_about_x",
    keep_out: [
      clamp(name: "front_strap", center: (0mm, -22mm), size: (24mm, 14mm), z_top: 12mm),
      clamp(name: "rear_strap",  center: (0mm, 22mm),  size: (24mm, 14mm), z_top: 12mm)
    ]
  }

  datum {
    work_offset: "G55", xy_from_datum: "D_HOLE_A", part_thickness: part_h,
    x_zero: datum_bore, y_zero: datum_bore, z_zero: stock_top
  }

  step "Locate G55 via two-hole midpoint & G68 angle" {
    locate_datum {
      work_offset:   "G55"
      seed:          operator_seed(feature: "D_HOLE_A", note: "Jog stylus over Hole A (-48, 0) within +-2mm")
      xy:            two_holes(datum_a: "D_HOLE_A", datum_b: "D_HOLE_B", origin: midpoint, dia_a: 16mm, dia_b: 16mm, tol: 0.05mm)
      rotation:      two_bores(datum_a: "D_HOLE_A", datum_b: "D_HOLE_B")
      z:             surface(at: (0mm, 0mm), expected_z: 0mm, tol: 0.3mm)
      probe_tool:    probe_3d
      manual_method: dial_indicator_two_holes
      manual_note:   "Indicate Hole A and Hole B to set G55 midpoint & angle, then touch top Z0"
    }
  }
}

One Source, Three Shop-Floor Datum Pickup Modes

Pickup Mode Hardware Needed What ClearNC Emits
Manual Edge finder / dial indicator Structured M00 operator checklists & verification prompts (zero probe cycles).
Guided Macro B Mitsubishi M80 / Fanuc Macro B #3006=1 operator prompts capturing machine coords (#5021..#5023) into G10 L2 P<n>, span sanity alarms (#3000), and automatic ATAN + G68/G69 rotation.
With Probe Renishaw Inspection Plus Full G65 cycles (P9832, P9810, P9814, P9843 + G68/G69, P9811, P9833) with 3D ruby-tip stylus simulation.
Lesson 07 · Verification & Proof

3D Crash Simulation, Diagnostics & Post-G-Code Verification

Every compile runs two independent safety gates: first, material-aware crash simulation on the compiled motion plan (CNC-SIM*); second, an independent G-code parser that replays the emitted NC file itself (CNC-GC*) to guarantee no post-processor bug, modal hazard, or collision reaches the machine.

Diagnostic Code Verification Stage What It Catches
CNC-SIM013D / 2D Material SimG00 rapid move plunging into uncut billet or bar stock
CNC-SIM02Workholding SimTool or holder colliding with vise jaws, chuck jaws, tailstock, or active strap/toe clamps
CNC-SIM03Tool & Shank SimNon-cutting shank rub, insufficient flute_len/reach, or boring-bar clearance violation
CNC-GC01Post-G-Code ParserMalformed NC syntax, missing program delimiters, or invalid controller words
CNC-GC02Modal State CheckerMissing safety header, missing spindle/feed/G43 H offset, CSS without G50, or unbalanced G68/G69
CNC-GC03Arc Geometry ProofDegenerate arc radius or mismatched I/J/K start/end radii on G02/G03 blocks
CNC-GC04Motion EquivalenceAny positional drift (> 0.015 mm) between replayed NC moves and the compiled motion plan
CNC-GC05G-Code Replay SimMaterial/fixture/shank collision detected directly on the emitted NC file, pinned to exact 1-based NC line

Workflow in ClearNC Studio & CLI

  • Step through 3D Simulation: Open the Visualize tab, scrub the timeline or hit Play, and inspect progressive material removal, fixtures, and Auto-Pause operator checkpoints.
  • Confirm the Green Verification Banner: Switch to the Compiled G-Code tab to inspect replayed move counts, max mathematical deviation (0.000 mm), and 0 replay collisions.
  • Bidirectional Traceability: Click any ClearNC line in the editor to jump straight to its generated G-code lines — or click any G-code block to highlight the exact source step that produced it.
CLI Validate, Inspect & Compile Locally with Cargo
# Inspect setup plan, tool-batching savings, simulation & G-code verification
cargo run -- inspect examples/bearing_plate_two_sided_mill3.cnc
cargo run -- inspect examples/manifold_5sided_mill5.cnc

# Compile verified controller-specific G-code
cargo run -- compile examples/sensor_bracket_mill3.cnc --controller mitsubishi_m80
cargo run -- compile examples/drive_shaft_lathe.cnc    --controller syntec_22ta
cargo run -- compile examples/manifold_5sided_mill5.cnc --controller fanuc_5axis
Lesson 08 · 5-Axis Machining

5-Axis Machining: 3+2 Tilted Work Planes, New Stock Forms & Simultaneous RTCP

With flavor: mill_5axis, ClearNC compiles single-setup 5-sided parts on trunnion and head-table machines. Declare machine rotary limits, stepped tool-holder envelopes, 5-axis vises, tilted 3+2 work_plane blocks, and simultaneous sampled_5axis pass-through toolpaths — all verified in isotropic 3D volumetric voxels and replayed directly from emitted G-code.

1. Machine Kinematics, Dovetail Stock, Stepped Holders & 3+2 Work Planes

Declare your trunnion limits in machine, add stepped holder geometry (shank_dia, holder_dia, holder_len, gauge_len) to each tool, clamp on a dovetail_vise (or five_axis_vise, riser, pyramid, zero_point_chuck), and write standard 3-axis operations inside any tilted work_plane.

ClearNC manifold_5sided_mill5.cnc — Dovetail Block, Stepped Holders & 3+2 Planes
clearnc v1

program "Hydraulic_Manifold_5Axis" {
  flavor:   mill_5axis
  units:    metric
  material: "6061-T6" (95 HB)
  author:   engineer
}

machine {
  kinematics:           trunnion_ac
  a_limits:             -120deg..120deg
  b_limits:             -30deg..30deg
  c_limits:             -360deg..360deg
  clearance_sphere_rad: 130mm
}

stock {
  form:            dovetail_block
  size:            (90mm, 76mm, 62mm)
  dovetail_height: 10mm
  dovetail_angle:  45deg
}

tools {
  tool em8  { type: flat_end_mill, dia: 8mm, flutes: 3, flute_len: 20mm, reach: 38mm,
              shank_dia: 8mm, holder_dia: 32mm, holder_len: 42mm, gauge_len: 88mm, center_cutting: true }
  tool d6_8 { type: twist_drill,   dia: 6.8mm, flute_len: 35mm, reach: 48mm, max_depth: 40mm,
              shank_dia: 6.8mm, holder_dia: 32mm, holder_len: 42mm }
}

setup "Single Setup — 5-Sided Manifold" (axis: +Z) {
  workholding { type: dovetail_vise, grip_z: -52mm, vise_top_z: -52mm }
  datum       { work_offset: "G54", x_zero: stock_center, y_zero: stock_center, z_zero: stock_top }
  safety      { retract_z: 30mm, clearance_z: 2mm, clearance_sphere_rad: 130mm, cut_direction: climb }

  step "Right Face (+X, A=90°, C=90°): Fluid Gallery Slot & Cross-Port" {
    work_plane "Right Face (+X)" (tilt_a: 90deg, rotate_c: 90deg, origin: (45mm, 0mm, -24mm)) {
      pocket { tool: em8, boundary: side_gallery, z_top: 0mm, z_bottom: -7mm, step_down: 3.5mm, entry: helix, speed: 10000 rpm, feed: 1100 mm/min, coolant: flood }
      drill  { tool: d6_8, at: [(0mm, 0mm)], z_top: 0mm, depth: 24mm, peck: 5mm, speed: 4200 rpm, feed: 420 mm/min, coolant: flood }
    }
  }

  step "Angled 35° Relief Port (A=-35°, C=0°): Tilted Bleed Seat" {
    work_plane "Back 35deg Relief" (tilt_a: -35deg, rotate_c: 0deg, origin: (0mm, 38mm, 0mm)) {
      pocket { tool: em8, boundary: angled_port, z_top: 0mm, z_bottom: -10mm, step_down: 5mm, entry: helix, speed: 10000 rpm, feed: 1050 mm/min, coolant: flood }
      drill  { tool: d6_8, at: [(0mm, 0mm)], z_top: 0mm, depth: 22mm, peck: 5mm, speed: 4200 rpm, feed: 400 mm/min, coolant: flood }
    }
  }
}

2. Hollow Tube Stock & Simultaneous 5-Axis Pass-Through (sampled_5axis + RTCP)

Combine hollow tube stock and 3+2 radial windows with continuous simultaneous 5-axis toolpaths using sampled_5axis. ClearNC enforces rtcp: true (G43.4 / TRAORI), supports inverse-time feed (feed_mode: inverse_time → G93), and sweeps the tilted ball-end mill + stepped holder through the full 3D voxel solid.

ClearNC impeller_hub_tube_mill5.cnc — Tube Stock & Simultaneous RTCP
stock {
  form:   tube
  od:     92mm
  id:     46mm
  length: 64mm
  axis:   z
}

// Inside setup (workholding: five_axis_vise):
step "Simultaneous 5-Axis Upper Shroud Blend (RTCP G43.4 + G93)" {
  sampled_5axis {
    tool:      bm8
    rtcp:      true
    feed_mode: inverse_time
    speed:     12000 rpm
    feed:      900 mm/min
    coolant:   flood
    moves: [
      rapid(x: 0mm,     y: -52mm,   z: 18mm,   a: 35deg, c: 0deg),
      line (x: 0mm,     y: -44mm,   z: -2mm,   a: 35deg, c: 0deg,   feed: 600 mm/min),
      line (x: 22mm,    y: -38.1mm, z: -2.5mm, a: 35deg, c: 30deg,  feed: 900 mm/min),
      line (x: 38.1mm,  y: -22mm,   z: -3mm,   a: 35deg, c: 60deg,  feed: 900 mm/min),
      line (x: 44mm,    y: 0mm,     z: -3mm,   a: 35deg, c: 90deg,  feed: 900 mm/min)
    ]
  }
}

3. 5-Axis Static Safety & Post-G-Code Verification

Check / Controller Code What ClearNC Proves
CNC-5X01..05Rotary limits (a_limits/b_limits/c_limits), clearance-sphere safety before indexing, holder/shank reach, valid tube (id < od) & dovetail_height < stock_z, and mandatory rtcp: true on sampled_5axis.
Fanuc / Mitsubishi M80 5-AxisVerifies balanced G68.2 + G53.1 → G69 (Tilted Work Plane) and G43.4 → G49 (RTCP) cancel before every tool change and M30, plus G93 → G94 feed restoration.
Siemens 840DVerifies balanced CYCLE800(...) tilted work planes and TRAORI → TRAFOOF transformation cancels alongside rotary travel limits.
3D Volumetric Replay (CNC-GC05)Replays parsed 5-axis G-code through ClearNC's 3D voxel simulator to confirm zero cutter/shank/holder crashes against uncut stock, vise jaws, riser, or trunnion table.
CAD Solid + Volumetric Modes & Machine View vs. Part View

ClearNC Studio's 5-axis visualizer renders both CAD Solid (default: true 3D boolean subtraction with smooth cylindrical intersections and crisp dark feature edges) and Volumetric (voxel crash cross-check & simultaneous sweep verification) — both animated at 60 FPS in physically accurate Machine View or upright Part View. On Trunnion A/C (kinematics: trunnion_ac), the rotary turntable, vise, and part tilt and spin inside a stationary cradle beneath a strictly vertical spindle; on Head-Table B/C (kinematics: head_table_bc), the rotary table spins in C while the swivel spindle head tilts in B. Compare them live in 5-Axis Manifold vs. Aerospace Rib (Head-Table B/C).

Lesson 09 · Multi-Tasking Mill-Turn

Multi-Tasking Mill-Turn (Mazak INTEGREX i-200ST)

With flavor: mill_turn, ClearNC unifies lathe turning, B/C-axis 3+2 milling, and automated sub-spindle part transfer inside a single verified program. Write OD/ID turning steps and tilted B-axis work_plane features in sequence — ClearNC automatically inserts safe turning/milling mode switches (M202 ↔ M200), G68.2/G69 tilted planes, synchronized sub-spindle handoff (M511/M306), and full horizontal-Z 3D CAD Solid & crash verification.

1. Dual-Chuck Machine Setup, Unified Turning & B-Axis Milling

Declare kinematics: integrex_mill_turn_bc with has_sub_spindle: true, configure both main_chuck and sub_spindle jaw positions, then combine turning operations (face, turn_rough, turn_finish, groove, thread) with B-axis work_plane pockets and through_spindle coolant cross-drilling.

ClearNC drive_hub_integrex_i200st.cnc — Machine, Turning & B-Axis Milling
program "Drive_Hub_INTEGREX_i200ST" {
  flavor:   mill_turn
  units:    metric
  material: "4140 Alloy Steel" (28 HRC)
  author:   engineer
}

machine {
  kinematics:           integrex_mill_turn_bc
  b_limits:             -30deg..210deg
  c_limits:             -360deg..360deg
  has_sub_spindle:      true
  clearance_sphere_rad: 150mm
}

setup "Single-Channel Multi-Tasking (Op 1 Main + Op 2 Sub-Spindle)" {
  workholding {
    main_chuck:     hard_3jaw
    grip_len:       25mm
    jaw_face_z:     -95mm
    sub_spindle:    true
    sub_jaw_face_z: 120mm
  }

  // Turn stepped hub with compensated chamfers & fillet, grooves, and M24x1.5 thread...
  step "Finish Turn OD with Chamfers & Fillet" {
    turn_finish { tool: od_finish, profile: hub_od, speed: 220 m/min, feed: 0.12 mm/rev, coolant: flood }
  }

  // Automatically switches to Milling Mode (M200) + G68.2 tilted planes:
  step "B90 Radial Wrench Flats (C0 & C180)" {
    work_plane "Wrench_Flat_C0" (tilt_b: 90deg, rotate_c: 0deg, origin: (23mm, 0mm, -65mm)) {
      pocket { tool: em10, boundary: wrench_flat, z_top: 0mm, z_bottom: -3mm, step_down: 1.5mm, step_over: 55%, speed: 4200 rpm, feed: 750 mm/min, coolant: flood }
    }
  }

  step "B45 Angled Grease Port (C270)" {
    work_plane "Angled_Grease_Port_45" (tilt_b: 45deg, rotate_c: 270deg, origin: (0mm, -23mm, -56mm)) {
      drill { tool: d5, at: [(0mm, 0mm)], z_top: 0mm, depth: 14mm, peck: 3.5mm, speed: 4000 rpm, feed: 280 mm/min, coolant: through_spindle }
    }
  }
}

2. Automated Sub-Spindle Transfer (part_transfer) & Op 2 Back-Working

Complete the back side of the part in the same cycle without manual rechucking: part_transfer synchronizes spindle RPM, grips the turned OD in the sub-spindle, parts off cleanly, and transitions directly into Op 2 back_face, drilling, and rear bearing boring.

ClearNC drive_hub_integrex_i200st.cnc — Sub-Spindle Handoff & Op 2 Bore
step "Automated Sub-Spindle Handoff & Part-Off" {
  part_transfer {
    sub_grip_len:  20mm
    sync_rpm:      800 rpm
    part_off_tool: cutoff
    at_z:          -80mm
    speed:         110 m/min
    feed:          0.08 mm/rev
    coolant:       flood
  }
}

step "Op 2 Sub-Spindle Back-Face & Rear Bearing Bore" {
  back_face   { tool: od_finish, from_z: -80mm, to_z: -79mm, doc: 1mm, speed: 200 m/min, feed: 0.14 mm/rev, coolant: flood }
  drill       { tool: d16, depth: 18mm, peck: 5mm, speed: 1100 rpm, feed: 0.16 mm/rev, coolant: through_spindle }
  bore_finish { tool: bore14, profile: rear_bore, speed: 140 m/min, feed: 0.12 mm/rev, coolant: flood }
}

3. Mazak Matrix 2 Mode Switching & Post-G-Code Verification

Mazak Matrix 2 Code Role in Mill-Turn Cycle Verified Safety Invariant
M202 / M200Switch cleanly between Turning Mode and C-Axis Milling ModeAlways retracts safely before mode change; never runs live-tool cuts in turning mode or vice versa
G68.2 / G53.1 / G69Tilted B/C work planes (B=0°, B=45°, B=90°, B=180°)Balanced G69 cancel verified before every tool change, turning switch, and M30
M511 / M306Synchronized main & sub-spindle rotation + automated handoffValidates sub-spindle grip length, part-off Z clearance, and Op 2 rear boring reach
3D Solid & Crash ReplayUnified horizontal-Z CAD Solid + Volumetric voxel checkRevolves turned OD/ID, boolean-subtracts B/C milled features, and checks both chucks & stepped holders