Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
95f652be5This file is pinned to the selected release. Download the original to open it in your design tool.
# Motionlayer Studio · Web
The browser edition of [Motionlayer Studio][studio]: a self-contained,
single-file HTML dashboard that talks to one or more Tinymovr servo drives
over a WebSerial slcan adapter. Hostable on GitHub Pages or any static HTTP
server, ships as one inlined `dashboard.html`.
[studio]: ../Python
> **Browser support.** Web Serial is currently Chrome / Edge / Opera only.
> Firefox and Safari are not supported. For those, install the desktop
> edition of Motionlayer Studio (`pip install tinymovr`).
## Hardware
You need an slcan-compatible USB-CAN adapter, e.g.
- [CANable](https://canable.io/) running slcan firmware
- [candleLight](https://github.com/HubertD/candleLight_fw) in slcan mode
- USB2CAN modules with slcan firmware
Any adapter that speaks the LAWICEL/slcan ASCII protocol over a USB serial
endpoint will work.
## How it works
```
WebSerial port → SlcanDriver → CanRouter → HeartbeatDiscovery + AvlosClient
(T....\r) (filter) (auto-discover, get/set/call)
```
- **SlcanDriver** speaks the slcan ASCII protocol (`S<n>\r`, `O\r`,
`T<id8><len><hex>\r`, etc.).
- **CanRouter** dispatches inbound frames to listeners by predicate.
- **HeartbeatDiscovery** listens for the standard 11-bit heartbeat at
`0x700 + node_id`, decodes the first 4 payload bytes as a little-endian
uint32, and matches the result against the embedded protocol specs.
- **AvlosClient** packs the (`node_id`, `hash_low8`, `ep_id`) tuple into a
29-bit extended ID exactly the way [`studio/Python/tinymovr/channel.py`](../Python/tinymovr/channel.py)
does, then issues RTR (get), data (set), and data+response (call) frames.
The protocol descriptions are baked in from
[`studio/Python/tinymovr/specs/`](../Python/tinymovr/specs/) at build time,
through the same `avlos.deserialize()` pipeline the firmware and Python
client use, so endpoint IDs and hashes are guaranteed to match.
## Source layout
```
studio/Web/
index.html Vite entry: HTML shell + <script type="module" src="/src/main.js">
src/
main.js Entry point (imports CSS + components, calls boot())
styles.css Global styles
specs.generated.json Generated by build_specs.py (gitignored)
components/ Web components: dash-card, dash-stat, dash-sparkline,
dash-gauge, tm-state-buttons, tm-setpoint, tm-health
runtime/ Codec, slcan driver, CAN router, can-id helpers,
AvlosClient, HeartbeatDiscovery, PollScheduler
app/ Page wiring: els (DOM refs), connect/disconnect,
controls, polling, explorer, health channels, boot
build_specs.py Runs avlos.deserialize() over each YAML, writes
src/specs.generated.json. Replaces the previous
template-substitution build.
vite.config.js Vite + vite-plugin-singlefile config (single-file
output, every asset inlined).
package.json Dev dependencies and npm scripts.
dashboard.html Build output. **Commit this** — it is what
GitHub Pages serves. Generated by `npm run build`.
```
## Prerequisites
- **Node.js 18+** (Vite 8 requires it).
- The project's Python virtual environment with `avlos` installed (the
same one used by the desktop Studio). Activate it before running
`npm run build` so `python3` sees `avlos` on `PYTHONPATH`.
## Building
From the repo root:
```bash
source venv/bin/activate # first time only, in this shell
cd studio/Web
npm install # first time only
npm run build # generates dashboard.html
```
`npm run build` does three things in order:
1. **`build_specs.py`** reads every YAML in
[`studio/Python/tinymovr/specs/`](../Python/tinymovr/specs/), runs the
avlos deserializer, and writes
`src/specs.generated.json` (gitignored).
2. **`vite build`** bundles `src/` into a single self-contained
`dist/index.html` (CSS, JS and the spec JSON are all inlined by
`vite-plugin-singlefile`).
3. **`cp dist/index.html dashboard.html`** publishes the artifact.
Re-run `npm run build` whenever a YAML spec or any source file changes.
## Development
`npm run dev` starts a Vite dev server with hot module reload — editing a
component or CSS rule reloads in place without losing the serial-port
connection. The dashboard is served on a local port that Vite prints on
startup. The spec generator runs once at start; re-run `npm run specs`
manually if you change a YAML.
## Hosting on GitHub Pages
Two options, depending on your Pages source:
1. **Pages from a folder.** Move the built file to whatever directory
Pages serves (e.g. `docs/dashboard.html`) and link to it from the
project landing page.
2. **Dedicated `gh-pages` branch.** Copy `studio/Web/dashboard.html` into
the branch root as `index.html`.
In either case the served file has zero runtime dependencies, so HTTPS,
no build step, and no asset pipeline are required at hosting time.
## Using the dashboard
1. Plug in your slcan adapter.
2. Open `dashboard.html` in Chrome / Edge / Opera.
3. Pick the bus bitrate (default 1 Mbps), click **Connect**, and pick the
serial port from the browser dialog.
4. Tinymovrs that are heartbeating on the bus appear in the **Device**
dropdown tagged with the matched protocol version. Pick one to focus.
5. Use the state / mode buttons, the setpoint inputs, and the estimate
cards to drive the device. The bottom **Spec explorer** exposes every
endpoint in the device's spec for advanced use.
The dashboard pauses polling automatically while a destructive action
(calibrate, erase config) is in flight, so the device receive buffer
isn't flooded.
## Config import / export
The **Spec explorer** card carries a small toolbar with **Export JSON**
and **Import JSON** buttons.
- **Export JSON** reads every endpoint tagged `meta: {export: True}`
in the YAML spec on the focused device, dumps them to a nested JSON
document keyed by endpoint path, and downloads it as
`tinymovr-config-node<id>-<spec>-<ts>.json`. A small `_meta` block
(spec version, hash, node id, timestamp) is added at the root for
traceability.
- **Import JSON** picks a file, asks for confirmation, and applies
every leaf whose path matches a settable, export-tagged endpoint on
the device. Each value is **read back immediately after writing**
and compared against the intended value (with float tolerance) so
silent firmware-side clamping or out-of-range rejection surfaces in
the report. The headline number in the status line is the verified
count — settings actually holding their target value on the device,
not frames sent on the wire. Unknown paths, write errors, and
mismatches are counted in the inline status and logged to the
console with full diagnostics.
The wire format is **byte-for-byte compatible with the desktop edition
of Motionlayer Studio (Python)**: a JSON exported in the browser can
be loaded with `tinymovr` GUI (File → Import) or
`tinymovr.config.import_config(...)`, and vice versa. Unit-bearing
attributes round-trip as `"<num> <unit>"` strings; unitless numerics
and enums round-trip as bare JSON numbers.
What is **not** exported (matches the desktop convention):
- Runtime controls — `controller.state`, `controller.mode`.
- Comms identity — `comms.can.id`, `comms.can.rate` (importing a
mismatched bitrate would kill the bus).
- Setpoints and any other endpoint with `meta.jog_step` or without an
`export: True` tag.
Polling is paused for the duration of both export and import so the
adapter receive buffer doesn't get flooded. The import does not
auto-`IDLE` the controller — for live-tuning sessions, switch to IDLE
manually first.
## Out of scope
- DFU / firmware update flow (the DFU specs are still embedded for
completeness but no UI is built around them yet).
- Plotting longer histories than the rolling sparkline buffer.
- Transports other than slcan / WebSerial.