Skip to content

ThermalCut compensation="control": the controller applies the kerf (#384) - #387

Merged
10-X-eng merged 2 commits into
mainfrom
feat/thermal-control-compensation
Nov 23, 2026
Merged

10-X-eng merged 2 commits into
mainfrom
feat/thermal-control-compensation

Conversation

@10-X-eng

Copy link
Copy Markdown
Contributor

Closes #384

ThermalCut(compensation="control"): the program carries the part side of the kerf path and the controller applies the whole kerf. Posted with the WinCNC plasma post either as the documented G41 O<kerf/2> / G40 form or, for a control its owner declares applies its material setup's kerf itself, with no compensation word.

What changed

Events. Event::CutterCompensation (Rust and Python) gains amount_mm (only when turning on): the controller offsets the written path by the whole amount. The motions stay where the beam centre runs, so the stream, stock, receivers, playback and stock replay are unchanged; the post writes the motions offset back by the amount. Without amount_mm nothing changes (serialization skips it).

Planner (src/thermal.rs, new src/thermal/control.rs).

  • Same kerf path, order, leads and proofs as "computer" along the edges. At an outside corner the part side is an arc of a few micrometres (the boundary margin) that cannot be written, so the written path has the corner there and the beam path planned is the controller's intersection join: the two edges' kerf paths extended to where they meet, r / sin(θ/2) from the written corner (WinCNC Versions Information List 3.1.01a: offset arcs and "calculate a new intersection point"). The arc join (half a kerf about the written corner) that a controller could use instead lies inside it; both are probed against every part, the extension pieces with a named refusal ("an acute part corner whose extended join reaches a neighbouring part").
  • Pierce on the written path, half a kerf to the part side of the planned lead, crater-probed with pierce_clearance_mm; the entry move (off to on) runs straight from it to the lead arc start, the cancel move from the lead-out arc end to the written end; both probed as leads. The written straight leads are collinear with the planned ones, so they run tangent into the lead arcs and the controller's start-up end point does not depend on its entry type.
  • A loop whose first vertex is an outside corner starts in the middle of the next edge; arcs are planned as at most quarter turns (the controller's offset of a written arc ends where its neighbours' offsets meet it, which moves its sweep by a hair of the rounding).
  • Refusals: common_line, micro_joints, corner_loops, edge_starts; leads without a straight part or without an arc; a kerf path bridging a gap narrower than the kerf (two outside corners meet, or a corner meets a sharp turn); a sharp turn toward the part; an element whose part side its corners trim away; a beam path that crosses itself; a corner join not clear of the parts.

Controller model (new src/controller_offset.rs, bound as native.replay_controller_offset). Reads only written curves, side and amount: offsets each written line/arc, joins consecutive offsets at their intersection, reports each outside corner's arc join and the intersection's reach, refuses entry/cancel moves that are not tangent into the path, offsets that do not meet or that trim an element away. Near-tangent junctions (rounded words) are joined at the local intersection, else across the gap; the gap and amount x sin(turn) at the entry/cancel are reported as residual_mm, refused beyond a quarter of the tolerance and added by the post engine to every replayed move's checked deviation, which must stay within the output tolerance.

Posting (python/camlib/postprocessor.py).

  • GCodeDialect.compensation_amount_word (None by default; WinCNC O): G41/G42 + amount on a block of its own, G40 on its own. A post whose dialect has no amount word refuses "control".
  • written_path() (Python, independent of the Rust replay and of the planner): what the post writes for a compensated stretch.
  • PostEngine._post_stretch: a stretch from compensation on to the move after it turns off is written and read whole (the controller joins each move with the next, so a move is known only once the next one is read), then checked in batches of at most 64 events through the same native session, so a stretch can have any length. Arcs in a stretch must be written as one G2/G3 block (the controller offsets the written arc); lowering them to lines is refused.
  • GCodeDecoder.begin_stretch/end_stretch/replay_compensation: the decoder reads G41/G42 O<r> and replays the controller's offset of what was written; unwritten_compensation() for a control that applies the amount with no word (the decoder then checks its compensation starts with the first move after the torch fires and ends with the last before it goes off, and refuses any other cut with the torch on).
  • Native session: compares the decoded amount within the output tolerance, and accepts a compensation change with no block only when the machine declares compensation_unwritten.
  • The Rust default post (src/gcode) refuses an amount (documented); its dialect accepts the new field.

WinCNC plasma post (examples/wincnc_plasma_post.py, docs/wincnc-plasma-post.md).

  • control_kerf="g41": G41 O<kerf/2> / G40 (WinCNC Users Guide, Controller 3.1, revision 3.1.04, pp. 138-139; ShopSabre's "shopsabre plasma" post, $Revision 44226, lines 490-504). The docs state that this behaviour is documented for revision 3.1.04 and that earlier versions are not covered by the citation.
  • control_kerf="material", material_kerf_mm=...: no compensation word, the control applies half its material setup's kerf to the left of travel from the first move after M61 to the last before M62. Documented as the owner's declaration of their control, not a WinCNC manual fact. Only compensated loops, in the usual direction, with the material's kerf.
  • control_kerf=None (default): refused. WINCNC.INI cutcomp premises T0 / positive D; R and C (defaults 200 in, 0.5°) replayed by the decoder (larger, flatter arcs become lines); F (3.1.07b, no documented default) must be declared before a compensated arc is posted.

Docs: docs/operations.md (ThermalCut), docs/posts.md (compensation_amount_word), docs/wincnc-plasma-post.md, docs/library-capabilities.md.

Direction finding (wear side fixed)

ThermalCut cuts outlines clockwise and holes counter-clockwise: the part is on the right of travel and the kerf/scrap on the left (src/thermal.rs: strokes reversed so part_left is false; scrap() is the left normal). The controller's offset must therefore go left, G41. "wear" wrote CompensationSide::Right (G42) for the default direction, which moves the torch into the part by the wear. This PR fixes it to G41 (G42 with reverse=True), with tests/thermal_control.rs::wear_compensation_offsets_to_the_scrap_side, which checks, independently of the planner, that a point one millimetre to the compensation side of every compensated cut is off the part (fails on main). That is the one change to existing output: "wear" programs now carry G41 where they carried G42 (and the reverse); nothing else in them changes.

Evidence

Tested commit 5b7d7d85ee7cd7761c8d3db2c21743b2fb5f17d1 (clean tree; the pushed head), Linux x86_64 (kernel 6.8, Ubuntu), rustc 1.98.1, CPython 3.12.3:

Check Command Result
Format cargo fmt --check; ruff check python examples bench; ruff format --check python examples bench passed
Clippy cargo clippy --workspace --all-targets --all-features -- -D warnings passed for every change here; this rustc's clippy also flags needless_range_loop in src/surface/spline_bounds.rs:95-96, a file this PR does not touch (the same on main), so the full lint was run with -A clippy::needless_range_loop
Rust lib + integration tests cargo test --profile ci --workspace --all-features --lib --tests (the CI test profile: release optimisation without LTO; the release-profile integration binary was OOM-killed at a 9 GB limit on this 15 GB host) passed: lib 461 (5 ignored), integration 674
Rust doc tests cargo test --release --doc passed (1)
New Rust tests tests/thermal_control.rs (3), controller_offset unit tests (3) passed; they fail on main (no "control"; wear test: G42)
Python PYTHONPATH=python python -m unittest discover -s python/tests 1064 run: 0 failures; 146 errors, all imports of CadQuery/OCP/numpy, which this host does not have (CAD adapter tests, as on main); 58 skipped. python/tests/test_thermal_control.py (5) passed
Examples, default refusal examples/standalone_job.py in a fresh directory with a space refused export, no NC file written; examples/cadquery_job.py not run (no CadQuery)
Untouched modes the plate above posted from main (dde509b) and from this branch: WinCNC plasma "computer" in inch and mm, both directions; default post (LinuxCNC dialect, beam) "computer" and "wear", both directions "computer": byte-identical. "wear": identical except G42 D1 -> G41 D1 (and G41 -> G42 reversed), the side fix below
Windows not run locally (CI)

Example

A 100 x 60 mm plate with a 20 mm hole, kerf 1.6 mm, WinCNC plasma post with start_code=None, local_coordinates="keep", M61/M62, end M66, inch at 4 decimals, control_kerf="g41":

G90
G20
G40
G49
(WORK ZERO AS SET AT THE MACHINE)
(TORCH TORCH)
G0 X2.5907 Y2.0787
M61
G41 O0.0315
G1 X2.4726 Y2.0787 F98.4252
G3 X2.3624 Y1.9685 I0. J-0.1102 F98.4252
G3 X2.7559 Y1.575 I0.3935 J0. F98.4252
G3 X3.1494 Y1.9685 I0. J0.3935 F98.4252
G3 X2.7559 Y2.362 I-0.3935 J0. F98.4252
G3 X2.3624 Y1.9685 I0. J-0.3935 F98.4252
G3 X2.453 Y1.8779 I0.0906 J0. F98.4252
G40
G1 X2.512 Y1.878 F98.4252
M62
G0 X0.5589 Y1.8583
M61
G41 O0.0315
G1 X0.677 Y1.8583 F98.4252
G3 X0.7872 Y1.9685 I0. J0.1102 F98.4252
G1 X0.7872 Y3.1498 F98.4252
G1 X4.7246 Y3.1498 F98.4252
G1 X4.7246 Y0.7872 F98.4252
G1 X0.7872 Y0.7872 F98.4252
G1 X0.7872 Y1.9685 F98.4252
G3 X0.6966 Y2.0591 I-0.0906 J0. F98.4252
G40
G1 X0.6376 Y2.0591 F98.4252
M62
M66

With control_kerf="material" the program is the same less the four compensation blocks (G41 O0.0315 and G40, twice; the header's G40 stays): python/tests/test_thermal_control.py checks exactly that.

Where the proposal was changed, with the evidence

  • Corner joins. The issue proposed the plan be "the same kerf path". At an outside corner that cannot be: its part side is an arc of the boundary margin's radius (0.005 mm by default), which no program can write (0.0002 in), so the written path has the corner and the controller forms the join. The plan therefore takes WinCNC's documented intersection join as the beam path there, and proves the arc join too. Along every edge the path is the computer path.
  • Leads. Both leads need an arc (radius_mm > 0), not only a straight part: with the straight lead meeting the cut at a corner, where a controller ends its start-up move differs between controllers (perpendicular to the entry or to the next move), and WinCNC does not document it.
  • Pierce. On the written path, half a kerf beside the planned lead (the controller is off there), as the issue says; edge starts are refused with it.
  • Inside corners narrower than the kerf. Not refused: the written path is the beam path offset back, so at an inside corner it has the corner the controller turns into exactly the planned kerf corner, and the controller can form it. Slots and gaps narrower than the kerf are refused.
  • Machine clearance (declared crash model) under controller compensation stays unproven, as for wear: the refusal message now names both.

Benchmarks

Release build, sequential, this host: python bench/run.py --label t384 --only plasma plasma-common-line plasma-edge-starts, then python bench/compare.py bench/expectations bench/results/t384.json: no toolpath change for any ThermalCut workload (the only rows are the other workloads, not measured in this run). numpy was supplied from a scratch directory for the runner; the CAD workloads were not run (no CadQuery). No workload was added for "control": it is a posting mode of ThermalCut, covered by the tests above.

Not done

🤖 Generated with Claude Code

10-X-eng and others added 2 commits November 22, 2026 21:34
)

The program carries the part side of the kerf path and the controller
offsets it by half the kerf. CutterCompensation gains amount_mm; the
motions stay the beam path, the post writes their part side
(written_path), and the decoders replay the controller's offset of what
was written (camlib::controller_offset), each move checked against the
plan with both corner joins bounded.

- Planner (thermal/control.rs): outside corners take the controller's
  intersection join, the arc join is probed too; the pierce and the
  lead-out end are on the written path; refusals for common_line,
  micro_joints, corner_loops, edge_starts, leads without an arc, gaps
  narrower than the kerf, trimmed or crossing offsets, unclear joins.
- Posting: GCodeDialect.compensation_amount_word (G41/G42 O# on a block
  of its own, G40 alone); compensated stretches are written and read
  whole and checked in batches of 64.
- WinCNC plasma post: control_kerf="g41" (G41 O<kerf/2>, Users Guide
  3.1.04 pp. 138-139) or "material" (the owner's declaration: the
  control applies its material setup's kerf with no word); cutcomp R, C
  and F replayed.
- Wear compensation offset to the scrap side: G41 for the usual
  direction (it was G42, into the part), with a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@10-X-eng

Copy link
Copy Markdown
Contributor Author

The original self-intersection scan skipped neighboring edges. A semicircle from (0, 0) to (2, 0) through (1, −1), followed by a straight edge to (−1, −1), has a second intersection at (0.2, −0.6). The old scan accepted it. Commit 27a29ab checks both the written outline and the beam path with the engine’s planar boundary validator. The regression also checks a simple loop with the same semicircle.

Linux passed the new regression, the three Rust controller-compensation integration tests and 38 Python thermal tests, including inch and millimetre output and independent G-code replay. The plasma, common-line and edge-start release benchmarks matched their committed expectations.

@10-X-eng
10-X-eng enabled auto-merge November 22, 2026 23:00
@10-X-eng
10-X-eng added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 5071c26 Nov 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ThermalCut: compensation="control" (part outline with G41/G42 and the kerf's half-width; WinCNC G41 O#)

1 participant