Skip to content

Posts: an axis the controller placed keeps no word until the program moves it - #368

Merged
10-X-eng merged 1 commit into
mainfrom
fix/placed-axes-keep-no-word
Nov 21, 2026
Merged

10-X-eng merged 1 commit into
mainfrom
fix/placed-axes-keep-no-word

Conversation

@10-X-eng

Copy link
Copy Markdown
Contributor

Closes #367.

The rule

A straight move (G0/G1) leaves out the word of an axis it does not move while that axis is still where the controller placed it itself:

  • every axis at the program start (the header moves none; PostEngine already refuses one that does);
  • after a tool change, from its change block (the dialect's M6, or the T word with tool_change="direct_t"/"lathe_t"): Z with tool_change_position_mode="z_home", every axis with "table" (the decoder puts every axis at position_after_mm). preserve_tip and preserve_spindle place nothing;
  • an axis leaves that state with the first block, from any hook, that names its word. Words are read as the machine check reads them (axis_words in src/machine/session.rs: the letter outside comments, unbalanced parentheses count every axis). That covers arcs, helices, canned cycles, tapping, threading and controller blocks such as FANUC/LNC G1 G43 H.. Z.. and Carvera G53 G0 Z-3. A probing cycle leaves every axis written, since its macros move axes their blocks need not name.

A word is left out only when the value the block would write equals the current decoded position exactly. The existing vertical-move rule keeps the current XY, so a move vertical in the plan qualifies. A block that turns cutter compensation on or off is written whole. A block that would be left with no axis word (it moves nothing) is also written whole, because a bare G0 is a keyword to the native decoder and not a motion block. Arcs, helices, cycles, probing, tapping and threading are unchanged.

Where it lives (Python and Rust write the same blocks):

  • Python: PostProcessor._call → _track_placed, plus the module helpers _uncommented/_axis_words/_changes_tool. The omission is in GCodePost.on_motion. The native fast paths _format_default and consume pass _placed to the native formatter and read it back.
  • Native default formatter: DefaultMotionPost.motions/format_decode and IntentSession.consume_default in bindings/python/src/lib.rs.
  • Rust: DefaultPost::call → track_placed, and DefaultPost::on_motion (src/gcode/post.rs). This is the default post plus the Haas NGC and Carvera named pairs.
  • Controller posts in examples/ (Carvera, Haas, FANUC 0i-MB, LNC, Siemens 808D native and ISO, Centroid mill, lathe and plasma, FANUC lathe, GRBL, QtPlasmaC, WinCNC) all inherit it through GCodePost.on_motion/_call. On lathes it applies to X/Z. GRBL's own vertical-move branch already writes Z only. The plasma posts never write Z.

Decoders: the Python, native and Rust decoders already read an absent word as the modal position. The FANUC test oracle (python/tests/fanuc_0imb_oracle.py) required X, Y, Z and F in every G1, so it now reads an absent axis word as modal, as the control does. The other oracles already accepted subsets. decoded_initial_position_mm is unchanged, since decoders start at the declared position.

Tests (each fails without the change)

  • tests/machine.rs::a_move_from_a_pose_on_the_travel_limits_writes_only_the_axes_it_moves: post_job on the new fixture fixtures/posts/rust/homed-facing.json (a Facing from the home pose of a LinuxCNC mill homed at X 0/Y 0 travel minimums, Z top, work error ±0.02). It must release with nothing accepted, the machine check clear and complete, the program equal to the Python one (homed-facing.nc), and the first blocks G0 Z12, G0 X-5 Y3.2 Z12. On main it is refused: "axis X calibration interval -0.020000 to 0.020000 mm (expected position 0.000000 mm) straddles the minimum".
  • tests/machine.rs::a_z_home_tool_change_places_z_until_a_block_writes_it: post_program with a z_home machine. The blocks are G0 Z12, G0 X-5 Y3.2 Z12, then after the second M6 G0 X0 Y0 (no Z), then G0 X0 Y0 Z12. On main they are G0 X-250 Y-200 Z12 … G0 X0 Y0 Z90.
  • python/tests/test_placed_axes.py:
    • the facing case through Job.post_nc (text, machine clear, Rust post_job identical, fixture equal to both);
    • native formatter vs Python hooks give identical text;
    • the old every-word output (forced through _placed) is refused uncertain with the straddle finding;
    • a z_home two-tool drilling job: first blocks after the M6s are G0 Z12 and G0 X8 Y8, Rust identical;
    • _placed after begin, table/z_home/preserve_tip tool changes and a canned cycle.

Existing expectations changed (only the first block after the start or a table tool change)

Each case keeps an axis the controller placed, so it loses that word:

  • fixtures/posts/rust/standalone-rest.nc: G0 X-3 Y1.6 Z8 → G0 X-3 Y1.6.
  • fixtures/posts/rust/carvera-drill.nc: G0 X8 Y8 Z12 → G0 X8 Y8.
  • fixtures/posts/rust/carvera-arcs.nc: G0 X6 Y13 Z14 → G0 X6 Y13.
  • fixtures/posts/rust/haas-program.nc: G1 X10. Y0. Z3. F1200. → G1 X10. F1200..
  • fixtures/posts/F0IMB1000.NC and fixtures/posts/LNC-MILL-ARCS.NC: G1 X10. Y0. Z3. F1200. → G1 X10. Z3. F1200.. Z stays, because the G1 G43 H7 Z3. block wrote it. The same sample is in docs/lnc-mill-post.md.
  • test_feed_traverse (G1 X10 F600), test_siemens808d_iso_post (G1 X10. F3000.), test_python_posts (G101 U10 E1200): the shared fixture moves X only from its table pose.
  • test_post_decode: helper calls 5 → 3 (S, X, F).
  • test_python_posts terminal-position comment: the check now compares with the decoded position itself. The unwritten Y/Z keep the declared values as given (int in the Python decoder path, float in the native one); the numeric check (10.0, 0.0, 3.0) above it is unchanged.

Nothing else in the suites changed.

Evidence

Tested on commit f9c0c93 (branch on main 90d22cf). Linux x86_64 (Ubuntu), local Rust 1.98, Python 3.12 without CadQuery/OCP/numpy.

Check Result
cargo test --profile ci --workspace --all-features --lib --tests passed: 497 unit, 678 integration
cargo test --profile ci --test integration rust_ after the fixture regeneration passed: 30
New Rust tests against main's src/gcode/post.rs both fail, as shown above
cargo fmt --check, ruff check, ruff format --check clean
cargo clippy --workspace --all-targets --all-features -- -D warnings (local 1.98) fails only on the known needless_range_loop in the untouched src/surface/spline_bounds.rs; clean with that lint allowed. CI's 1.100 decides
python -m unittest discover -s python/tests (release build) 1021 run, 150 errors, all No module named cadquery/OCP/numpy; no other failure or error

Not run locally (CI decides):

  • the CadQuery tests;
  • test_linuxcnc_interpreter (no rs274 here);
  • the benchmarks, which need CadQuery (posting only, so the toolpaths cannot change);
  • clippy on Rust 1.100;
  • macOS and Windows.

The release extension used for the Python run was built before a cargo fmt that only reformatted one closure in bindings/python/src/lib.rs.

Follow-up noted, not changed here

The machine check counts every axis letter in header blocks, such as Haas/FANUC G52 X0 Y0 Z0 and Haas G100 X0 Y0 Z0, which move no axis. On those controllers a start pose on a travel limit can therefore still be reported uncertain even though the post now leaves the words out.

🤖 Generated with Claude Code

…moves it

A straight move (G0/G1) now leaves out the word of an axis it does not
move while that axis is still where the controller placed it itself:
every axis at the program start, Z after a z_home tool change and every
axis after a table tool change (from the M6, or the T word that changes
the tool). An axis leaves that state with the first block that names its
word (any hook: moves, arcs, cycles, taps, threads, controller blocks
such as FANUC's G43 Z or Carvera's G53 Z), and every axis with a probing
cycle. A word is left out only when the value equals the current
position exactly, never in a compensation on/off block, and a block
that would keep no axis word is written whole.

A word of an unchanged value still commands the axis through the
controller's actual work offset; at a travel limit it moved the axis by
the calibration error, past the limit. A Facing from the home pose of a
mill homed at its minimums now posts G0 Z12 first and releases clear.

Python (PostProcessor._call/_track_placed, GCodePost.on_motion), the
native default formatter (DefaultMotionPost) and the Rust DefaultPost
(default, Haas NGC, Carvera) apply the same rule; the controller posts
in examples/ inherit it. Expected programs change only in those first
blocks; the FANUC test oracle reads an absent axis word as modal.

Closes #367.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@10-X-eng
10-X-eng added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 05c9a94 Nov 21, 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.

Posts: an axis the controller placed keeps no word until the program moves it

1 participant