Skip to content

Plan pocket depths from a faced top, not from its sweep guard (#381) - #388

Open
10-X-eng wants to merge 1 commit into
mainfrom
fix/adaptive-faced-floor-engagement
Open

10-X-eng wants to merge 1 commit into
mainfrom
fix/adaptive-faced-floor-engagement

Conversation

@10-X-eng

Copy link
Copy Markdown
Contributor

Closes #381

Root cause

The planner was wrong. The proof was right to refuse.

A flat cut at height h leaves the stock model's upper bound at h plus the sweep guard, which is the run's sweep tolerance_mm (1e-5 by default; Stock::preview_sweep sets upper = z + guard). Since #364 (#344), StockTop::planning_top plans the depths from the highest reachable stock above top_z_mm. On a top faced to exactly Z20 that stock is at Z20.00001, so every level moved up by the guard. When the depth is a whole number of stepdowns, the plan then gets one more level, 1e-5 mm below the level above it:

stepdown 2: tips [18.00001, 16.00001, 14.00001, 12.00001, 12.0]
stepdown 8: tips [12.00001, 12.0]

On that last level the whole region is a sheet of possible material 1e-5 mm thick. The engagement proof cannot bound the contact angle of a stroke buried in it, so it refuses (could not resolve its boundary certificate; nodes 2 ... depth 0). That is the correct result for that plan. A Pocket has the same problem in another form: it repeats its floor pass, and at the posted resolution the two passes are the same blocks. The 56 lines #364 added to fixtures/posts/rust/standalone-rest.nc are exactly that repeated pass.

The rule was also inconsistent. Every level after the first is placed a stepdown below the tip of the level above it, not below the guard that level leaves. So in the "below the stock model" sense, levels 2 and later already cut a stepdown plus the guard.

The fix

StockTop::planning_top treats stock no more than the operation's tolerance_mm above the top as being at the top. Stock that stands higher still raises the planning top. This is used both before motion and on the rescan. The first level is now measured like every later level, from the tip of the cut that left the stock.

What #344 required still holds: no motion removes more than a stepdown of the stock model. The new tests measure this as before.upper - after.upper for every motion, the same way top_inside_the_tolerance_band_never_cuts_deeper_than_a_stepdown does. The #344 band case (stock 0.1 mm above the top) is unchanged. No tolerance, band or check is relaxed, and the engagement proof is untouched.

Tests

  • tests/pocket_top.rs::adaptive_pocket_from_a_faced_floor_cuts_whole_stepdowns_to_the_floor uses the issue's program: a 100 x 60 plate in 21 mm stock, a 6 mm end mill, faced to Z20, then an AdaptivePocket from Z20 to Z12. It runs stepdowns 2, 3 and 8, each with a helical entry and with a ramp entry. It checks:
    • the levels are whole stepdowns ([18,16,14,12], [17,14,12], [12]), and the last is exactly at the floor;
    • every level changes stock;
    • every level is released;
    • no motion removes more than a stepdown of the model;
    • the floor inside the pocket is at Z12 (+1e-5);
    • a Pocket from the same faced floor plans 4 depth passes, not 5.
  • stock_just_beyond_the_tolerance_above_the_top_still_raises_the_planning_top: stock 1e-5 above the top plans from the top, and stock 1.1e-5 above it still raises the top, for both Pocket and AdaptivePocket.
  • pocket_and_adaptive_use_faced_stock_top_without_resetting_stock_or_extra_depths: now asserts the exact tips [6, 5] instead of a band.
  • python/tests/test_faced_pocket_top.py streams Facing then AdaptivePocket end to end, with stock-contact checks, at stepdowns 2 and 8. It checks the layers, completion and that every contact check is clear.

Failing on main: I ran the new Rust tests against src/pocket.rs from dde509b. adaptive_pocket_from_a_faced_floor..., stock_just_beyond... and the updated faced-stock test fail there; at stepdown 2 the tips are [18.00001, ..., 12.00001, 12.0]. A probe on dde509b reproduced the refusal itself: contact angle ... not proven ... adaptive pocket level 4 at Z12 for helix at stepdown 2, and level 1 at Z12 at stepdown 8.

Benchmarks (release, bench/run.py, compared with bench/expectations)

Only rest-pocket changed. It returns to the values it had before #364:

  • moves 186 -> 130
  • posted blocks 225 -> 169
  • exact-stop cycle 92.1 s -> 69.9 s
  • pocket and rest: 2 plunges fewer each

Material bounds are unchanged. I regenerated bench/expectations/rest-pocket.json from the measurement with bench/expectations.py. It is byte-identical to the file before #364. fixtures/posts/rust/standalone-rest.nc is also byte-identical to its version before #364. Every other workload matches its expectation.

Evidence

  • Tested commit: 0928b9f (the pushed head). Linux x86_64, Ubuntu, Python 3.12.3, CadQuery 2.8.0.
  • cargo test --profile ci -j 4 --workspace --all-features --lib --tests: 458 unit passed (5 ignored), 673 integration passed. The release-profile build of the test binaries was OOM-killed under an 8 GB memory cap, so I used --profile ci, the same optimisation level without LTO.
  • cargo test --release --doc: 1 passed.
  • cargo +1.100 clippy --workspace --all-targets --all-features -- -D warnings (the CI-pinned toolchain): clean. Local stable 1.98 clippy flags needless_range_loop in src/surface/spline_bounds.rs:95, which this PR does not touch; 1.100 does not.
  • cargo fmt --check: clean on stable and on 1.100.
  • python -m unittest discover -s python/tests (release build, with CadQuery): 1124 tests OK, 21 skipped.
  • python -m unittest discover -s bench -p "test_*.py": 12 OK.
  • ruff check and ruff format --check on python, examples and bench: clean.
  • Both examples run without --accept-unchecked-machine in fresh directories containing spaces. Each refuses export (unchecked_machine) and writes no NC file.
  • python bench/run.py --label fix-381, then bench/compare.py: only rest-pocket differs, as listed above.
  • Not run locally: Windows and the LinuxCNC interpreter tests. CI covers them.

Docs: docs/operations.md ("A top below the remaining stock") now explains the planning top, and drops the note about a nearly empty last depth.

#385 (Flat around a round boss) also edits docs/operations.md, in a different section (Flat). It shares no other file with this PR.

🤖 Generated with Claude Code

A flat cut at height h leaves the stock model's upper bound its sweep
guard (the run's sweep tolerance_mm, 1e-5 by default) above h. Since
#344, Pocket and AdaptivePocket planned their depths from the highest
reachable stock above top_z_mm, so a top faced to exactly top_z_mm
moved every level up by that guard. When the depth was a whole number
of stepdowns this left a last level one guard (1e-5 mm) below the one
above it: for an AdaptivePocket the whole region was then a sheet that
thick, and the engagement proof (correctly) could not bound the contact
angle of its strokes, so the level was refused. A Pocket repeated its
floor pass, identical at the posted resolution.

The levels below the first are each placed a stepdown below the tip of
the level above, not below the guard that level leaves; the first is
now measured the same way. Stock no more than the operation's
tolerance_mm above the top is at the top; stock standing higher still
raises the planning top, so no motion removes more than a stepdown of
the stock model (#344's guarantee, measured by the tests).

The standalone rest example's golden program and the rest-pocket
benchmark expectation return to their pre-#344 values (130 moves, 169
posted blocks instead of 186 and 225; material bounds unchanged).

Closes #381

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

AdaptivePocket: the last level at the floor is refused (engagement_front contact angle not proven) when the pocket's top is a faced floor

1 participant