by John Lauer
Two-board Molecule interferometer with onboard RP2040, USB-C data, 15 V USB-C PD power and a JST stage interface.
c0c5c9b
smi-dash: dashboard, simulator and CLI
One binary. smi-dash start runs a small local web server (Rust, axum) that owns all state: the data source (simulator or a Pico over USB serial), the fringe detector, the running displacement, recording and settings. The page in assets/index.html is drawn on canvases from a Server-Sent Events stream, and every button calls the same HTTP endpoint a CLI verb calls, so the page, the CLI and an AI always agree.
| File | Role |
|---|---|
src/sim.rs |
Lang-Kobayashi self-mixing model, target motions, multimode beat, the board's analog chain and the RP2040 ADC; with the board model, the laser's current dependence (power, tuning, mode hops); the stage profile follows the test stage's mirror |
src/controls.rs |
Board controls (1.2 and 1.3): the control map, the command protocol, and the simulated board, which runs the firmware's smi_ctl.c (compiled in by build.rs) and models the driver, the ADS1115, the DAC and the switches |
src/tune.rs |
Commands to the simulated board or the Pico, auto-centre, tune for fringes |
src/stage.rs |
Board 1.3 test stage: the protocol, the simulated stage (the firmware's smi_stage.c compiled in, a simulated TMC2209 and a mechanism model), the self-test analysis, Calibrate |
src/dsp.rs |
Fringe detector (low-pass, envelope, edge detection, direction) and the spectrum |
src/proto.rs |
Decoder for the firmware's framed stream, with resync and CRC |
src/engine.rs |
Sample rings, displacement history, display frames, acquisition and serial threads |
src/record.rs |
CSV (streamed) and HDF5 (written on stop) recording |
src/server.rs |
HTTP API, SSE live channel, settings, page console |
src/eval.rs |
Offline accuracy suites against the simulator's ground truth (--suite, and --board through the simulated board) |
src/main.rs |
CLI |
Use
smi-dash start # background server for this AI thread or user, port reused across restarts
smi-dash show # open it in a Hydrogen webview tab (show --surface pup for the pup browser)
smi-dash status # displacement, velocity, fringe rate, link and recording
smi-dash sim --profile sine --amp-um 10 --freq-hz 1
smi-dash source serial # first Pico found; --serial-port COM5 to choose
smi-dash record start --format csv --seconds 10
smi-dash eval --suite # the published error table
smi-dash stage home # test stage: home, step 128, step -500 --nm, selftest
smi-dash calibrate --beam-safe # the board calibrates itself with the stage as the moving target (simulator)
smi-dash stop
Run smi-dash --help or smi-dash <verb> --help for every flag. Each answer starts with OK: or ERROR: and ends with Hint: lines naming the next command; add --json for {status, data, hints}.
HTTP API
| Method and path | Purpose |
|---|---|
GET /events |
SSE: state, frame (about 30 per second), toast, click, reveal, cursor, reload |
GET /state, GET /frame, GET /health |
Current state with enums and ranges, one display frame, liveness |
POST /sim, /detect, /view, /source |
Partial JSON updates; unknown keys are refused with the valid list |
POST /zero, /record/start, /record/stop |
Displacement zero, recording |
GET/POST /settings |
Persisted settings |
POST /ui/{toast,click,reveal,cursor,reload} |
Drive the open page |
GET/POST /console |
The page's console, readable by the CLI |
GET /board |
Board state joined with the control map, the map and its hash, tune progress |
POST /board/laser |
{on: false}, or {on: true, confirm: "beam-safe"} |
POST /board/set |
{id, value, unit: units|counts|index}; id is a map id or an alias (laser, ch1-offset, ch2-amp, bias, ...) |
POST /board/read_current, /board/auto_centre, /board/clear_fault, /board/config |
Readback, centring, faults, current-sense rate and heartbeat timeout |
GET/POST /board/tune, POST /board/tune/stop |
Tune for fringes |
GET /stage |
Stage state, the 30 s commanded-against-counted trace, the self-test and Calibrate results |
POST /stage/cmd |
{action: status|home|step|move|speed|stop|off|current|selftest, value, unit: pulses|nm} |
POST /stage/align, GET /stage/selftest |
Put the counted trace on the commanded one now; the last self-test |
GET/POST /calibrate, POST /calibrate/stop |
Calibrate ({confirm: "beam-safe"}), its progress and report |
Settings persist in ~/.adom/instances/smi-dash/settings.json; each thread's simulator and view settings are restored from snapshots/ on the next start. An idle server saves and exits after 24 h (Settings, or --keep-alive). While the laser is on, or the stage driver is enabled, the server sends the firmware a heartbeat every second; if the server stops, the firmware turns the laser off and disables the stage after 3 s. View > keep_awake (smi-dash view --keep-awake on) makes the page hold a screen wake lock for unattended recordings; it is off by default.
Build
python3 ../controls/gen_controls.py ../controls/control-map.json # after any change to the control map
cargo build --release # Linux, needs libudev-dev, libhdf5-dev (and a C compiler: build.rs compiles smi_ctl.c and smi_stage.c)
cargo build --release --target x86_64-pc-windows-gnu --no-default-features # Windows, CSV only
cargo test --release
# smi-dash: dashboard, simulator and CLI
One binary. `smi-dash start` runs a small local web server (Rust, axum) that owns all state: the data source (simulator or a Pico over USB serial), the fringe detector, the running displacement, recording and settings. The page in `assets/index.html` is drawn on canvases from a Server-Sent Events stream, and every button calls the same HTTP endpoint a CLI verb calls, so the page, the CLI and an AI always agree.
| File | Role |
|---|---|
| `src/sim.rs` | Lang-Kobayashi self-mixing model, target motions, multimode beat, the board's analog chain and the RP2040 ADC; with the board model, the laser's current dependence (power, tuning, mode hops); the `stage` profile follows the test stage's mirror |
| `src/controls.rs` | Board controls (1.2 and 1.3): the control map, the command protocol, and the simulated board, which runs the firmware's `smi_ctl.c` (compiled in by `build.rs`) and models the driver, the ADS1115, the DAC and the switches |
| `src/tune.rs` | Commands to the simulated board or the Pico, auto-centre, tune for fringes |
| `src/stage.rs` | Board 1.3 test stage: the protocol, the simulated stage (the firmware's `smi_stage.c` compiled in, a simulated TMC2209 and a mechanism model), the self-test analysis, Calibrate |
| `src/dsp.rs` | Fringe detector (low-pass, envelope, edge detection, direction) and the spectrum |
| `src/proto.rs` | Decoder for the firmware's framed stream, with resync and CRC |
| `src/engine.rs` | Sample rings, displacement history, display frames, acquisition and serial threads |
| `src/record.rs` | CSV (streamed) and HDF5 (written on stop) recording |
| `src/server.rs` | HTTP API, SSE live channel, settings, page console |
| `src/eval.rs` | Offline accuracy suites against the simulator's ground truth (`--suite`, and `--board` through the simulated board) |
| `src/main.rs` | CLI |
## Use
```
smi-dash start # background server for this AI thread or user, port reused across restarts
smi-dash show # open it in a Hydrogen webview tab (show --surface pup for the pup browser)
smi-dash status # displacement, velocity, fringe rate, link and recording
smi-dash sim --profile sine --amp-um 10 --freq-hz 1
smi-dash source serial # first Pico found; --serial-port COM5 to choose
smi-dash record start --format csv --seconds 10
smi-dash eval --suite # the published error table
smi-dash stage home # test stage: home, step 128, step -500 --nm, selftest
smi-dash calibrate --beam-safe # the board calibrates itself with the stage as the moving target (simulator)
smi-dash stop
```
Run `smi-dash --help` or `smi-dash <verb> --help` for every flag. Each answer starts with `OK:` or `ERROR:` and ends with `Hint:` lines naming the next command; add `--json` for `{status, data, hints}`.
## HTTP API
| Method and path | Purpose |
|---|---|
| `GET /events` | SSE: `state`, `frame` (about 30 per second), `toast`, `click`, `reveal`, `cursor`, `reload` |
| `GET /state`, `GET /frame`, `GET /health` | Current state with enums and ranges, one display frame, liveness |
| `POST /sim`, `/detect`, `/view`, `/source` | Partial JSON updates; unknown keys are refused with the valid list |
| `POST /zero`, `/record/start`, `/record/stop` | Displacement zero, recording |
| `GET/POST /settings` | Persisted settings |
| `POST /ui/{toast,click,reveal,cursor,reload}` | Drive the open page |
| `GET/POST /console` | The page's console, readable by the CLI |
| `GET /board` | Board state joined with the control map, the map and its hash, tune progress |
| `POST /board/laser` | `{on: false}`, or `{on: true, confirm: "beam-safe"}` |
| `POST /board/set` | `{id, value, unit: units\|counts\|index}`; id is a map id or an alias (laser, ch1-offset, ch2-amp, bias, ...) |
| `POST /board/read_current`, `/board/auto_centre`, `/board/clear_fault`, `/board/config` | Readback, centring, faults, current-sense rate and heartbeat timeout |
| `GET/POST /board/tune`, `POST /board/tune/stop` | Tune for fringes |
| `GET /stage` | Stage state, the 30 s commanded-against-counted trace, the self-test and Calibrate results |
| `POST /stage/cmd` | `{action: status\|home\|step\|move\|speed\|stop\|off\|current\|selftest, value, unit: pulses\|nm}` |
| `POST /stage/align`, `GET /stage/selftest` | Put the counted trace on the commanded one now; the last self-test |
| `GET/POST /calibrate`, `POST /calibrate/stop` | Calibrate (`{confirm: "beam-safe"}`), its progress and report |
Settings persist in `~/.adom/instances/smi-dash/settings.json`; each thread's simulator and view settings are restored from `snapshots/` on the next start. An idle server saves and exits after 24 h (Settings, or `--keep-alive`). While the laser is on, or the stage driver is enabled, the server sends the firmware a heartbeat every second; if the server stops, the firmware turns the laser off and disables the stage after 3 s. `View > keep_awake` (`smi-dash view --keep-awake on`) makes the page hold a screen wake lock for unattended recordings; it is off by default.
## Build
```
python3 ../controls/gen_controls.py ../controls/control-map.json # after any change to the control map
cargo build --release # Linux, needs libudev-dev, libhdf5-dev (and a C compiler: build.rs compiles smi_ctl.c and smi_stage.c)
cargo build --release --target x86_64-pc-windows-gnu --no-default-features # Windows, CSV only
cargo test --release
```