Skip to content

feat(sequencer): flat programs (StackAxisType.NONE) - a single plane is one burst per FOV, with or without a piezo - #877

Draft
hongquanli wants to merge 6 commits into
feat/hardware-sequencer-workerfrom
feat/hardware-sequencer-flat-programs
Draft

hongquanli wants to merge 6 commits into
feat/hardware-sequencer-workerfrom
feat/hardware-sequencer-flat-programs

Conversation

@hongquanli

Copy link
Copy Markdown
Contributor

A single-plane acquisition (one Z, several channels per position) has had no legal sequencer program: the loop always names a stepper or piezo stack axis, and the worker's eligibility check admitted only acquisitions whose z-stack uses the piezo. This PR gives the program a flat shape and lets a single plane run as one hardware-sequenced burst per position, on systems with or without a piezo. Stacked on #656 (base branch feat/hardware-sequencer-worker); retargeted when it merges.

One wire value, the same rules on both sides

StackAxisType::None = 2 (firmware) / StackAxisType.NONE = 2 (host). Valid only with n_layers == 1, dz == 0 and no return move; stack_axis_id is ignored (the host writes NONE_ID); a channel z_offset on a flat program is refused (BadChannel with the channel index), because there is no axis to offset along. The layout is unchanged and WIRE_VERSION stays 2: older firmware does not know the value and answers BadStackAxis, so a flat program fails loud there instead of being misread.

  • Firmware: seq::validate() applies the three rules; SeqEngine::stack_range_ok() has no range to check and accepts any SEQ_RUN stack start; command_stack() makes no HAL call, so no DAC or axis is ever written, and honours z_settle_us once as the wait before the first exposure (see below). finish() needs no change (no return move).
  • Host mirror: the same rules in SequencerProgram.validate(), check_stack_range() as a no-op; the header cross-check test ties the two enums together.
  • Golden vector: a second pinned program, FLAT_HEX with CRC 0xCE65, asserted byte for byte in Python and in the firmware's wire test, so the two sides cannot drift.
  • Simulator: no change was needed; a flat program runs its channels once from any stack start on both serial fakes.

The one wait a flat program keeps (please confirm)

On a piezo system a single plane used to run as a 1-layer piezo program whose first PREP waited z_settle_us (MULTIPOINT_PIEZO_DELAY_MS) before the first trigger. In practice that settled the piezo right after the per-FOV laser-AF offset move, which is open loop and has no settle of its own. A flat program that fired on the first tick would expose the first channel while that piezo may still be moving, so the engine honours z_settle_us once for a flat program, and the host sends the piezo settle only when a piezo exists and 0 without one (StackPlan.settle_us()). A system without a piezo gains no wait; piezo systems keep the timing they had. This came out of the branch's review and is a small amendment to the design; the alternative was a host-side sleep keyed on "laser AF moved the piezo".

Worker

StackPlan decides once per acquisition how a burst drives z: NONE for a single plane (with or without a piezo), PIEZO for a stack (which needs the piezo range). build_program() takes the plan instead of the piezo range and flip. On a flat run the burst path never touches the piezo: the stack start is 0, the capture metadata carries no piezo z, and the per-level piezo bookkeeping and the move back after a failed burst run only when there is a piezo. A single plane without a piezo is now eligible; a z-stack without one keeps its reason.

Tests

Firmware: 6 validation tests, 2 engine tests (nothing moves, any stack start runs), 2 wire tests (the flat golden and its parse). Host: the flat golden and its round trip, the NONE rules, the range check, a simulator run on both fakes, StackPlan and the flat builder, eligibility, and two end-to-end runs in simulation: a two-FOV single plane without a piezo uploads one NONE program, the controller fires one burst per FOV, and the images and data files match the software-sequenced run; on a piezo system the same acquisition is flat and keeps the piezo position in its metadata. Whole native suite 348, host sequencer and worker suites green; both firmware images build. One fresh-context review pass ran on the branch; its one Important finding is the settle above, fixed here; its minors are listed below.

Reflash note

A controller flashed with sequencer firmware from before this branch does not know the None value and refuses every single-plane sequenced run with BadStackAxis (loud, but it does not yet say why). Reflash before running single planes sequenced; a host-side hint naming the remedy is a follow-up.

Review minors, deferred

  • A host-side hint for the refusal above, and the kWireVersion comment in seq_wire.h lacks the "v2 also admits None" note the host comment has.
  • The end-to-end test does not read coordinates.csv to assert there is no piezo column on a run without a piezo.
  • Three if start_um is not None guards in the burst path, as the plan prescribed; on a flat piezo run the move back after a failed burst is a harmless redundant write.
  • Comment drift (seq_engine.h start / stack_range_ok, seq_wire.h kOpSeqRun, Microcontroller.seq_run, one worker comment) does not mention None; StackPlan has no __post_init__ against a hand-built piezo plan without a range.

Hand-off when this merges into #656

#790 builds one single-channel program per channel: its build_program call(s) take stack= now. #792 is on wire version 3: FLAT_HEX / kFlatHex start 03 there and FLAT_CRC16 is recomputed with crc16_ccitt_false; seq_types.h keeps both that branch's additions and None = 2.

🤖 Generated with Claude Code

hongquanli and others added 6 commits November 29, 2026 03:33
A single-plane acquisition has had no legal program shape: the loop always
names a stepper or piezo axis. None (2) is a program that moves nothing;
validate() accepts it only with n_layers 1, dz 0 and no return move, ignores
stack_axis_id, and refuses a channel z offset (BadChannel with the index):
with no axis to offset along it would be silently ignored. Older firmware
answers BadStackAxis for the unknown value, so a flat program fails loud
there instead of being misread.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…program

stack_range_ok() has no range to check for a flat program and accepts any
stack_start (SEQ_RUN's argument is ignored, as validate() pinned n_layers 1
and dz 0); command_stack() arms the settle gate as already elapsed and makes
no HAL call, so the first exposure is scheduled on the first tick and no DAC
or axis is ever written. finish() needs no change: validate() forbids a
return move for None.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ge for StackAxisType.NONE

The host enum gains NONE = 2 (the header cross-check test requires both sides
to change together); validate() applies the firmware's three rules (one
layer, no step, no return move; the axis id is ignored) and refuses a channel
z offset on a flat program; check_stack_range() has nothing to check.
WIRE_VERSION stays 2: the layout is unchanged and older firmware answers
BadStackAxis. A second golden vector, FLAT_HEX / 0xCE65, is pinned in Python
and in the firmware's wire test, so the two sides cannot drift apart. The
simulator needed no change: a flat program runs its channels once from any
stack start on both serial fakes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…eligible without a piezo

StackPlan decides once per acquisition how a burst drives its z axis: NONE
for a single plane (with or without a piezo), PIEZO for a stack (which needs
the piezo range). build_program() takes the plan instead of the piezo range
and flip, emits a NONE loop (axis id NONE_ID, dz 0, no return move) for a
single plane, and refuses a flat plan with more than one layer or a channel
z offset. A single plane without a piezo is eligible; a stack without one
keeps its reason.

The worker still calls build_program() with the old arguments; the next
commit moves it to the plan.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…or without a piezo

The worker decides a StackPlan once per acquisition and builds its program
from it; a single plane is a flat (NONE) program, so a system without a
piezo is eligible. The burst path no longer touches the piezo on a flat run:
the stack start is 0 (the controller ignores it), the capture metadata
carries no piezo z, and the per-level piezo bookkeeping and the move back
after a failed burst run only when there is a piezo. The log line says
'flat (no stack axis)' instead of a layer count.

End to end, in simulation: a two-FOV single-plane acquisition without a piezo
uploads one NONE program, the controller fires one burst per FOV, and the
images and files match the software-sequenced run; on a piezo system the
same acquisition is flat too and keeps the piezo position in its metadata.
The harness compares data files only (the save-job runner's warning log
appears with its first warning, a matter of timing).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…t exposure when a piezo exists

Review finding on the branch: on a piezo system a single plane used to run as
a 1-layer PIEZO program whose first PREP waited z_settle_us before the first
trigger, which in practice settled the piezo right after the per-FOV laser AF
offset move (an open-loop move with no settle of its own). A None program
fired on the first tick, so the first channel could be exposed while the
piezo was still moving.

The engine's None branch now honours z_settle_us once, as the wait before the
first exposure (still no DAC or axis write). StackPlan.settle_us() sends the
piezo settle for a flat program when a piezo exists and 0 when there is none
(nothing can have moved), so a system without a piezo gains no wait. The
engine test runs with a 50 ms settle and pins both the wait and that nothing
else is waited for; the builder and end-to-end tests pin 0 and the piezo
settle respectively.

Also drops the redundant 'self.piezo is not None' guard (set_use_piezo refuses
use_piezo without a piezo).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

1 participant