Repository navigation
Posts: an axis the controller placed keeps no word until the program moves it - #368
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
M6, or theTword withtool_change="direct_t"/"lathe_t"): Z withtool_change_position_mode="z_home", every axis with"table"(the decoder puts every axis atposition_after_mm).preserve_tipandpreserve_spindleplace nothing;axis_wordsinsrc/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/LNCG1 G43 H.. Z..and CarveraG53 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
G0is 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):
PostProcessor._call→_track_placed, plus the module helpers_uncommented/_axis_words/_changes_tool. The omission is inGCodePost.on_motion. The native fast paths_format_defaultandconsumepass_placedto the native formatter and read it back.DefaultMotionPost.motions/format_decodeandIntentSession.consume_defaultinbindings/python/src/lib.rs.DefaultPost::call→track_placed, andDefaultPost::on_motion(src/gcode/post.rs). This is the default post plus the Haas NGC and Carvera named pairs.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 throughGCodePost.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_mmis 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_jobon the new fixturefixtures/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 checkclearand complete, the program equal to the Python one (homed-facing.nc), and the first blocksG0 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_programwith a z_home machine. The blocks areG0 Z12,G0 X-5 Y3.2 Z12, then after the second M6G0 X0 Y0(no Z), thenG0 X0 Y0 Z12. On main they areG0 X-250 Y-200 Z12 … G0 X0 Y0 Z90.python/tests/test_placed_axes.py:Job.post_nc(text, machineclear, Rustpost_jobidentical, fixture equal to both);_placed) is refuseduncertainwith the straddle finding;G0 Z12andG0 X8 Y8, Rust identical;_placedafter 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.NCandfixtures/posts/LNC-MILL-ARCS.NC:G1 X10. Y0. Z3. F1200.→G1 X10. Z3. F1200.. Z stays, because theG1 G43 H7 Z3.block wrote it. The same sample is indocs/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_poststerminal-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.
cargo test --profile ci --workspace --all-features --lib --testscargo test --profile ci --test integration rust_after the fixture regenerationsrc/gcode/post.rscargo fmt --check,ruff check,ruff format --checkcargo clippy --workspace --all-targets --all-features -- -D warnings(local 1.98)needless_range_loopin the untouchedsrc/surface/spline_bounds.rs; clean with that lint allowed. CI's 1.100 decidespython -m unittest discover -s python/tests(release build)No module named cadquery/OCP/numpy; no other failure or errorNot run locally (CI decides):
test_linuxcnc_interpreter(no rs274 here);The release extension used for the Python run was built before a
cargo fmtthat only reformatted one closure inbindings/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 Z0and HaasG100 X0 Y0 Z0, which move no axis. On those controllers a start pose on a travel limit can therefore still be reporteduncertaineven though the post now leaves the words out.🤖 Generated with Claude Code