firmament: move pattern playback to the laptop and lay out the plan
The phone now only records; a laptop loops a self-clocking pattern over
DDP, so sync comes from the frames. Records the language and capture
decisions, explains bundle adjustment, and orders the milestones.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RTqTY6rxipjjiFzKVTpHeu
diff --git a/README.md b/README.md
index c63c702..1a58a12 100644
--- a/README.md
+++ b/README.md
@@ -31,8 +31,10 @@ do the mapping with an iPhone Pro (ARKit + LiDAR) and a WLED-driven string.
- Research and notes: written (2026-11-14), compiled from a web research
session plus earlier chats from October and November 2026.
- `firmament/`: design only.
-- Next step: a tracking spike, to see whether ARKit tracking survives a dim
- room with a blinking string.
+- Next steps (see [`firmament/DESIGN.md`](firmament/DESIGN.md#plan)): pin
+ down the pattern and session format, build the DDP pattern player, then a
+ tracking spike to see whether ARKit tracking survives a dim room with the
+ pattern running.
## A note on provenance
diff --git a/firmament/DESIGN.md b/firmament/DESIGN.md
index 0075b98..644fee4 100644
--- a/firmament/DESIGN.md
+++ b/firmament/DESIGN.md
@@ -1,14 +1,22 @@
# firmament design
-Draft, 2026-11-14. Everything here is a plan, not a record of what works.
+Draft, 2026-11-14; revised 2026-11-22. Everything here is a plan, not a record
+of what works.
-## Principle: phone records, laptop solves
+## Principle: the laptop plays, the phone records, the laptop solves
-The iPhone app only records. Each capture session saves frames, per-frame
-poses and intrinsics, depth, and a timeline of what pattern WLED was showing.
-The solver runs offline on a laptop, in any language. That means the solver can
-be improved and re-run without re-walking the tree, and sample sessions can
-live in the repo as test data.
+- **Laptop plays.** A small script loops the ID pattern to WLED over DDP. The
+ phone has no part in LED control.
+- **Phone records.** The iPhone app saves frames, per-frame ARKit poses and
+ intrinsics, and depth. It doesn't need to know what the LEDs are doing.
+- **Laptop solves.** The solver runs offline on the recordings.
+
+The pattern clocks itself: each cycle starts with all-on and all-off sync
+frames that are visible in the images, so the solver finds bit boundaries from
+the frames themselves. That removes Wi-Fi jitter and DDP latency from the sync
+problem, and keeps the phone app small. The solver can also be improved and
+re-run without re-walking the tree, and sample sessions can live in the repo
+as test data.
## Parameters (the first target)
@@ -21,77 +29,121 @@ live in the repo as test data.
| WLED outputs | 2 x 250 | to confirm: indices continue across both outputs |
| Tree | ~2.29 m tall, ~0.58 m base radius | approximate cone prior |
+## Decisions
+
+- **Solver language: Python** (NumPy, OpenCV, SciPy). The problem is small
+ (500 points, a few dozen stations); revisit only if it's slow.
+- **Stations, not continuous capture,** for v1: hold still for a cycle or two,
+ then move. Continuous capture can come later on the same session format.
+- **Capture app: native Swift** (a Mac with Xcode is on hand). An
+ off-the-shelf LiDAR recorder that exports per-frame poses could stand in for
+ a first spike; not checked which ones do.
+
## Pipeline
-### 1. Capture (iPhone)
+### 1. Pattern player (laptop, Python)
+
+- Streams frames to WLED over DDP. 500 LEDs is about 1.5 KB per frame.
+- One cycle, looped forever:
+ 1. all on (sync, and each LED's "on" brightness)
+ 2. all off (sync, and the background)
+ 3. 9 gray-code bits, plain white on/off
+ 4. a parity bit
+- Each slot is held for 3 or more camera frames. At 30 fps and 100 ms per
+ slot, a 12-slot cycle is about 1.2 s.
+- Low brightness, to limit blooming and stay well inside the 10A supply.
+- Debug modes: light a single index, or a single strand. Use these to answer
+ whether WLED indices continue across the two 250-pixel outputs (light LED
+ 250 and see which strand it's on).
+- Optionally logs its own timeline, for debugging only; the solver must not
+ depend on it.
+
+### 2. Recorder (iPhone, Swift)
- ARKit world-tracking session, gravity-aligned, with scene depth enabled.
-- LED control: stream frames to WLED over DDP (or UDP realtime), not the JSON
- API. 500 LEDs is about 1.5 KB per frame.
-- Pattern, per station: all-on flash, all-off flash (sync), then 9 gray-code
- bits as plain white on/off, then a parity bit. Hold each bit for 3 or more
- camera frames. Repeat the cycle for redundancy.
-- Stations: stand still for 1-2 seconds, then move on. Cover the tree from many
- heights and angles, including above and below.
-- Lock exposure if the capture device allows it; otherwise lower LED
- brightness.
-- Record per frame: timestamp, camera transform, intrinsics, image size,
- tracking state; plus the pattern timeline.
-
-### 2. Solver (laptop)
-
-1. **Detect** blobs per frame (difference against the all-off frame, threshold,
- connected components).
-2. **Decode** IDs per blob track from the on/off sequence; use parity and the
- repeated cycles to reject bad decodes.
-3. **Triangulate** each LED from all views with known poses, robustly (reject
- by reprojection error, median).
-4. **Refine** with bundle adjustment over poses and points, since ARKit poses
- drift.
-5. **Clean up** with priors:
+- Lock exposure if the capture device allows it **(unverified)**; otherwise
+ lower LED brightness.
+- Per frame: timestamp, camera transform, intrinsics, image size, tracking
+ state. Images as frames or a video.
+- A button marks station start and end, so the solver knows when the camera
+ was meant to be still.
+- Stations: cover the tree from many heights and angles, including above and
+ below.
+
+### 3. Solver (laptop, Python)
+
+1. **Detect** blobs per frame: difference against the all-off frame,
+ threshold, connected components.
+2. **Sync**: find the all-on/all-off frames, then slice each station into bit
+ slots.
+3. **Decode** IDs per blob: threshold each LED halfway between its own on and
+ off brightness, read the gray code, check parity, and use repeated cycles to
+ reject bad decodes.
+4. **Triangulate** each LED from all views with known poses, robustly (reject
+ by reprojection error, take the median).
+5. **Refine** with bundle adjustment (see below).
+6. **Clean up** with priors:
- String continuity within strands (~0.10 m).
- Approximate cone fit from LiDAR or the point cloud, with LEDs near its
surface.
- Interpolate LEDs that were never seen along their strand.
-6. **Score** every LED: number of views, reprojection error, prior agreement.
+7. **Score** every LED: number of views, reprojection error, prior agreement.
-Language is undecided. Python (NumPy/OpenCV) is fastest to prototype.
+#### Bundle adjustment
-### 3. Outputs
+ARKit poses drift by millimeters to a centimeter or two over a walk-around, so
+lines of sight from different views don't quite meet, and that error goes into
+the LED positions. Bundle adjustment treats both the camera poses and the LED
+positions as unknowns, and searches for the combination that minimizes
+reprojection error: the pixel distance between where each LED projects into
+each image and where it was actually seen.
+
+- The problem is heavily overdetermined (each LED seen from many stations,
+ each station seeing hundreds of LEDs), so a drifted pose can't hide.
+- It's nonlinear least squares; SciPy's `least_squares` handles this size.
+- It starts from ARKit's poses and the first triangulation.
+- Keep it anchored: hold gravity and metric scale from ARKit so the solution
+ can't slide, rotate, or rescale freely.
+- It's a refinement, not a requirement. Raw ARKit poses are probably good
+ enough for effects like vertical sweeps.
+
+### 4. Outputs
- **Canonical:** `leds.json` or CSV with index, x, y, z (meters, y up),
confidence, and views per LED.
-- **Exporters:** xLights 3D custom model, WLED ledmap (height order as the
- trivial fallback), Pixelblaze map, Blender-friendly CSV.
+- **Exporters:** WLED ledmap (height order as the trivial first version),
+ xLights 3D custom model, Pixelblaze map, Blender-friendly CSV.
-### 4. Viewer
+### 5. Viewer
A 3D plot of the points, colored by confidence, so bad ones are easy to spot.
-### 5. Streamer (later)
+### 6. Streamer (later)
A small service that computes a color per LED from (x, y, z) each frame and
sends DDP frames to WLED. Effects: vertical sweeps, rotating colors, rising
-flames.
+flames. It can share DDP code with the pattern player.
## Capture session layout (sketch)
```
session-YYYYMMDD-HHMM/
- session.json # LED count, code scheme, device model, notes
+ session.json # LED count, code scheme and slot timing, device model, notes
stations/
001/
frames/ # image per frame (or a video)
poses.jsonl # {t, transform[16], fx, fy, cx, cy, w, h, tracking}
- pattern.jsonl # {t, bit_index or sync marker}
depth/ # optional
+ player.jsonl # optional: pattern player's own timeline, debug only
```
+The synthetic generator writes this same format.
+
## Testing
- **Synthetic first.** Generate known LED positions on a cone, render them
- through simulated cameras with realistic noise and occlusion, and check the
- solver recovers them. No tree needed.
+ through simulated cameras with realistic noise, drift, blooming, and
+ occlusion, and check the solver recovers them. No tree needed.
- **Real baseline.** Map the same tree with MariMapper and compare.
## Risks
@@ -99,23 +151,35 @@ session-YYYYMMDD-HHMM/
- ARKit tracking in a dim room (first thing to test).
- Exposure blooming the LEDs.
- LEDs facing away from the camera biasing detections.
-- Pattern/frame sync under Wi-Fi jitter.
- Drift between stations.
+- Rolling shutter splitting a bit transition across one frame (holding each
+ slot for 3+ frames, and discarding transition frames, should cover it).
## Open questions
-- Stations or continuous capture?
-- Solver language (Python vs. something compiled)?
+- Do WLED indices continue across the two 250-pixel outputs? (Answered by the
+ pattern player's debug mode.)
+- Can exposure be locked during an ARKit session?
- Whether LiDAR meaningfully improves the cone prior or visibility checks.
-- Do WLED indices continue across the two 250-pixel outputs?
-
-## Milestones
-
-- [ ] Tracking spike: log `trackingState` waving a phone at the blinking
- string in a dim room.
-- [ ] Capture app: ARKit session, DDP code player, recorder.
-- [ ] Synthetic dataset generator.
-- [ ] Solver: detect, decode, triangulate.
-- [ ] Priors and bundle adjustment.
-- [ ] Viewer and exporters.
-- [ ] Streamer with a first 3D effect.
+- Is there a recorder app good enough to skip writing the Swift app for the
+ spike?
+
+## Plan
+
+In order. Steps 1, 2 and 4 need no phone or tree; 3 and 5 do.
+
+1. **Spec.** Pin down the code scheme, slot timing, and session format. These
+ are the contract between capture, synthetic data, and solver.
+2. **Pattern player.** DDP loop with debug modes; check it on the tree.
+3. **Tracking spike.** Minimal Swift recorder (or an existing app) on the
+ phone, with the pattern player running, in a dim room. Does tracking hold?
+4. **Synthetic generator,** then the solver against it: detect, sync, decode,
+ triangulate.
+5. **Real data.** Record the tree and run the solver.
+6. **Height-ordered WLED ledmap,** the quick win once any positions exist.
+7. Priors and bundle adjustment.
+8. Viewer and exporters.
+9. Streamer with a first 3D effect.
+
+A v1 for this season would stop at step 6, plus a rough 3D map from raw ARKit
+poses.
diff --git a/firmament/README.md b/firmament/README.md
index 07418b3..290bf5d 100644
--- a/firmament/README.md
+++ b/firmament/README.md
@@ -11,13 +11,15 @@ Design only. Nothing is built. See [`DESIGN.md`](DESIGN.md).
## Shape of it
-1. **Capture (iPhone, native Swift).** Plays a gray-code pattern to WLED while
- recording frames, ARKit poses, intrinsics, and depth. A dumb recorder.
-2. **Solver (laptop, offline).** Decodes LED IDs, triangulates, cleans up with
+1. **Pattern player (laptop, Python).** Loops a self-clocking gray-code
+ pattern to WLED over DDP.
+2. **Recorder (iPhone, native Swift).** Records frames, ARKit poses,
+ intrinsics, and depth. A dumb recorder; it doesn't control the LEDs.
+3. **Solver (laptop, Python, offline).** Decodes LED IDs, triangulates, cleans up with
string and tree-shape priors, exports positions.
-3. **Viewer and exporters.** A 3D preview, plus CSV/JSON, xLights model, and
+4. **Viewer and exporters.** A 3D preview, plus CSV/JSON, xLights model, and
WLED ledmap outputs.
-4. **Streamer (later).** Computes 3D effects per LED and sends them to WLED
+5. **Streamer (later).** Computes 3D effects per LED and sends them to WLED
over DDP.
## Context