# Interface spec (v2)

The software uses a configurable placeholder in `config/machine.example.yaml`. A majority of those parameters are currently placeholder. Other teams should fill in and review accordingly before testing

## Hardware

- Gantry: CoreXY
- Extrusion: 3 syringes (current code supports multi color now)
- That makes 5 steppers in total: 2 for XY and 3 for the plungers.
- Controller: UFP for now . One RP2040 stepper board per motor, each on its own USB port, driven from Python with Quentin's ufp library. Boards with MOTOR_ID 1, 2, 3 are flashed, which is enough for single color (2 XY motors + 1 plunger).
- Board units: full steps, 200 steps per revolution. Software never sees them: the firmware wrappers convert (`mm_per_step`). Only the plungers are configured in steps.
- CoreXYZ reference design:  demo moves at 300 mm/s and 1200 mm/s².


## Units and coordinates

- Millimetres and seconds in the config and the events (speeds in mm/s). Only the firmware wrappers convert to motor steps.
- Machine origin is the lower left corner, +X to the right, +Y away from the operator.
- Stage frame (firmware): (0, 0) = both XY motors on their limit switches; machine = stage + `ufp.home_offset`. The usable region is the box `machine.travel_limits` (x / y limits, passed to the wrapper in the stage frame); each motor's range is derived from it (`xy_geometry.motor_ranges`) and may reach past its switch position.
- Each nozzle has an offset = nozzle tip position relative to the gantry reference point.

## Multi color
- Each SVG shape keeps its colour (stroke, else fill) and is printed by the
  nozzle whose configured color is closest ( "redmean" RGB distance).

## Open questions
1. Plunger calibration: which syringe and what is the nozzle fofset between each
2. Gantry travel limits: `machine.travel_limits` and `ufp.home_offset` are placeholders; measure them. The carriages need free travel past their switch position wherever the box extends beyond it (e.g. with the home in a corner, one motor goes below its switch reference for y > x).

## Software <-> firmware contract
- `scripts/motion.py` emits `XYMove` (machine mm, mm/s, mm/s^2), `Prime` / `Extrude` / `Retract` (syringe steps), `Wait`, `Pause`.
- `scripts/ufp_driver.py` maps them on `firmware/xy_stage_wrapper.XYStage.move_to` and `syringe_wrapper.SyringeBank.prime / extrude / retract`. Nothing in `software/` imports `ufp` or touches a board.
- Shared, dependency-free geometry lives in `firmware/xy_geometry.py` (CoreXY transform, x / y box test, per-motor ranges and limits).
- Wrapper additions made for this: `invert` / `invert_a,b`, `expected_id(s)` (raises `WrongBoardError`), `StepperMotor.assume_homed()` for axes without a switch.
