The planner buffer depth harness; the XY microstep set is in

scripts/bench/planner_blocks_test.py restarts the null-sink controller
at $398=400 and at 1000 on one settings store and requires an answer on
the port, the depth in the status report and a move to Idle. It runs in
the grblHAL repo's CI; registered on the bench page and in the README.
BRINGUP: $398 runs over its whole range, the spin item is closed, and
the XY microstep item is committed, pushed and pinned. CAMPAIGN-LOG: the
landing and the index fix, with the host and bench proof.

No catalog consequence beyond the core submodule the motion tests
already cover; the coverage lint is clean.
This commit is contained in:
ScottW514
2026-09-07 18:38:39 -04:00
parent 0dc8c746e5
commit 59c4516c00
5 changed files with 283 additions and 13 deletions
+1
View File
@@ -35,6 +35,7 @@ page's takeover does that; from a host, stop them first.
| `z_envelope_test.py` | Host-side Z envelope harness (null-sink controller): the Z soft limit belongs to the driver, not to `$20`, so the driver re-applies `sys.work_envelope`, `sys.homed` and `sys.soft_limits` for Z from the settings-changed chain. Checks that an unreferenced Z is collapsed to where the lens stands and blocks a move each way, that X and Y stay free, and that neither a `$20` write (the core clears the soft-limit mask in the setter) nor a `$132` write (which un-homes the axis as well) frees Z. Runs in the grblHAL repo's CI. |
| `live_fire_drills.py` | **LIVE LASER** drills, on the board (the bench page) or from a LAN host (`GF_HOST`): `live_fire_drills.py <drill> [S] [F]` - `witness` (emission witness, lid-IR peaks vs the ambient baseline, HV current, job-based disarm on M2), `hold` (disarm grace in Hold), `faultpos` (armed job refuses a stale origin after an underrun), `ircut` (lid-IR characterization cut at S/F), `pthresh` (laser power-threshold ladder: 13 constant-power rungs from 2 % to 30 % of full on scrap; the lowest rung that marks is the tube's striking threshold and reads directly as the `$35` value - requires `$35` = 0 for the run), `dladder` (density ladder at a chosen base period), `pcurve` (laser performance-curve ladder: one 100 mm line per level at 10 mm/s under M3, the laser off between rungs and a mid-ladder rung repeated at the end; reads `pic/hv_current` and the head thermopile `head/beam_detect_analog` (a scatter detector in the beam path upstream of the final mirror, so it sees the beam, not the material) from sysfs at ~25 Hz on the board, brackets each rung on the controller's Run/Idle states, and reports per rung the current with a clipped-at-1023 flag, the thermopile delta over its laser-off baseline and in-line drift, then the normalized curve, monotonicity, a line fit with its threshold intercept and the repeat-rung drift; JSON record with the raw trace in the bench data directory; rungs follow `laser_power_model`, a comma list overrides; a curve measurement wants `$35` = 0), `dpatch [F] [pitch] [length]` (depth witness for the density dose curve: two rows of small serpentine-filled patches, row A CW at feeds giving relative doses 1.0 to 0.25 of the reference feed, row B at the reference feed at 100/80/60/45/30 % density; the operator matches each row-B patch to the row-A patch of equal depth, which reads the density's light fraction off the material beside the thermopile's prediction; JSON record), `m4feeds [S] [F1] [F2]` (the density time base across feeds: one out-and-back line pair per feed at the same S under M4 density, one armed run; the operator reads within-line evenness and reversal darkness at both feeds - M4's velocity scaling is what holds dose per mm through the accel), `m4corner [S] [F]` (M4 velocity-scaled power into corners: a corner-heavy vector pattern at 30 % under M4 density, one armed run; the operator confirms every commanded segment marks - the floor makes a dropout unreachable - and the drill asserts the arm report, one discharge window and dark after), `m5dark` (the rapids after an M5 ship dark: one 20 mm line at M3 S400, M5, dwell, rapid back, dwell, rapid forward; PASS when the 25 Hz current trace shows one discharge segment and reads dark after the M5 and `laser_on_sampled` never re-lights; the catalog's `laser.m5-rapid-dark` is its port), `flowload` (cooling under laser load, one armed run per invocation, the conf keys it writes put back at the end, the pump never commanded off: `t1` reproduces the flow-check trip with the check on at its defaults and two 30 x 4 mm CW fills at F1500 starting on the press with no dark dwell, and reports the engine's rise/dT verdict beside the 25 Hz trace of both coolant sensors, the current, the digital witness and the heater output in 5 s bins across the window, with the shape at fire start; `t2 <secs> [pct]` runs with the check off and one fill of about `secs` lit seconds at CW or at `pct` density, and reports the lag to each sensor, the rise per raw-second of `hv_current` and what a full 50 s window would add against the 1.6 C margin; `fit` fits rise against dose over every t2 record; JSON records), `expstop` (armed kill on the expected-stop path; needs the panel token - `GF_TOKEN`, or the board's token file) and `ctrlstart` (the separate controller restart after it). Every drill waits for the operator's physical arm press; eye protection, fire watch, extinguisher, and exhaust are mandatory. |
| `pacing_test.py` | Protocol-loop pacing check (runs on the board, dry motion): idle and parked-in-Hold states are coarse-paced, active motion is tight-paced, and a feed-hold/resume mid-move preserves position with no feeder starve. |
| `planner_blocks_test.py` | Host-side planner buffer depth harness (null-sink controller): `$398` written to 400 and to 1000, the controller restarted on the same settings store each time, and it must answer on the port, report the depth in its status report and run a move. A byte-wide ring index once made 255 blocks or more spin the start. Runs in the grblHAL repo's CI. |
| `xy_mode_test.py` | Host-side XY microstep mode harness (null-sink controller): `xy_microsteps` in the shared config sets `$100`/`$101` and the machine tick, a typed `$100` is overwritten on the spot, a value that is not a mode falls back to x8 with a warning, and `$110`/`$111` are held under a tick lowered with `GFSINK_RATE`. Runs in the grblHAL repo's CI. |
| `raster_dry.py` | A dry raster at top speed at each XY microstep mode (runs on the board; the controller in GRBL mode, idle, no other Grbl client): per mode given (default 8, 16, 32) it stores `xy_microsteps` through forgectrl, waits for the restarted controller, streams 60 passes of 150 mm at F12000 with the laser off, and reports the peak feed, the controller CPU, the kernel counters against the start, `cnc/underruns` and any clamped-event line. Needs 150 mm of free +X and 12 mm of free +Y travel. Ends at x8. |
| `xy_pattern_accel.py` | The XY microstep modes by the head accelerometer with the machine silent (runs on the board; the machine homed and at home, the lid closed, no other Grbl client): per mode it takes the cooling engine's quiet hold with the pump (`POST /cool/quiet?on=1&pump=1`: every fan, the pump and the TEC off), waits the fixed 10 s, samples the LIS2HH12 over `/dev/i2c-3` in one SMBus block transaction per reading at about 600 Hz, and runs the pattern from home at F12000: to (18, 9) in, to (9, 9) in, a 9 in circle from its mid-bottom back to (9, 9), to (9, 0), home. Reports the cruise-window RMS and peak-to-peak per leg and overall, the leg times, the kernel counters against home and `cnc/underruns`; JSON with the trace in the bench data directory. Ends at x8. |
+223
View File
@@ -0,0 +1,223 @@
#!/usr/bin/env python3
"""Host-side verification that a deep planner buffer starts.
$398 (planner buffer blocks) is a reboot-required setting with a range of
30 to 1000. The core links the block ring at start, one block after
another, and the index that walks the ring has to hold every block
number up to the buffer size: a byte-wide index never reaches 255, and a
buffer of 255 blocks or more then spins the controller at start. The
main thread sits at 100 percent in the planner reset, the Grbl port
accepts a connection (the listener is its own thread) and never answers,
and the supervisor still reports the controller running.
Runs the native grblHAL_glowforge binary in null-sink mode (no hardware,
no root) and drives it over TCP, keeping one settings store across
restarts:
1. a fresh store starts and reports its default $398
2. $398=400 is accepted and read back
3. the controller restarted on that store answers on the port, reports
400 blocks, and the status report shows a planner that deep
4. the same at $398=1000, the top of the range
5. a motion line runs to completion on the deep buffer
A controller that connects and never answers after the restart is the
failure this harness exists for. Every exit kills the controller it
started, so a spinning one never outlives the run or holds the port.
The binary keeps its settings in EEPROM.DAT in the working directory, so
each run starts from defaults in a temporary directory and leaves
nothing behind.
Usage: planner_blocks_test.py [path-to-binary]
(default ./build-native/grblHAL_glowforge)
"""
import os
import re
import shutil
import socket
import subprocess
import sys
import tempfile
import time
BIN = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else "build-native/grblHAL_glowforge")
PORT = 2401
CONNECT_S = 8.0
ANSWER_S = 5.0
DEEP = 400
TOP = 1000
_live = None # the controller process a failure has to take down
def fail(msg):
print("FAIL: %s" % msg)
if _live is not None:
_live.stop()
sys.exit(1)
class Session:
"""One null-sink controller process on a settings store that outlives it."""
def __init__(self, workdir):
global _live
self.workdir = workdir
env = dict(os.environ, GF_STATE_DIR=self.workdir, FFLOG_STDERR="1")
for key in ("GFSINK", "GF_SWITCH_FILE", "GF_VERDICT_FILE"):
env.pop(key, None)
self.proc = subprocess.Popen([BIN, "-p", str(PORT)],
cwd=self.workdir, env=env,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE)
_live = self
self.sock = self.connect()
self.read(1.0) # banner and any boot messages
def connect(self):
end = time.time() + CONNECT_S
while time.time() < end:
try:
return socket.create_connection(("127.0.0.1", PORT), timeout=1)
except OSError:
time.sleep(0.1)
err = b""
if self.proc.poll() is not None:
err = self.proc.stderr.read() or b""
fail("the controller never opened the port within %.0f s (exit=%s)\n%s"
% (CONNECT_S, self.proc.poll(), err.decode(errors="replace")))
def read(self, timeout=0.8):
out = b""
end = time.time() + timeout
while time.time() < end:
self.sock.settimeout(max(0.05, end - time.time()))
try:
data = self.sock.recv(4096)
except (socket.timeout, OSError):
break
if not data:
break
out += data
return out.decode(errors="replace")
def send(self, line, timeout=1.0):
self.sock.sendall(b"?" if line == "?" else (line + "\n").encode())
return self.read(timeout)
def answers(self):
"""True when the controller answers a settings query at all."""
return "$398=" in self.send("$398", ANSWER_S)
def setting(self, key):
reply = self.send(key)
m = re.search(r"^%s=(\S+)" % re.escape(key), reply, re.M)
if not m:
fail("no value reported for %s: %r" % (key, reply))
return m.group(1)
def write_setting(self, assignment):
reply = self.send(assignment)
if "ok" not in reply:
fail("settings write %r refused: %r" % (assignment, reply))
def report(self):
return self.send("?")
def state(self):
m = re.search(r"<(\w+)", self.report())
return m.group(1) if m else "?"
def planner_free(self):
"""The planner blocks the status report shows free (Bf:<blocks>,<rx>)."""
m = re.search(r"\|Bf:(\d+),", self.report())
if not m:
fail("no buffer field in the status report")
return int(m.group(1))
def wait_idle(self, timeout=5.0):
end = time.time() + timeout
while time.time() < end:
if self.state() == "Idle":
return True
time.sleep(0.1)
return False
def stop(self):
global _live
try:
self.sock.close()
except (OSError, AttributeError):
pass
self.proc.terminate()
try:
self.proc.wait(timeout=5)
except subprocess.TimeoutExpired:
self.proc.kill()
self.proc.wait()
_live = None
def check(ok, ok_msg, fail_msg):
if not ok:
fail(fail_msg)
print("ok %s" % ok_msg)
def restart_on(workdir, blocks):
"""Write $398, restart on the same store, and prove the controller answers."""
s = Session(workdir)
s.write_setting("$398=%d" % blocks)
check(s.setting("$398") == str(blocks),
"$398=%d accepted" % blocks, "$398=%d not read back" % blocks)
s.stop()
s = Session(workdir)
check(s.answers(),
"the restarted controller answers at $398=%d" % blocks,
"the controller restarted at $398=%d accepts the connection and never "
"answers within %.0f s: the start spins" % (blocks, ANSWER_S))
check(s.setting("$398") == str(blocks),
"it reports $398=%d" % blocks, "it reports another $398")
s.write_setting("$10=%d" % (int(s.setting("$10")) | 2)) # buffer state in the report
free = s.planner_free()
check(free >= blocks - 1,
"the status report shows %d planner blocks free" % free,
"the status report shows %d planner blocks free, expected at least %d"
% (free, blocks - 1))
return s
def main():
if not os.path.isfile(BIN):
fail("no controller binary at %s" % BIN)
workdir = tempfile.mkdtemp(prefix="planner-blocks-")
try:
s = Session(workdir)
check(s.answers(), "a fresh store starts and answers",
"a fresh store does not answer")
print(" default $398=%s" % s.setting("$398"))
s.stop()
s = restart_on(workdir, DEEP)
s.stop()
s = restart_on(workdir, TOP)
reply = s.send("G91 G1 X1 F600", 1.5)
check("ok" in reply and "error" not in reply and "ALARM" not in reply,
"a motion line is accepted on the deep buffer",
"the motion line was refused: %r" % reply)
check(s.wait_idle(), "the move completes and the controller is Idle",
"the controller did not return to Idle after the move")
s.stop()
print("PASS: the planner buffer starts at %d and %d blocks" % (DEEP, TOP))
finally:
if _live is not None:
_live.stop()
shutil.rmtree(workdir, ignore_errors=True)
if __name__ == "__main__":
main()