Repository navigation
fix(gcode): emit a self-describing modal preamble (G21/G90/G94) (#322) - #324
Merged
Merged
Conversation
Every program now begins with a modal preamble — `G21` (mm units), `G90` (absolute positioning), `G94` (feed in units per minute) — right after the `; Parameters` header, so the output no longer silently depends on the controller's power-on modal state. Previously `MarlinDialect.prologue()` existed but was never wired into `serialize()`, and the toolchain emitted no setup codes (inherited from the original Cyclone reference); it worked only because Marlin's defaults happen to match, and marlin-host's handshake sends only `M110`. The preamble is a serialization concern (like the `; Parameters` header), not motion, so it stays out of the Motion IR: `serialize()` emits it from the dialect, and `read_program` skips the modal lines it represents, keeping the round-trip byte-exact. The skip set is exactly the modes the reader already assumes (`G21`/`G90`/`G94`); the opposite modes (`G20` inch, `G91` relative, `G93` inverse-time) still raise `ProgramReadError` rather than be silently misread as absolute mm. The `marlin-xab` profile's `requiredGcodes` now lists the full emitted set (`G0/G21/G90/G92/G94`), and the machine-profile guide states the preamble as the compatibility contract. Example goldens regenerated: motion bytes unchanged, three preamble lines added.
This was referenced Jun 30, 2026
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 #322.
Problem
FiberPath emitted no modal setup codes.
MarlinDialect.prologue()existed but was never wired intoserialize()— dead since introduction, inherited from the original Cyclone TS reference (which also emitted none). A streamed program relied entirely on the controller's power-on modal state for units, positioning, and feed mode; marlin-host's handshake sends onlyM110(line-number reset), nothing modal. It works today only because Marlin's defaults (mm / absolute / units-per-minute) happen to match — a latent footgun if the controller isn't freshly at defaults.Change
serialize()now emits a preamble right after the; Parametersheader:serialize()emits it from the dialect;read_programskips the modal lines, soserialize(read_program(g))stays byte-exact.{G21, G90, G94}(the modes the reader already assumes) are skipped.G20(inch) /G91(relative) /G93(inverse-time) still raiseProgramReadError— silently dropping them would make the simulator/plotter misread an external program's coordinates. (This preserves the pre-Dead code: MarlinDialect.prologue() is never emitted — G21/G94 (units & feed-mode) absent from output #322 fail-loud behavior for unsupported modes.)marlin-xab'srequiredGcodesnow lists the full emitted setG0/G21/G90/G92/G94; the machine-profile guide states the preamble as the compatibility contract (resolving the "FiberPath does not emit these" caveat from spec: machine-profile / firmware-compatibility spec ('what hardware must meet to be compatible') #197).units/feedModeprofile fields functional (they now drive the preamble) instead of declarative-only.Goldens
All 7 example goldens regenerated: exactly +3 lines each, 0 motion bytes changed (verified via numstat). The cone example stays equivalence-gated (no byte golden). Sim/plot snapshot is unchanged (it's IR-based; the preamble is skipped on read).
Tests / checks
pytest244 pass — incl. round-trip byte-exact on regenerated goldens, a newtest_modal_preamble_lines_are_skipped, andtest_unhonorable_modes_still_raise(G20/G91/G93). · ruff/format/scoped-mypy clean · no wind-schema/openapi drift.{G21,G90,G94}with a regression test. Round-trip, dialect detection, andrequiredGcodescompleteness all verified correct.Decision
Per maintainer call on #322: emit (self-describing output) over require (document-only). Includes
G90(absolute) alongside G21/G94 — same class of assumption, and the most dangerous one to leave implicit.