Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Mobile shell: video pinned on top, one status strip, bottom tabs, a snap-point drive sheet - and exactly ONE stop button #82

Parked opened this in answer to
Closed without merging

vesper/arm:vesper/49-mobile-shell-video-pinned-on-top-one-sta → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
11 files changed +570 −1208
Software/README.md +37 −52
@@ -510,67 +510,52 @@ appended to `admin.log.jsonl` next to it, with who did it. `/admin` shows
510510 the latest entries. Changes are accepted only from the owner, and only from
511511 the app's own page.
512512
513 **On a phone.** The page is laid out for one thumb, phone first. The view
514 (camera or 3D) sits on top at full width. Under it a status strip shows who
515 drives, your place in the line, the time left, the turn's one button, and
516 the red **Stop**. Stop is there whenever you drive, and for the owner. Below
517 that is a sheet with tabs at the bottom edge: **Chat**, **Queue**,
518 **Controls** (only on your turn, and it opens by itself when your turn
519 starts) and **Admin** (the owner: the room, the safe zone, the trims,
520 metrics and 3D calibration).
513 **On a phone.** The page is laid out for one thumb, phone first, and the
514 camera and the 3D model are on screen together. The camera sits on top at
515 full width, 16:9, with its room kept before the first frame. Under it a
516 status strip shows who drives, your place in the line, the time left, the
517 arm's link (live, reconnecting, simulated), the turn's one button, a
518 **notes** pill and the one red **Stop**. The 3D model fills the space below,
519 down to the tray of the open tab and the tabs at the bottom edge: **Drive**
520 (only on your turn, and it opens by itself when your turn starts),
521 **Queue**, **Chat**, **Admin** (the owner) and **Machine**. Tap the open tab
522 again to fold its tray away and give the model the room.
521523
522 - Controls, phone upright: a row of chips (J1 base, J2 shoulder, J3 elbow,
523 J4 wrist, J5 roll, Grip) picks one joint. One tall lever drives it: push
524 up or down, and the further you push the faster it goes. Let go and it
525 stops. ▲/▼ beside the lever nudge one step per tap and jog while held.
526 Under them come the poses, Hold, Record and the rest. This layout is for
527 screens up to 640 px wide. A tablet held upright gets the joystick and
528 sliders of the wider screens. From a keyboard, arrows on the chips pick
529 the joint and ↑/↓ on the lever step it.
530 - Controls, phone on its side: the sheet tucks away when your turn starts,
531 and two thumb sticks sit over the picture. The left stick moves J1
532 sideways and J2 up/down. The right stick moves J4 sideways and J3 up/down,
533 and **Wrist** swaps it to J5 roll and the gripper. **Open** and **Close**
534 between the sticks are press-and-hold. **Show** brings the sheet back.
535 The sticks and the grip buttons take touch and a mouse only. With a
536 keyboard or a screen reader, **Show** brings back the sheet, and its joint
537 sliders and ±-buttons drive every joint, the gripper included.
538 - How touch driving works (`src/ui/drive.js`): a finger's deflection is a
539 speed, with a dead band in the middle, never a position. Each finger is
540 tracked by its own pointer, so two thumbs drive two sets of joints
541 independently. The instant a finger lifts, its joints' targets are sent
542 as they stand, without waiting for the next frame (`src/ui/frames.js`
543 sends whatever is still pending with it). The arm's governor
544 settles on them. The same happens on pointercancel, on a lost capture,
545 when the window loses focus, when the page is hidden, and when driving
546 stops being allowed: your turn ends, the arm is stopped, or it is
547 reconnecting (`canDrive` in `src/ui/drive.js`). Frames go out
548 at 25 Hz. A target never runs more than 0.6 s ahead of where the arm
549 last said it was, so a slow link or a speed cap never queues up motion.
550 The server's limits clamp every frame as before. Android buzzes on a
551 press and at the end of a joint's range. Every press also shows on
552 screen. The screen stays awake during your turn (Screen Wake Lock), and
553 the status line shows the round trip to the arm once it passes 250 ms.
554 On a phone the strip carries one stop button, the E-stop.
555 - Controls, wider screens: a joystick moves the gripper. Up reaches out,
556 sideways swings around the base, and ▲/▼ raise and lower it. The page
557 solves that onto pan, lift and elbow against the URDF
558 (`src/ui/reach.js`), and the server checks every frame against the zone
559 as usual. Below the joystick come the joint sliders with hold-to-jog −/+,
560 the poses, and the rest.
524 - Drive with the model: touch a part of the arm and drag to turn its joint.
525 The target streams live, at most every 33 ms, latest wins
526 (`src/ui/frames.js`). One finger on empty space does nothing. Two fingers
527 turn the view and pinching zooms, and neither sends anything to the arm.
528 The model shows where you asked the arm to be. A faint blue ghost shows
529 where the arm really is, so you can see the lag while you drag.
530 - Drive with the sliders: the Drive tray lists every joint at once, one
531 compact row each (name, slider, value). Each row has a mark for your
532 target and one for where the arm is. A vertical swipe on a row scrolls the
533 tray. Below the rows come the poses, Hold, Record and the rest. Wider
534 screens add hold-to-jog −/+ to each row.
535 - Notes never cover the camera or the model. Zone warnings, a jam,
536 reconnecting, the speed cap, the owner's announcement and the page's own
537 messages are all counted in the pill ("2 notes"). It turns red when one is
538 serious, and a tap opens them all in a sheet (`src/ui/notes.js`). A stop
539 is a full-width row under the strip, with the two-tap **Resume driving**.
540 - STOP: one button in every layout, red, at least 56 px tall. It fires on
541 the press, not the release, and is always in the strip. The screen stays
542 awake during your turn (Screen Wake Lock), and the strip shows the round
543 trip to the arm once it passes 250 ms.
561544 - Chat: the page follows the visual viewport. The keyboard shrinks the
562545 sheet and the view, and never covers the box or the last message.
563546 Long-press a message (or right-click it) to delete it, or mute or ban its
564547 author.
565 - Phone on its side: the view fills the screen, the strip and the sheet
566 float over it, and **Hide** clears them away. A wide screen puts the
567 sheet in a column beside the view.
548 - Phone on its side: the strip with STOP runs across the top, and the camera
549 and the model sit side by side under it. The sheet is a third column while
550 it is shown. It is put away when your turn starts, and **Show** brings it
551 back. A wide screen puts the camera, the model and the sheet in three
552 columns, and there the **3D** button can put the model away.
568553 - Every tap target is at least 44 px. The safe-area insets are respected,
569554 the page follows the system's light or dark mode, and nothing moves for
570555 people who ask for reduced motion. The bottom-right corner belongs to the
571556 forge pill, so no control sits under it.
572 - Mobile data: the first view needs no three.js. The model and the
573 joystick arrive after it. The relay gzips the page, three.js, the URDF
557 - Mobile data: the first view needs no three.js. The model arrives
558 after it. The relay gzips the page, three.js, the URDF
574559 and the meshes (`src/compress.ts`). The page's modules are cached for
575560 good under a name that changes with their content. On a slow link, a
576561 slow `/status` round trip or the browser's Save-Data, the camera drops
Software/so101/src/phone-layout.test.ts added +192
@@ -0,0 +1,192 @@
1 /**
2 * The phone layouts, measured in a real browser: the page from bench/fake-serve.ts with one camera listed, opened in
3 * headless Chrome over the DevTools protocol (no driver library) at 390x844 and 412x915, upright and on their sides.
4 * Where no Chrome starts (no binary, or a sandbox without sockets) the suite is skipped and says why.
5 * With PHONE_SHOTS=<dir>, a screenshot of every state goes there, light and dark.
6 */
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11
12 type Rect = { x: number; y: number; w: number; h: number };
13 type Seen = { stops: Rect[]; camera: Rect | null; model: Rect | null; notices: Rect[]; buttons: Rect[]; banner: Rect | null; joysticks: number; tray: number; shut: boolean; w: number; h: number; tabs: string[] };
14
15 const CHROMES = [process.env.CHROME, "/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome", "/usr/bin/google-chrome-stable"].filter((p): p is string => Boolean(p));
16 const dir = mkdtempSync(join(tmpdir(), "so101-phone-"));
17 const shots = process.env.PHONE_SHOTS;
18
19 /** Chrome, headless, its DevTools socket and one page attached. */
20 async function launch(): Promise<{ proc: ReturnType<typeof Bun.spawn>; ws: WebSocket } | string> {
21 const bin = CHROMES.find((p) => existsSync(p));
22 if (!bin) return "no Chrome or Chromium on this machine";
23 const proc = Bun.spawn([bin, "--headless=new", "--no-sandbox", "--no-first-run", "--hide-scrollbars", "--mute-audio", "--use-angle=swiftshader", "--enable-unsafe-swiftshader",
24 `--user-data-dir=${join(dir, "chrome")}`, "--remote-debugging-port=0", "about:blank"], { stdout: "ignore", stderr: "pipe", env: { ...process.env, HOME: dir } });
25 const reader = proc.stderr.getReader();
26 let text = "";
27 const deadline = Date.now() + 15000;
28 while (Date.now() < deadline) {
29 const chunk = await Promise.race([reader.read(), Bun.sleep(500).then(() => null)]);
30 if (chunk?.done) break;
31 if (chunk?.value) text += new TextDecoder().decode(chunk.value);
32 const url = /DevTools listening on (ws:\/\/\S+)/.exec(text)?.[1];
33 if (url) {
34 reader.releaseLock();
35 const ws = new WebSocket(url);
36 await new Promise((resolve, reject) => { ws.onopen = resolve; ws.onerror = reject; });
37 return { proc, ws };
38 }
39 }
40 proc.kill();
41 return `Chrome did not start: ${text.split("\n").find((l) => /FATAL|ERROR/.test(l))?.slice(0, 160) ?? "no DevTools socket"}`;
42 }
43
44 /** The page under test: the simulated arm behind the relay, one camera listed so the camera's box is shown. */
45 async function serve(): Promise<{ proc: ReturnType<typeof Bun.spawn>; base: string }> {
46 const data = join(dir, "data");
47 mkdirSync(join(data, "so101"), { recursive: true });
48 writeFileSync(join(data, "so101", "cameras.json"), JSON.stringify({ next: 2, cameras: [{ id: 1, name: "Overhead", source: "http://127.0.0.1:9/stream" }] }));
49 const env: Record<string, string> = { ...process.env, PORT: "0", FORGE_APP_DATA: data } as Record<string, string>;
50 delete env.FORGE_APP_ENV; delete env.FORGE_APP_IDENTITY_KEY; delete env.ARM_SERVER; // local: every visitor drives
51 const proc = Bun.spawn(["bun", "run", join(import.meta.dir, "..", "bench", "fake-serve.ts")], { stdout: "pipe", stderr: "inherit", env });
52 const reader = proc.stdout.getReader();
53 let text = "";
54 while (!/arm on (http:\/\/\S+)/.test(text)) {
55 const { value, done } = await reader.read();
56 if (done) throw new Error(`fake-serve exited: ${text}`);
57 text += new TextDecoder().decode(value);
58 }
59 reader.releaseLock();
60 return { proc, base: /arm on (http:\/\/\S+)/.exec(text)![1]! };
61 }
62
63 let chrome: Awaited<ReturnType<typeof launch>> | null = null;
64 let server: Awaited<ReturnType<typeof serve>> | null = null;
65 let id = 0;
66 let session = "";
67 const waiting = new Map<number, (m: { result?: any; error?: { message: string } }) => void>();
68 function cdp(method: string, params: object = {}, sessionId: string | undefined = session || undefined): Promise<any> {
69 const ws = (chrome as { ws: WebSocket }).ws;
70 const n = ++id;
71 ws.send(JSON.stringify({ id: n, method, params, ...(sessionId ? { sessionId } : {}) }));
72 return new Promise((resolve, reject) => waiting.set(n, (m) => (m.error ? reject(new Error(`${method}: ${m.error.message}`)) : resolve(m.result))));
73 }
74 const evaluate = async (expression: string) => (await cdp("Runtime.evaluate", { expression, awaitPromise: true, returnByValue: true })).result.value;
75
76 const started = await launch();
77 const why = typeof started === "string" ? started : null;
78 if (why) console.log(`phone-layout: skipped, ${why}`);
79 else chrome = started;
80
81 /** What a phone sees: every visible STOP, the camera's and the model's boxes, the notices, the buttons, the tray. */
82 const MEASURE = `(() => {
83 const box = (e) => { const b = e.getBoundingClientRect(); return { x: b.x, y: b.y, w: b.width, h: b.height }; };
84 const shown = (e) => { if (!e) return false; const s = getComputedStyle(e), b = e.getBoundingClientRect(); return s.display !== "none" && s.visibility !== "hidden" && b.width > 0 && b.height > 0 && b.bottom > 0 && b.right > 0 && b.top < innerHeight && b.left < innerWidth && e.closest("[hidden]") === null; };
85 const all = (sel) => [...document.querySelectorAll(sel)].filter(shown).map(box);
86 const one = (sel) => { const e = document.querySelector(sel); return shown(e) ? box(e) : null; };
87 const tray = [...document.querySelectorAll("#sheet .tab")].find(shown);
88 return { stops: all("[data-stop]"), camera: one("#app"), model: one("#modelBox"), notices: all("#banner, #notes, #notesDlg, #msg:not(.sr), [role=alert]:not(:empty), #why:not(:empty)"),
89 buttons: all("button, a[href], input, select"), banner: one("#banner"), joysticks: document.querySelectorAll("#sticks, .stick, #pad, #lever, #chips").length,
90 tray: tray ? tray.getBoundingClientRect().height : 0, shut: document.getElementById("shell").classList.contains("shut"), w: innerWidth, h: innerHeight,
91 tabs: [...document.querySelectorAll("#tabs [role=tab]")].filter(shown).map((b) => b.textContent.trim()) };
92 })()`;
93 const overlap = (a: Rect, b: Rect) => a.x < b.x + b.w - 0.5 && b.x < a.x + a.w - 0.5 && a.y < b.y + b.h - 0.5 && b.y < a.y + a.h - 0.5;
94
95 async function open(width: number, height: number, scheme: "light" | "dark") {
96 await cdp("Emulation.setDeviceMetricsOverride", { width, height, deviceScaleFactor: 2, mobile: true, screenOrientation: width > height ? { type: "landscapePrimary", angle: 90 } : { type: "portraitPrimary", angle: 0 } });
97 await cdp("Emulation.setTouchEmulationEnabled", { enabled: true, maxTouchPoints: 5 });
98 await cdp("Emulation.setEmulatedMedia", { features: [{ name: "prefers-color-scheme", value: scheme }] });
99 await cdp("Page.navigate", { url: `${server!.base}/` });
100 // Ready: the Drive tab is up (local: everyone drives) and the views are placed.
101 await evaluate(`new Promise((done) => { const t = Date.now(); const look = () => (document.getElementById("t-controls") && !document.getElementById("t-controls").hidden && document.querySelector("#stage .pane.on")) || Date.now() - t > 8000 ? setTimeout(done, 600) : setTimeout(look, 100); look(); })`);
102 return (await evaluate(MEASURE)) as Seen;
103 }
104 async function shot(name: string) {
105 if (!shots) return;
106 mkdirSync(shots, { recursive: true });
107 const { data } = await cdp("Page.captureScreenshot", { format: "png" });
108 writeFileSync(join(shots, `${name}.png`), Buffer.from(data, "base64"));
109 }
110
111 describe.skipIf(why !== null)("the phone layouts in a browser", () => {
112 beforeAll(async () => {
113 const ws = (chrome as { ws: WebSocket }).ws;
114 ws.onmessage = (e) => { const m = JSON.parse(String(e.data)); if (m.id && waiting.has(m.id)) { waiting.get(m.id)!(m); waiting.delete(m.id); } };
115 server = await serve();
116 const { targetId } = await cdp("Target.createTarget", { url: "about:blank" }, undefined);
117 session = (await cdp("Target.attachToTarget", { targetId, flatten: true }, undefined)).sessionId;
118 await cdp("Page.enable");
119 }, 30000);
120 afterAll(async () => {
121 if (server) { await fetch(`${server.base}/resume`, { method: "POST", body: "{}" }).catch(() => {}); server.proc.kill(); }
122 if (chrome && typeof chrome !== "string") { chrome.ws.close(); chrome.proc.kill(); }
123 rmSync(dir, { recursive: true, force: true });
124 });
125
126 for (const [width, height, name] of [[390, 844, "iphone"], [412, 915, "android"], [844, 390, "iphone-side"], [915, 412, "android-side"]] as const) {
127 test(`${name} ${width}x${height}: one STOP in reach, camera and model both on screen, nothing over them, nothing under the forge pill`, async () => {
128 for (const scheme of ["dark", "light"] as const) {
129 const seen = await open(width, height, scheme);
130 await shot(`${name}-${scheme}`);
131 expect(seen.joysticks).toBe(0);
132 expect(seen.stops.length).toBe(1);
133 const stop = seen.stops[0]!;
134 expect(stop.h).toBeGreaterThanOrEqual(56);
135 expect(stop.x >= 0 && stop.y >= 0 && stop.x + stop.w <= seen.w && stop.y + stop.h <= seen.h).toBe(true);
136 expect(seen.camera).not.toBeNull();
137 expect(seen.model).not.toBeNull();
138 expect(overlap(seen.camera!, seen.model!)).toBe(false);
139 expect(seen.model!.h).toBeGreaterThanOrEqual(width > height ? 200 : 100);
140 if (width < height) {
141 expect(seen.camera!.w).toBe(width); // full width, 16:9
142 expect(Math.abs(seen.camera!.h - (width * 9) / 16)).toBeLessThan(1.5);
143 expect(seen.model!.y).toBeGreaterThan(seen.camera!.y + seen.camera!.h); // the model below the camera
144 expect(seen.tabs[0]).toBe("Drive");
145 } else expect(Math.abs(seen.camera!.y - seen.model!.y)).toBeLessThan(1); // side by side
146 for (const n of seen.notices) for (const view of [seen.camera!, seen.model!]) expect(overlap(n, view)).toBe(false);
147 const pill = { x: seen.w - 68, y: seen.h - 56, w: 68, h: 56 };
148 for (const b of seen.buttons) expect(overlap(b, pill)).toBe(false);
149 if (width > height) {
150 // On its side the turn starts with the sheet away; Show makes it a third column, still clear of both views and the pill.
151 await evaluate(`document.getElementById("sheetToggle").click()`);
152 const sheet = (await evaluate(MEASURE)) as Seen;
153 await shot(`${name}-${scheme}-sheet`);
154 expect(sheet.stops.length).toBe(1);
155 expect(sheet.tabs.length).toBeGreaterThan(0);
156 for (const b of sheet.buttons) expect(overlap(b, pill)).toBe(false);
157 for (const b of sheet.buttons.filter((r) => r.x >= sheet.camera!.x + sheet.camera!.w + sheet.model!.w)) for (const view of [sheet.camera!, sheet.model!]) expect(overlap(b, view)).toBe(false);
158 }
159 }
160 }, 60000);
161 }
162
163 test("upright, the open tab folds its tray away and the model takes the room; a second tap brings it back", async () => {
164 const before = await open(390, 844, "dark");
165 expect(before.tray).toBeGreaterThan(100);
166 await evaluate(`document.getElementById("t-controls").click()`);
167 const folded = (await evaluate(MEASURE)) as Seen;
168 await shot("iphone-folded");
169 expect(folded.shut).toBe(true);
170 expect(folded.tray).toBe(0);
171 expect(folded.model!.h).toBeGreaterThan(before.model!.h + 100);
172 await evaluate(`document.getElementById("t-controls").click()`);
173 const again = (await evaluate(MEASURE)) as Seen;
174 expect(again.shut).toBe(false);
175 expect(Math.abs(again.tray - before.tray)).toBeLessThan(1);
176 }, 30000);
177
178 test("stopped: a full-width row under the strip, never over the camera or the model, and still exactly one STOP", async () => {
179 for (const [width, height, name] of [[390, 844, "iphone"], [844, 390, "iphone-side"]] as const) {
180 await open(width, height, "dark");
181 await evaluate(`fetch("/stop", { method: "POST", body: "{}" }).then(() => new Promise((r) => setTimeout(r, 1200)))`);
182 const seen = (await evaluate(MEASURE)) as Seen;
183 await shot(`${name}-stopped`);
184 expect(seen.banner).not.toBeNull();
185 expect(seen.banner!.w).toBe(width);
186 expect(seen.stops.length).toBe(1);
187 for (const view of [seen.camera!, seen.model!]) expect(overlap(seen.banner!, view)).toBe(false);
188 expect(await evaluate(`Boolean(document.querySelector("#banner #resume"))`)).toBe(true);
189 await evaluate(`fetch("/resume", { method: "POST", body: "{}" })`);
190 }
191 }, 60000);
192 });
Software/so101/src/relay.test.ts +3 −3
@@ -161,17 +161,17 @@ describe("relay", () => {
161161 expect(page.headers.get("content-encoding")).toBe("gzip");
162162 expect(page.headers.get("x-content-type-options")).toBe("nosniff");
163163 const html = gunzipSync(Buffer.from(await page.arrayBuffer())).toString();
164 const module = /\/ui\/[0-9a-f]{12}\/reach\.js/.exec(html)?.[0];
164 const module = /\/ui\/[0-9a-f]{12}\/intent\.js/.exec(html)?.[0];
165165 expect(module).toBeDefined();
166166 const js = await raw(module!);
167167 expect(js.status).toBe(200);
168168 expect(js.headers.get("cache-control")).toContain("immutable");
169169 expect(js.headers.get("content-encoding")).toBe("gzip");
170 expect(gunzipSync(Buffer.from(await js.arrayBuffer())).toString()).toContain("export function reachStep");
170 expect(gunzipSync(Buffer.from(await js.arrayBuffer())).toString()).toContain("export class Intent");
171171 // A client that asks for nothing compressed gets the plain bytes.
172172 const plain = await fetch(`${base}${module}`, { headers: { "accept-encoding": "identity" }, decompress: false } as RequestInit);
173173 expect(plain.headers.get("content-encoding")).toBeNull();
174 expect(await plain.text()).toContain("export function reachStep");
174 expect(await plain.text()).toContain("export class Intent");
175175 });
176176
177177 test("set: status, poses and /follow go to the arm server; the camera's bytes come through", async () => {
Software/so101/src/server.test.ts +47 −8
@@ -160,7 +160,7 @@ describe("viewer page", () => {
160160 }
161161 expect(bytes).toBeLessThan(50_000);
162162 // three.js, the leader's mapping, the calibration panel and the Machine panel are imported where they are used, not up front.
163 for (const lazy of ["three", "/leader-map.js", "calibration.js", "reach.js", "machine-panel.js", "machine.js"]) expect([...upfront].some((p) => p === lazy || p.endsWith(`/${lazy}`))).toBe(false);
163 for (const lazy of ["three", "/leader-map.js", "calibration.js", "intent.js", "machine-panel.js", "machine.js"]) expect([...upfront].some((p) => p === lazy || p.endsWith(`/${lazy}`))).toBe(false);
164164 expect(script).toContain('import("/leader-map.js")');
165165 expect(script).toMatch(/import\("\/ui\/[0-9a-f]{12}\/calibration\.js"\)/);
166166 expect(script).toMatch(/import\("\/ui\/[0-9a-f]{12}\/machine-panel\.js"\)/);
@@ -176,13 +176,16 @@ describe("viewer page", () => {
176176 expect(r.headers.get("content-type")).toBe("text/javascript");
177177 expect(r.headers.get("cache-control")).toContain("immutable");
178178 const version = path!.split("/")[2];
179 expect((await fetch(`${base}/ui/${version}/reach.test.ts`)).status).toBe(404);
179 expect((await fetch(`${base}/ui/${version}/intent.test.ts`)).status).toBe(404);
180180 expect((await fetch(`${base}/ui/${version}/nothing.js`)).status).toBe(404);
181181 expect((await fetch(`${base}/ui/${version}/..%2Fserver.ts`)).status).toBe(404);
182182 });
183183
184184 test("is laid out for a phone: tabs under the thumb, an E-stop beside the status, room for the forge pill", async () => {
185185 const page = await (await fetch(`${base}/`)).text();
186 expect(page.indexOf('data-tab="controls"')).toBeLessThan(page.indexOf('data-tab="queue"')); // Drive · Queue · Chat
187 expect(page.indexOf('data-tab="queue"')).toBeLessThan(page.indexOf('data-tab="chat"'));
188 expect(page).toContain("viewport-fit=cover");
186189 for (const tab of ["chat", "queue", "controls", "admin"]) expect(page).toContain(`data-tab="${tab}"`);
187190 expect(page).toContain('class="estop"');
188191 expect(page).toContain("interactive-widget=resizes-content");
@@ -191,19 +194,53 @@ describe("viewer page", () => {
191194 expect(page).toMatch(/#tabs \{[^}]*var\(--pill\)/);
192195 });
193196
194 test("serves the touch-driving modules, and the phone layout keeps the browser's gestures off the controls", async () => {
197 test("drives by the 3D model and every joint's slider: no joysticks, no one-joint lever, the real arm as a ghost", async () => {
195198 const page = await (await fetch(`${base}/`)).text();
196 for (const name of ["drive", "frames"]) {
199 for (const name of ["frames", "notes"]) {
197200 const path = new RegExp(`/ui/[0-9a-f]{12}/${name}\\.js`).exec(page)?.[0];
198201 expect(path).toBeDefined();
199202 const r = await fetch(`${base}${path}`);
200203 expect(r.status).toBe(200);
201204 expect(r.headers.get("cache-control")).toContain("immutable");
202205 }
203 expect(page).toMatch(/#lever \{[^}]*touch-action: none/);
204 expect(page).toMatch(/\.stick \{[^}]*touch-action: none/);
205 expect(page).toMatch(/#grips button \{[^}]*min-height: (7[2-9]|[89]\d)px/);
206 expect(page).toMatch(/#chips button small \{[^}]*white-space: nowrap/); // a long label never wraps and shifts the row
206 for (const gone of ['id="sticks"', 'id="stickL"', 'id="pad"', 'id="lever"', 'id="chips"', "reach.js", "drive.js", "bindSurface", "reachBegin"]) expect(page).not.toContain(gone);
207 expect((await fetch(`${base}${/\/ui\/[0-9a-f]{12}\//.exec(page)![0]}drive.js`)).status).toBe(404);
208 // One finger on a part turns its joint; two fingers turn the view and pinch zooms, and those never stream.
209 expect(page).toContain("viewer.controls.touches = { ONE: -1, TWO: THREE.TOUCH.DOLLY_ROTATE }");
210 expect(page).toMatch(/#modelBox \{[^}]*touch-action: none/);
211 // The ghost is the arm as it reports itself, never pickable, so a drag always takes the solid target.
212 expect(page).toContain("ghost = robot.clone()");
213 expect(page).toContain("o.raycast = () => {}");
214 expect(page).toContain("ghost?.setJointValue(name, toRad(j.id, j.position))");
215 // All joints at once, one row each on a phone; a vertical swipe on a slider scrolls the tray.
216 expect(page).toMatch(/\.j input\[type=range\] \{[^}]*touch-action: pan-y/);
217 expect(page).toMatch(/\.j \{ grid-template-columns: 58px minmax\(0, 1fr\) 46px; grid-template-areas: "name slide val"/);
218 });
219
220 test("on a phone the camera sits on top and the model fills the room below it, and no notice is drawn over either", async () => {
221 const page = await (await fetch(`${base}/`)).text();
222 expect(page).toContain('grid-template-areas: "view" "strip" "banner" "model" "sheet"');
223 expect(page).toMatch(/#app \{[^}]*aspect-ratio: 16 \/ 9/);
224 expect(page).toMatch(/max-height: 500px\) \{\n #shell, #shell.typing \{[^}]*"view model sheet"/); // on its side: side by side
225 expect(page).toContain('#shell.bare { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "strip strip" "banner banner" "view model"; }');
226 const between = (from: string, to: string) => page.slice(page.indexOf(from), page.indexOf(to, page.indexOf(from)));
227 const camera = between('<div id="app">', '<section id="strip"'), model = between('<div id="modelBox">', '<section id="sheet"');
228 expect(camera.length).toBeGreaterThan(0);
229 expect(model).toContain("<urdf-viewer");
230 for (const box of [camera, model]) for (const notice of ['role="alert"', 'role="status"', 'id="banner"', 'id="msg"', 'id="notes"', 'id="notice"', 'id="why"']) expect(box).not.toContain(notice);
231 expect(page).not.toMatch(/#banner \{[^}]*position: absolute/);
232 expect(between('<section id="strip"', "</section>")).toContain('<button id="notes"');
233 expect(page).toContain('note("arm", `Reconnecting to the arm');
234 // The tray under the model has one height whatever is in it, and the open tab folds it away.
235 expect(page).toMatch(/\.tab \{ flex: none; height: var\(--tray\)/);
236 expect(page).toContain('shell.classList.add("shut")');
237 // Below a wide screen the last camera stays: its own button sits on it, and nothing else would bring it back.
238 expect(page).toContain('if (key !== "pane3" && !on && !wide.matches && cams.filter(paneOn).length === 1) return;');
239 expect(page).not.toMatch(/max-height: 500px\) \{[^@]*#tabs \{ padding-right: var\(--safe-r\)/); // the pill keeps its corner on its side too
240 });
241
242 test("one STOP in every layout: red, at least 56 px, on the press; resume takes its own second tap", async () => {
243 const page = await (await fetch(`${base}/`)).text();
207244 // One STOP in every layout: one stop control in the markup, and no layout hides it. Resume is its own control.
208245 expect(page.match(/<button[^>]*data-stop/g)?.length).toBe(1);
209246 expect(page).not.toMatch(/#stop \{[^}]*display: none/);
@@ -212,6 +249,8 @@ describe("viewer page", () => {
212249 expect(page).toContain('api("/resume", {})');
213250 expect(page).toContain("Resume driving");
214251 expect(page.match(/>Stop</g)?.length).toBe(1);
252 expect(page).toMatch(/\.estop \{[^}]*min-height: (5[6-9]|[6-9]\d)px/);
253 expect(page).toContain('$("stop").addEventListener("pointerdown"');
215254 });
216255 });
217256
Software/so101/src/ui/drive.js deleted −356
@@ -1,356 +0,0 @@
1 /**
2 * Touch driving: a finger's deflection is a joint's velocity, never its position. Plain ESM, served to the page at
3 * /ui/ and imported by the tests. The wire stays what /follow always took, a target in ticks per joint: each held
4 * joint's target runs ahead at the deflection's share of the jog speed, and the moment the last finger on it lifts
5 * the target stops where it is and goes out at once. That frame is the zero: the arm's governor settles on it.
6 * The server's limits still clamp every frame; this only keeps the page from asking for more.
7 */
8
9 /** The tick direction that raises the gripper, swings the base right, rolls the wrist or opens the jaw (from the URDF). */
10 export const UP = /** @type {Record<number, number>} */ ({ 1: 1, 2: -1, 3: -1, 4: -1, 5: 1, 6: 1 });
11
12 /**
13 * A raw deflection (-1..1) through a dead band and a gentle curve: nothing near the middle, fine control
14 * a little way out, full speed at the edge.
15 * @param {number} v
16 * @param {number} [dead]
17 */
18 export function shape(v, dead = 0.12) {
19 if (!Number.isFinite(v)) return 0;
20 const a = Math.min(1, Math.abs(v));
21 if (a <= dead) return 0;
22 return Math.sign(v) * ((a - dead) / (1 - dead)) ** 1.5;
23 }
24
25 /** @typedef {Record<number, { min: number, max: number }>} Limits */
26 /** @typedef {Record<number, number>} Frame */
27
28 /**
29 * Whether a finger may drive now: it is this person's turn, the arm is not stopped and not reconnecting, and its
30 * limits are known. The page asks before a press starts and on every status poll, letting go of whatever is held
31 * the moment the answer turns false.
32 * @param {{ mayDrive: boolean, estop?: unknown, held?: unknown, reconnecting?: unknown, limits?: Limits | null }} state
33 */
34 export function canDrive({ mayDrive, estop, held, reconnecting, limits }) {
35 return Boolean(mayDrive) && !estop && !held && !reconnecting && Object.keys(limits ?? {}).length > 0;
36 }
37
38 /**
39 * The velocity integrator. Each holder (a pointer, a key) holds some joints at some deflections; a joint's velocity is
40 * the sum of its holders', capped at 1. `step` advances the held joints and returns their targets; `release` drops a
41 * holder and returns the targets of the joints it was moving, which is what stops them.
42 */
43 export class Drive {
44 /** @param {{ margin?: number, lead?: number }} [options] */
45 constructor(options = {}) {
46 /** Ticks kept clear of each end of a joint's range, as the page's sliders always did. */
47 this.margin = options.margin ?? 30;
48 /** How far a target may run ahead of where the arm last said it was: a slow arm (a speed cap) never builds up a backlog. */
49 this.lead = options.lead ?? 0.6;
50 /** @type {Map<string, Map<number, number>>} holder → joint → deflection */
51 this.holders = new Map();
52 /** @type {Map<number, number>} the targets of joints being driven, in fractional ticks */
53 this.targets = new Map();
54 /** @type {Map<number, number>} where the arm last said each joint was */
55 this.present = new Map();
56 }
57
58 /** Where the arm is. A joint nobody holds starts from here when it is next held. @param {Iterable<readonly [number, number]>} positions */
59 seed(positions) {
60 for (const [id, p] of positions) if (Number.isFinite(p)) this.present.set(id, p);
61 }
62
63 /** Whether any joint is held off the middle. */
64 get moving() {
65 for (const axes of this.holders.values()) for (const v of axes.values()) if (v !== 0) return true;
66 return false;
67 }
68
69 /** The joints held, by anyone. */
70 held() {
71 const out = new Set();
72 for (const axes of this.holders.values()) for (const id of axes.keys()) out.add(id);
73 return out;
74 }
75
76 /**
77 * A holder's joints and deflections, replacing what it held before; a joint it lets go of this way stops like a release.
78 * @param {string} holder
79 * @param {Record<number, number>} axes joint id → deflection, -1..1, already shaped
80 * @returns {Frame | null} targets for joints that stopped, to send at once
81 */
82 hold(holder, axes) {
83 const before = this.holders.get(holder);
84 const next = new Map();
85 for (const [k, v] of Object.entries(axes)) {
86 const id = Number(k);
87 if (!Number.isInteger(id) || !Number.isFinite(v)) continue;
88 if (!this.targets.has(id)) {
89 const p = this.present.get(id);
90 if (p === undefined) continue; // no position yet: nothing to run ahead of
91 this.targets.set(id, p);
92 }
93 next.set(id, Math.max(-1, Math.min(1, v)));
94 }
95 this.holders.set(holder, next);
96 const dropped = before ? [...before.keys()].filter((id) => !next.has(id)) : [];
97 return this.#stop(dropped);
98 }
99
100 /** @param {string} holder @returns {Frame | null} the zero: the targets of the joints this holder moved, now still */
101 release(holder) {
102 const axes = this.holders.get(holder);
103 if (!axes) return null;
104 this.holders.delete(holder);
105 return this.#stop([...axes.keys()]);
106 }
107
108 /** Every holder at once: the window lost focus, the page was hidden. @returns {Frame | null} */
109 releaseAll() {
110 const ids = [...this.held()];
111 this.holders.clear();
112 return this.#stop(ids);
113 }
114
115 /**
116 * One small step of one joint, for a tap on − or +.
117 * @param {number} id @param {number} ticks @param {Limits} limits
118 * @returns {Frame | null}
119 */
120 nudge(id, ticks, limits) {
121 const from = this.targets.get(id) ?? this.present.get(id);
122 if (from === undefined || !limits[id]) return null;
123 const t = this.#clamp(id, from + ticks, limits);
124 if (!this.held().has(id)) this.targets.delete(id); else this.targets.set(id, t);
125 this.present.set(id, t); // the next nudge goes on from here, not from a stale reading
126 return { [id]: Math.round(t) };
127 }
128
129 /**
130 * Advance every held joint by `dt` seconds at up to `speed` ticks/s.
131 * @param {number} dt @param {number} speed @param {Limits} limits
132 * @returns {{ frame: Frame | null, stops: number[] }} the targets to send, and joints that just met an end of their range
133 */
134 step(dt, speed, limits) {
135 /** @type {Map<number, number>} */
136 const v = new Map();
137 for (const axes of this.holders.values()) for (const [id, d] of axes) v.set(id, (v.get(id) ?? 0) + d);
138 /** @type {Frame} */
139 const frame = {};
140 const stops = [];
141 let any = false;
142 for (const [id, sum] of v) {
143 const t0 = this.targets.get(id);
144 if (t0 === undefined || !limits[id]) continue;
145 const vel = Math.max(-1, Math.min(1, sum));
146 if (vel === 0) continue;
147 const want = t0 + vel * speed * dt;
148 let t = this.#clamp(id, want, limits);
149 const ended = t !== want;
150 // Never more than `lead` seconds of travel ahead of the arm: a slow arm (a speed cap) is waited for, not queued
151 // up behind. Only further travel is held back; a target never steps back toward a stale reading.
152 const p = this.present.get(id);
153 if (p !== undefined) {
154 const room = Math.max(speed * this.lead, 20);
155 t = vel > 0 ? Math.min(t, Math.max(t0, p + room)) : Math.max(t, Math.min(t0, p - room));
156 }
157 if (t === t0) continue; // nowhere to go: nothing to send
158 if (ended) stops.push(id);
159 this.targets.set(id, t);
160 frame[id] = Math.round(t);
161 any = true;
162 }
163 return { frame: any ? frame : null, stops };
164 }
165
166 /** @param {number} id @param {number} t @param {Limits} limits */
167 #clamp(id, t, limits) {
168 const l = limits[id];
169 if (!l) return t;
170 return Math.max(l.min + this.margin, Math.min(l.max - this.margin, t));
171 }
172
173 /** @param {number[]} ids */
174 #stop(ids) {
175 const still = this.held();
176 /** @type {Frame} */
177 const frame = {};
178 let any = false;
179 for (const id of ids) {
180 if (still.has(id)) continue; // another finger still drives it
181 const t = this.targets.get(id);
182 this.targets.delete(id);
183 if (t === undefined) continue;
184 frame[id] = Math.round(t);
185 this.present.set(id, t); // until the arm says otherwise, it is where it was told to stop
186 any = true;
187 }
188 return any ? frame : null;
189 }
190 }
191
192 /**
193 * The page's driver: a Drive, a clock at the send rate while anything is held, and the ways a press ends.
194 * `send` takes frames at the clock's rate (the page may coalesce them); `flush` must put a frame on the wire now,
195 * because it is the zero; `end` says nothing is held any more.
196 */
197 export class Driver {
198 /**
199 * @param {{
200 * send: (frame: Frame) => void,
201 * flush: (frame: Frame) => void,
202 * end: () => void,
203 * begin?: () => boolean | void,
204 * limits: () => Limits,
205 * speed: () => number,
206 * hz?: number,
207 * onStop?: (id: number) => void,
208 * timers?: { every: (fn: () => void, ms: number) => unknown, cancel: (handle: unknown) => void, now: () => number },
209 * }} options
210 */
211 constructor(options) {
212 this.o = options;
213 this.drive = new Drive();
214 this.hz = Math.max(20, Math.min(30, options.hz ?? 25));
215 this.timers = options.timers ?? { every: (fn, ms) => setInterval(fn, ms), cancel: (h) => clearInterval(/** @type {any} */ (h)), now: () => performance.now() };
216 /** @type {unknown} */
217 this.clock = null;
218 this.last = 0;
219 }
220
221 /** Whether a finger (or a key) is down on anything. */
222 get active() {
223 return this.clock !== null;
224 }
225
226 /** @param {Iterable<readonly [number, number]>} positions */
227 seed(positions) {
228 this.drive.seed(positions);
229 }
230
231 /** @param {string} holder @param {Record<number, number>} axes @returns {boolean} false when driving is refused */
232 hold(holder, axes) {
233 if (!this.clock) {
234 if (this.o.begin?.() === false) return false;
235 this.last = this.timers.now();
236 this.clock = this.timers.every(() => this.tick(), 1000 / this.hz);
237 }
238 const stopped = this.drive.hold(holder, axes);
239 if (stopped) this.o.flush(stopped);
240 return true;
241 }
242
243 /** A holder lets go: its joints' zero goes out now, not at the next tick. @param {string} holder */
244 release(holder) {
245 const frame = this.drive.release(holder);
246 if (frame) this.o.flush(frame);
247 if (this.clock && this.drive.holders.size === 0) this.#idle();
248 }
249
250 /** Everything lets go at once: the window lost focus, the page was hidden. */
251 releaseAll() {
252 const frame = this.drive.releaseAll();
253 if (frame) this.o.flush(frame);
254 if (this.clock) this.#idle();
255 }
256
257 /** One step of one joint, for a tap. @param {number} id @param {number} ticks signed */
258 nudge(id, ticks) {
259 if (this.o.begin?.() === false) return;
260 const frame = this.drive.nudge(id, ticks, this.o.limits());
261 if (frame) this.o.flush(frame);
262 if (!this.clock) this.o.end();
263 }
264
265 tick() {
266 const now = this.timers.now();
267 const dt = Math.min(0.1, Math.max(0, (now - this.last) / 1000)); // a late tick never turns into a jump
268 this.last = now;
269 const { frame, stops } = this.drive.step(dt, this.o.speed(), this.o.limits());
270 if (frame) this.o.send(frame);
271 for (const id of stops) this.o.onStop?.(id);
272 }
273
274 #idle() {
275 this.timers.cancel(this.clock);
276 this.clock = null;
277 this.o.end();
278 }
279
280 /**
281 * Every way a hold can end without a pointerup: the window loses focus, the page is hidden or put away.
282 * @param {EventTarget} win @param {EventTarget & { hidden?: boolean }} doc
283 */
284 watch(win, doc) {
285 const all = () => this.releaseAll();
286 win.addEventListener("blur", all);
287 win.addEventListener("pagehide", all);
288 doc.addEventListener("visibilitychange", () => { if (doc.hidden) all(); });
289 }
290 }
291
292 /**
293 * @typedef {EventTarget & {
294 * setPointerCapture?: (id: number) => void,
295 * getBoundingClientRect: () => { left: number, top: number, width: number, height: number },
296 * classList: { toggle: (name: string, on?: boolean) => unknown },
297 * }} Surface
298 * @typedef {Event & { pointerId: number, clientX: number, clientY: number }} Pointer
299 */
300
301 /**
302 * One finger on a surface, tracked by its pointerId: `place` maps where it is to joint deflections, every way the
303 * finger can leave ends the hold, and a second finger on the same surface is ignored until the first one lifts.
304 * Two surfaces are two holders, so two thumbs drive two sets of joints independently.
305 * @param {Surface} el
306 * @param {Driver} driver
307 * @param {string} holder
308 * @param {(x: number, y: number) => Record<number, number> | null} place x, y from -1 to 1 across the surface, y up
309 * @param {{ show?: (x: number, y: number) => void, haptic?: () => void }} [view]
310 * @returns {{ end: () => void }}
311 */
312 export function bindSurface(el, driver, holder, place, view = {}) {
313 /** @type {number | null} */
314 let pointer = null;
315 /** @param {Pointer} e */
316 const at = (e) => {
317 const r = el.getBoundingClientRect();
318 const x = r.width ? ((e.clientX - r.left) / r.width) * 2 - 1 : 0;
319 const y = r.height ? 1 - ((e.clientY - r.top) / r.height) * 2 : 0;
320 return [Math.max(-1, Math.min(1, x)), Math.max(-1, Math.min(1, y))];
321 };
322 /** @param {Pointer} e */
323 const apply = (e) => {
324 const [x = 0, y = 0] = at(e);
325 view.show?.(x, y);
326 const axes = place(x, y);
327 if (!axes) return false;
328 return driver.hold(holder, axes);
329 };
330 const end = () => {
331 if (pointer === null) return;
332 pointer = null;
333 el.classList.toggle("held", false);
334 view.show?.(0, 0);
335 driver.release(holder);
336 };
337 el.addEventListener("pointerdown", (ev) => {
338 const e = /** @type {Pointer} */ (ev);
339 if (pointer !== null) return;
340 e.preventDefault();
341 pointer = e.pointerId;
342 try { el.setPointerCapture?.(e.pointerId); } catch { /* a synthetic pointer */ }
343 el.classList.toggle("held", true);
344 view.haptic?.();
345 if (apply(e) === false) end();
346 });
347 el.addEventListener("pointermove", (ev) => {
348 const e = /** @type {Pointer} */ (ev);
349 if (e.pointerId === pointer) apply(e);
350 });
351 for (const type of ["pointerup", "pointercancel", "lostpointercapture"]) {
352 el.addEventListener(type, (ev) => { if (/** @type {Pointer} */ (ev).pointerId === pointer) end(); });
353 }
354 el.addEventListener("contextmenu", (e) => e.preventDefault());
355 return { end };
356 }
Software/so101/src/ui/drive.test.ts deleted −293
@@ -1,293 +0,0 @@
1 import { describe, expect, test } from "bun:test";
2 import { bindSurface, canDrive, Drive, Driver, shape } from "./drive.js";
3
4 const LIMITS = { 1: { min: 1000, max: 3000 }, 2: { min: 1000, max: 3000 }, 3: { min: 1000, max: 3000 }, 4: { min: 1000, max: 3000 }, 6: { min: 2000, max: 3500 } };
5 const AT = [[1, 2000], [2, 2000], [3, 2000], [4, 2000], [6, 2500]] as const;
6
7 /** A driver on a hand-wound clock that records what goes on the wire, and when. */
8 function rig() {
9 const wire: Array<{ kind: "send" | "flush" | "end"; frame?: Record<number, number>; at: number }> = [];
10 let now = 0;
11 let tick: (() => void) | null = null;
12 const driver = new Driver({
13 send: (frame) => wire.push({ kind: "send", frame, at: now }),
14 flush: (frame) => wire.push({ kind: "flush", frame, at: now }),
15 end: () => wire.push({ kind: "end", at: now }),
16 limits: () => LIMITS,
17 speed: () => 300,
18 timers: { every: (fn) => ((tick = fn), 1), cancel: () => (tick = null), now: () => now },
19 });
20 driver.seed(AT);
21 /** Advance the clock by one 40 ms frame and run the tick, when one is running. */
22 const frame = () => {
23 now += 40;
24 tick?.();
25 };
26 return { driver, wire, frame, running: () => tick !== null };
27 }
28
29 /** A surface 100 px square at the origin, built on EventTarget like the page's elements. */
30 function surface() {
31 const el = Object.assign(new EventTarget(), {
32 captured: [] as number[],
33 held: false,
34 setPointerCapture(id: number) { this.captured.push(id); },
35 getBoundingClientRect: () => ({ left: 0, top: 0, width: 100, height: 100 }),
36 classList: { toggle: (_: string, on?: boolean) => (el.held = Boolean(on)) },
37 });
38 return el;
39 }
40 const pointer = (type: string, pointerId: number, clientX = 50, clientY = 50) => Object.assign(new Event(type, { cancelable: true }), { pointerId, clientX, clientY });
41
42 describe("the stick's shape", () => {
43 test("a dead band in the middle, the full speed at the edge, never more", () => {
44 expect(shape(0.05)).toBe(0);
45 expect(shape(-0.12)).toBe(0);
46 expect(shape(1)).toBe(1);
47 expect(shape(-3)).toBe(-1);
48 expect(shape(Number.NaN)).toBe(0);
49 expect(shape(0.5)).toBeGreaterThan(0);
50 expect(shape(0.5)).toBeLessThan(0.5); // fine control a little way out
51 expect(shape(-0.5)).toBe(-shape(0.5));
52 });
53 });
54
55 describe("the velocity integrator", () => {
56 test("a held joint runs ahead at the deflection's share of the speed, from where the arm is", () => {
57 const d = new Drive();
58 d.seed(AT);
59 d.hold("a", { 1: 0.5 });
60 expect(d.step(0.1, 300, LIMITS).frame).toEqual({ 1: 2015 });
61 expect(d.step(0.1, 300, LIMITS).frame).toEqual({ 1: 2030 });
62 });
63
64 test("the target stops at the range's margin and says so once", () => {
65 const d = new Drive();
66 d.seed([[1, 2960]]);
67 d.hold("a", { 1: 1 });
68 expect(d.step(0.1, 300, LIMITS)).toEqual({ frame: { 1: 2970 }, stops: [1] });
69 expect(d.step(0.1, 300, LIMITS)).toEqual({ frame: null, stops: [] });
70 });
71
72 test("never runs more than the lead ahead of an arm that lags, and never steps back toward a stale reading", () => {
73 const d = new Drive({ lead: 0.5 });
74 d.seed([[1, 2000]]);
75 d.hold("a", { 1: 1 });
76 for (let i = 0; i < 20; i++) d.step(0.1, 300, LIMITS);
77 expect(d.targets.get(1)).toBe(2150); // 0.5 s of 300 ticks/s ahead of where the arm said it was
78 d.seed([[1, 1900]]); // a reading older than the target
79 expect(d.step(0.1, 300, LIMITS).frame).toBeNull();
80 expect(d.targets.get(1)).toBe(2150);
81 });
82
83 test("a joint without a position is not driven", () => {
84 const d = new Drive();
85 d.hold("a", { 5: 1 });
86 expect(d.step(0.1, 300, LIMITS).frame).toBeNull();
87 expect(d.release("a")).toBeNull();
88 });
89
90 test("a tap nudges from the last target, inside the range", () => {
91 const d = new Drive();
92 d.seed([[6, 3450]]);
93 expect(d.nudge(6, 20, LIMITS)).toEqual({ 6: 3470 });
94 expect(d.nudge(6, 20, LIMITS)).toEqual({ 6: 3470 });
95 expect(d.nudge(6, -20, LIMITS)).toEqual({ 6: 3450 });
96 });
97 });
98
99 describe("the driver", () => {
100 test("lifting the finger sends zero within one frame: the target as it stands, flushed at once, then nothing", () => {
101 const { driver, wire, frame, running } = rig();
102 driver.hold("lever", { 2: 1 });
103 frame(); frame();
104 const last = wire.at(-1)!;
105 expect(last.kind).toBe("send");
106 const sentAt = wire.length;
107 driver.release("lever");
108 // Before any further tick of the clock: the zero is already on the wire.
109 expect(wire.slice(sentAt)).toEqual([{ kind: "flush", frame: last.frame, at: last.at }, { kind: "end", at: last.at }]);
110 expect(running()).toBe(false);
111 frame(); frame();
112 expect(wire.length).toBe(sentAt + 2); // and nothing after it
113 });
114
115 test("two thumbs drive independent joints: lifting one stops only its joints", () => {
116 const { driver, wire, frame } = rig();
117 driver.hold("left", { 1: 1, 2: 0 });
118 driver.hold("right", { 3: -1 });
119 frame();
120 expect(wire.at(-1)).toEqual({ kind: "send", frame: { 1: 2012, 3: 1988 }, at: 40 });
121 driver.release("left");
122 expect(wire.at(-1)).toEqual({ kind: "flush", frame: { 1: 2012, 2: 2000 }, at: 40 });
123 frame();
124 expect(wire.at(-1)).toEqual({ kind: "send", frame: { 3: 1976 }, at: 80 }); // the right thumb goes on
125 driver.release("right");
126 expect(wire.slice(-2)).toEqual([{ kind: "flush", frame: { 3: 1976 }, at: 80 }, { kind: "end", at: 80 }]);
127 });
128
129 test("two fingers on one joint: it stops only when both have lifted", () => {
130 const { driver, wire, frame } = rig();
131 driver.hold("lever", { 4: 1 });
132 driver.hold("plus", { 4: 1 });
133 frame();
134 driver.release("plus");
135 expect(wire.at(-1)!.kind).toBe("send");
136 frame();
137 expect(wire.at(-1)).toEqual({ kind: "send", frame: { 4: 2024 }, at: 80 });
138 driver.release("lever");
139 expect(wire.at(-1)!.kind).toBe("end");
140 });
141
142 test("blur, pagehide and a hidden page stop every joint at once", () => {
143 for (const how of ["blur", "pagehide", "hidden"] as const) {
144 const { driver, wire, frame, running } = rig();
145 const win = new EventTarget(), doc = Object.assign(new EventTarget(), { hidden: false });
146 driver.watch(win, doc);
147 driver.hold("left", { 1: 1 });
148 driver.hold("right", { 3: 1 });
149 frame();
150 if (how === "hidden") { doc.hidden = true; doc.dispatchEvent(new Event("visibilitychange")); }
151 else win.dispatchEvent(new Event(how));
152 expect(wire.slice(-2)).toEqual([{ kind: "flush", frame: { 1: 2012, 3: 2012 }, at: 40 }, { kind: "end", at: 40 }]);
153 expect(running()).toBe(false);
154 }
155 });
156
157 test("a hidden page that was not driving sends nothing", () => {
158 const { driver, wire } = rig();
159 const win = new EventTarget(), doc = Object.assign(new EventTarget(), { hidden: true });
160 driver.watch(win, doc);
161 doc.dispatchEvent(new Event("visibilitychange"));
162 win.dispatchEvent(new Event("blur"));
163 expect(wire).toEqual([]);
164 });
165
166 test("refused by the page (not your turn), a press starts nothing", () => {
167 const wire: unknown[] = [];
168 const driver = new Driver({ send: (f) => wire.push(f), flush: (f) => wire.push(f), end: () => wire.push("end"), begin: () => false, limits: () => LIMITS, speed: () => 300 });
169 driver.seed(AT);
170 expect(driver.hold("x", { 1: 1 })).toBe(false);
171 expect(driver.active).toBe(false);
172 driver.nudge(1, 20);
173 expect(wire).toEqual([]);
174 });
175
176 test("a tap nudges and ends at once", () => {
177 const { driver, wire } = rig();
178 driver.nudge(6, -20);
179 expect(wire).toEqual([{ kind: "flush", frame: { 6: 2480 }, at: 0 }, { kind: "end", at: 0 }]);
180 });
181 });
182
183 describe("a surface under a finger", () => {
184 const lever = (y: number) => ({ 2: y });
185
186 test("pointerup sends the zero before the next frame, and the surface lets go", () => {
187 const { driver, wire, frame } = rig();
188 const el = surface();
189 bindSurface(el, driver, "lever", (_, y) => lever(y));
190 el.dispatchEvent(pointer("pointerdown", 7, 50, 0)); // the top edge: full speed up
191 expect(el.captured).toEqual([7]);
192 expect(el.held).toBe(true);
193 frame();
194 expect(wire.at(-1)).toEqual({ kind: "send", frame: { 2: 2012 }, at: 40 });
195 el.dispatchEvent(pointer("pointerup", 7));
196 expect(wire.slice(-2)).toEqual([{ kind: "flush", frame: { 2: 2012 }, at: 40 }, { kind: "end", at: 40 }]);
197 expect(el.held).toBe(false);
198 });
199
200 for (const type of ["pointercancel", "lostpointercapture"]) {
201 test(`${type} ends the hold like a lift`, () => {
202 const { driver, wire, frame, running } = rig();
203 const el = surface();
204 bindSurface(el, driver, "lever", (_, y) => lever(y));
205 el.dispatchEvent(pointer("pointerdown", 3, 50, 100));
206 frame();
207 el.dispatchEvent(pointer(type, 3));
208 expect(wire.at(-1)!.kind).toBe("end");
209 expect(running()).toBe(false);
210 });
211 }
212
213 test("a second finger on the same surface neither steers it nor ends it", () => {
214 const { driver, wire, frame } = rig();
215 const el = surface();
216 bindSurface(el, driver, "lever", (_, y) => lever(y));
217 el.dispatchEvent(pointer("pointerdown", 1, 50, 0));
218 el.dispatchEvent(pointer("pointerdown", 2, 50, 100));
219 el.dispatchEvent(pointer("pointermove", 2, 50, 100));
220 el.dispatchEvent(pointer("pointerup", 2));
221 frame();
222 expect(wire.at(-1)).toEqual({ kind: "send", frame: { 2: 2012 }, at: 40 });
223 });
224
225 test("two sticks under two thumbs, each with its own pointer, drive their own joints", () => {
226 const { driver, wire, frame } = rig();
227 const left = surface(), right = surface();
228 bindSurface(left, driver, "left", (x, y) => ({ 1: x, 2: y }));
229 bindSurface(right, driver, "right", (x, y) => ({ 4: x, 3: y }));
230 left.dispatchEvent(pointer("pointerdown", 11, 100, 50)); // full right
231 right.dispatchEvent(pointer("pointerdown", 12, 50, 100)); // full down
232 frame();
233 expect(wire.at(-1)).toEqual({ kind: "send", frame: { 1: 2012, 3: 1988 }, at: 40 });
234 right.dispatchEvent(pointer("pointerup", 11)); // the other thumb's id on this stick: ignored
235 left.dispatchEvent(pointer("pointerup", 11));
236 expect(wire.at(-1)).toEqual({ kind: "flush", frame: { 1: 2012, 2: 2000 }, at: 40 });
237 frame();
238 expect(wire.at(-1)).toEqual({ kind: "send", frame: { 3: 1976 }, at: 80 });
239 });
240
241 test("a press the page refuses lets go of the surface at once", () => {
242 const driver = new Driver({ send: () => {}, flush: () => {}, end: () => {}, begin: () => false, limits: () => LIMITS, speed: () => 300 });
243 const el = surface();
244 bindSurface(el, driver, "lever", (_, y) => lever(y));
245 el.dispatchEvent(pointer("pointerdown", 1, 50, 0));
246 expect(el.held).toBe(false);
247 });
248
249 test("the arm drops while a thumb is held: the poll's releaseAll flushes the zero, and the still-pressed stick sends nothing more", () => {
250 const wire: Array<{ kind: string; frame?: Record<number, number> }> = [];
251 let tick: (() => void) | null = null, now = 0;
252 const state = { mayDrive: true, estop: false, reconnecting: false, limits: LIMITS };
253 const driver = new Driver({
254 send: (frame) => wire.push({ kind: "send", frame }),
255 flush: (frame) => wire.push({ kind: "flush", frame }),
256 end: () => wire.push({ kind: "end" }),
257 begin: () => canDrive(state),
258 limits: () => LIMITS,
259 speed: () => 300,
260 timers: { every: (fn) => ((tick = fn), 1), cancel: () => (tick = null), now: () => now },
261 });
262 driver.seed(AT);
263 const stick = surface();
264 bindSurface(stick, driver, "left", (x, y) => ({ 1: x, 2: y }));
265 stick.dispatchEvent(pointer("pointerdown", 7, 100, 50));
266 now += 40; tick!();
267 expect(wire.at(-1)).toEqual({ kind: "send", frame: { 1: 2012 } });
268 // The status poll: reconnecting, so driving is refused and everything held lets go.
269 state.reconnecting = true;
270 if (!canDrive(state)) driver.releaseAll();
271 expect(wire.slice(-2)).toEqual([{ kind: "flush", frame: { 1: 2012, 2: 2000 } }, { kind: "end" }]);
272 expect(tick).toBeNull();
273 const after = wire.length;
274 stick.dispatchEvent(pointer("pointermove", 7, 100, 0)); // the thumb is still down and moving
275 expect(wire.length).toBe(after);
276 expect(tick).toBeNull();
277 });
278 });
279
280 describe("canDrive", () => {
281 const ok = { mayDrive: true, estop: false, reconnecting: false, limits: LIMITS };
282 test("drives on your turn, with the arm up and its limits known", () => {
283 expect(canDrive(ok)).toBe(true);
284 });
285 test("refuses when it is not your turn, the arm is stopped, the arm is reconnecting, or no limits have come", () => {
286 expect(canDrive({ ...ok, mayDrive: false })).toBe(false);
287 expect(canDrive({ ...ok, estop: true })).toBe(false);
288 expect(canDrive({ ...ok, held: { by: "ann", at: "2026-10-20T22:05:00Z" } })).toBe(false); // STOP, until someone resumes
289 expect(canDrive({ ...ok, reconnecting: true })).toBe(false);
290 expect(canDrive({ ...ok, limits: {} })).toBe(false);
291 expect(canDrive({ ...ok, limits: null })).toBe(false);
292 });
293 });
Software/so101/src/ui/notes.js added +60
@@ -0,0 +1,60 @@
1 /**
2 * Notes: what the page has to say, kept off the camera and the model. Standing notes (a zone warning, reconnecting,
3 * the speed cap, the announcement) are there while their condition holds; messages the page says (a pose reached, a
4 * refusal) are kept for a minute, the last few only. The strip shows one pill with the count and the worst level; a tap
5 * opens the list. Plain ESM, served at /ui/ and imported by the tests.
6 */
7
8 /** @typedef {"info" | "warn" | "bad"} Level */
9 /** @typedef {{ text: string, level: Level, at?: number }} Note */
10
11 const RANK = { info: 0, warn: 1, bad: 2 };
12 /** @param {unknown} level @returns {Level} */
13 const level = (level) => (level === "warn" || level === "bad" ? level : "info");
14
15 export class Notes {
16 /** @param {{ keep?: number, last?: number }} [options] keep: ms a message counts; last: how many messages are kept */
17 constructor(options = {}) {
18 this.keep = options.keep ?? 60000;
19 this.last = options.last ?? 5;
20 /** @type {Map<string, Note>} */
21 this.standing = new Map();
22 /** @type {Note[]} */
23 this.said = [];
24 }
25
26 /**
27 * A standing note under `key`, or none when `text` is empty. @returns {boolean} whether anything changed
28 * @param {string} key @param {string | null | undefined} text @param {Level} [lvl]
29 */
30 set(key, text, lvl = "info") {
31 const was = this.standing.get(key);
32 if (!text) return this.standing.delete(key);
33 const next = { text: String(text), level: level(lvl) };
34 if (was?.text === next.text && was.level === next.level) return false;
35 this.standing.set(key, next);
36 return true;
37 }
38
39 /** A message, counted from `now`. @param {string} text @param {Level} lvl @param {number} now */
40 say(text, lvl, now) {
41 if (!text) return;
42 this.said.push({ text: String(text), level: level(lvl), at: now });
43 if (this.said.length > this.last) this.said.splice(0, this.said.length - this.last);
44 }
45
46 /** Forget the messages; standing notes stay while their condition does. */
47 clear() { this.said = []; }
48
49 /** Every note now: the standing ones first, then the messages, newest first. @param {number} now @returns {Note[]} */
50 list(now) {
51 this.said = this.said.filter((n) => now - /** @type {number} */ (n.at) < this.keep);
52 return [...this.standing.values(), ...[...this.said].reverse()];
53 }
54 }
55
56 /** The pill: hidden at none, "1 note", "3 notes", coloured by the worst. @param {Note[]} list */
57 export function pill(list) {
58 const worst = list.reduce((w, n) => (RANK[n.level] > RANK[w] ? n.level : w), /** @type {Level} */ ("info"));
59 return { hidden: list.length === 0, text: list.length === 1 ? "1 note" : `${list.length} notes`, level: worst };
60 }
Software/so101/src/ui/notes.test.ts added +38
@@ -0,0 +1,38 @@
1 import { describe, expect, test } from "bun:test";
2 import { Notes, pill } from "./notes.js";
3
4 describe("notes", () => {
5 test("a standing note is there while its condition holds, and says when it changed", () => {
6 const n = new Notes();
7 expect(n.set("arm", "Reconnecting to the arm…", "warn")).toBe(true);
8 expect(n.set("arm", "Reconnecting to the arm…", "warn")).toBe(false); // the same: nothing to redraw
9 expect(n.list(0)).toEqual([{ text: "Reconnecting to the arm…", level: "warn" }]);
10 expect(n.set("arm", null)).toBe(true);
11 expect(n.set("arm", null)).toBe(false);
12 expect(n.list(0)).toEqual([]);
13 });
14
15 test("messages count for a minute, the last five only, newest first after the standing notes", () => {
16 const n = new Notes();
17 n.set("cap", "Speed limited to 50% of full");
18 for (let i = 1; i <= 7; i++) n.say(`message ${i}`, "info", i * 1000);
19 const now = n.list(8000);
20 expect(now.map((x) => x.text)).toEqual(["Speed limited to 50% of full", "message 7", "message 6", "message 5", "message 4", "message 3"]);
21 expect(n.list(66_500).map((x) => x.text)).toEqual(["Speed limited to 50% of full", "message 7"]);
22 n.clear();
23 expect(n.list(66_500).map((x) => x.text)).toEqual(["Speed limited to 50% of full"]);
24 });
25
26 test("an unknown level is plain information, and an empty message is no note", () => {
27 const n = new Notes();
28 n.say("", "bad", 0);
29 n.set("x", "hello", "loud" as never);
30 expect(n.list(0)).toEqual([{ text: "hello", level: "info" }]);
31 });
32
33 test("the pill: hidden at none, a count, and the colour of the worst", () => {
34 expect(pill([])).toEqual({ hidden: true, text: "0 notes", level: "info" });
35 expect(pill([{ text: "a", level: "info" }])).toEqual({ hidden: false, text: "1 note", level: "info" });
36 expect(pill([{ text: "a", level: "warn" }, { text: "b", level: "bad" }, { text: "c", level: "info" }])).toEqual({ hidden: false, text: "3 notes", level: "bad" });
37 });
38 });
Software/so101/src/ui/reach.js deleted −79
@@ -1,79 +0,0 @@
1 /**
2 * The touch joystick's arithmetic: move the gripper, not a joint. Plain ESM, served to the page at /ui/ and
3 * imported by the tests. The page owns the arm's geometry (the URDF in three.js) and hands it in as `tip`:
4 * joint angles in, the gripper's position in the base frame (metres, z up) out.
5 */
6
7 /**
8 * The joystick and the height buttons as a displacement of the gripper, in the base frame.
9 * Up on the pad reaches away from the base, sideways swings around it; `lift` is -1, 0 or 1.
10 * `tip` is where the gripper is now; the step is `speed` m/s for `dt` seconds at full deflection.
11 * @param {{ x: number, y: number, lift: number }} stick
12 * @param {number[]} tip
13 * @param {number} speed
14 * @param {number} dt
15 * @returns {number[]}
16 */
17 export function stickToDelta(stick, tip, speed, dt) {
18 const [tx = 0, ty = 0] = tip;
19 const r = Math.hypot(tx, ty);
20 // Straight above the base there is no "away": take the base's own forward, +x.
21 const fx = r > 1e-3 ? tx / r : 1;
22 const fy = r > 1e-3 ? ty / r : 0;
23 const x = clampUnit(stick.x), y = clampUnit(stick.y), lift = clampUnit(stick.lift);
24 const step = speed * dt;
25 // Sideways is the forward direction turned a quarter to the right, seen from above.
26 return [(fx * y + fy * x) * step, (fy * y - fx * x) * step, lift * step];
27 }
28
29 /**
30 * One damped-least-squares step: the joint changes that move the tip by `delta`.
31 * The Jacobian comes from `tip` by finite differences, so any chain the page can evaluate works;
32 * the damping keeps the step small near a stretched-out or folded-up arm instead of letting it whip.
33 * @param {(angles: number[]) => number[]} tip
34 * @param {number[]} angles
35 * @param {number[]} delta
36 * @param {{ h?: number, damping?: number, maxStep?: number }} [options]
37 * @returns {number[]}
38 */
39 export function reachStep(tip, angles, delta, options = {}) {
40 const h = options.h ?? 1e-4, damping = options.damping ?? 0.02, maxStep = options.maxStep ?? 0.08;
41 const here = tip(angles);
42 const n = angles.length;
43 /** @type {number[][]} J[row][joint] */
44 const J = [[], [], []];
45 for (let j = 0; j < n; j++) {
46 const moved = angles.slice();
47 moved[j] = (moved[j] ?? 0) + h;
48 const there = tip(moved);
49 for (let r = 0; r < 3; r++) /** @type {number[]} */ (J[r])[j] = ((there[r] ?? 0) - (here[r] ?? 0)) / h;
50 }
51 // dq = Jᵀ (J Jᵀ + λ² I)⁻¹ delta
52 const A = [0, 1, 2].map((r) => [0, 1, 2].map((c) => dot(/** @type {number[]} */ (J[r]), /** @type {number[]} */ (J[c])) + (r === c ? damping * damping : 0)));
53 const w = solve3(A, delta);
54 const dq = angles.map((_, j) => w.reduce((s, wr, r) => s + wr * (/** @type {number[]} */ (J[r])[j] ?? 0), 0));
55 // Never more than maxStep radians on any joint in one step.
56 const biggest = Math.max(...dq.map(Math.abs));
57 return biggest > maxStep ? dq.map((d) => (d * maxStep) / biggest) : dq;
58 }
59
60 /** @param {number} v */
61 const clampUnit = (v) => (Number.isFinite(v) ? Math.max(-1, Math.min(1, v)) : 0);
62 /** @param {number[]} a @param {number[]} b */
63 const dot = (a, b) => a.reduce((s, v, i) => s + v * (b[i] ?? 0), 0);
64
65 /**
66 * Cramer's rule for a 3×3 system; a singular matrix gives no motion.
67 * @param {number[][]} A
68 * @param {number[]} b
69 */
70 function solve3(A, b) {
71 /** @param {number[][]} m */
72 const det = (m) => {
73 const [[a = 0, b = 0, c = 0] = [], [d = 0, e = 0, f = 0] = [], [g = 0, h = 0, i = 0] = []] = m;
74 return a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
75 };
76 const d = det(A);
77 if (!Number.isFinite(d) || Math.abs(d) < 1e-12) return [0, 0, 0];
78 return [0, 1, 2].map((c) => det(A.map((row, r) => row.map((v, k) => (k === c ? b[r] ?? 0 : v)))) / d);
79 }
Software/so101/src/ui/reach.test.ts deleted −58
@@ -1,58 +0,0 @@
1 import { describe, expect, test } from "bun:test";
2 import { reachStep, stickToDelta } from "./reach.js";
3
4 // A yaw joint and a two-link planar arm on top of it: the SO-101's pan, shoulder lift and elbow, roughly.
5 const L1 = 0.116, L2 = 0.135;
6 const tip = ([pan = 0, lift = 0, elbow = 0]: number[]) => {
7 const reach = L1 * Math.cos(lift) + L2 * Math.cos(lift + elbow);
8 const z = L1 * Math.sin(lift) + L2 * Math.sin(lift + elbow);
9 return [reach * Math.cos(pan), reach * Math.sin(pan), z];
10 };
11 const distance = (a: number[], b: number[]) => Math.hypot(...a.map((v, i) => v - b[i]!));
12
13 describe("the joystick as a displacement", () => {
14 test("up on the pad reaches away from the base, whichever way the arm faces", () => {
15 const [dx, dy, dz] = stickToDelta({ x: 0, y: 1, lift: 0 }, [0, 0.2, 0.1], 0.05, 0.1);
16 expect(dx).toBeCloseTo(0);
17 expect(dy).toBeCloseTo(0.005);
18 expect(dz).toBe(0);
19 });
20
21 test("right on the pad swings clockwise seen from above, and lift is straight up", () => {
22 const [dx, dy, dz] = stickToDelta({ x: 1, y: 0, lift: 1 }, [0.2, 0, 0.1], 0.05, 0.1);
23 expect(dx).toBeCloseTo(0);
24 expect(dy).toBeCloseTo(-0.005);
25 expect(dz).toBeCloseTo(0.005);
26 });
27
28 test("a deflection past the edge or a broken number is clamped, never amplified", () => {
29 const [dx, dy, dz] = stickToDelta({ x: 0, y: 9, lift: Number.NaN }, [0.2, 0, 0], 0.05, 0.1);
30 expect(dx).toBeCloseTo(0.005);
31 expect(dy).toBeCloseTo(0);
32 expect(dz).toBe(0);
33 });
34 });
35
36 describe("a reach step", () => {
37 test("moves the tip the way it was asked, and the error shrinks step by step", () => {
38 let angles = [0.3, 0.6, -1.2];
39 const start = tip(angles);
40 const goal = [start[0]! + 0.03, start[1]! - 0.02, start[2]! + 0.02];
41 let before = distance(start, goal);
42 for (let i = 0; i < 20; i++) {
43 const here = tip(angles);
44 const delta = goal.map((g, k) => g - here[k]!);
45 angles = angles.map((a, k) => a + reachStep(tip, angles, delta)[k]!);
46 const after = distance(tip(angles), goal);
47 expect(after).toBeLessThanOrEqual(before + 1e-9);
48 before = after;
49 }
50 expect(before).toBeLessThan(0.001);
51 });
52
53 test("a stretched-out arm asked to reach further barely moves instead of whipping", () => {
54 const angles = [0, 0, 0]; // straight out: no joint can take the tip further away
55 const dq = reachStep(tip, angles, [0.05, 0, 0]);
56 for (const d of dq) expect(Math.abs(d)).toBeLessThanOrEqual(0.08);
57 });
58 });
Software/so101/src/viewer.html +193 −359
@@ -18,17 +18,19 @@
1818 } }
1919 </script>
2020 <link rel="modulepreload" href="/ui/__VERSION__/camera-plan.js">
21 <link rel="modulepreload" href="/ui/__VERSION__/drive.js">
2221 <link rel="modulepreload" href="/ui/__VERSION__/frames.js">
22 <link rel="modulepreload" href="/ui/__VERSION__/notes.js">
2323 <style>
24 /* Phone portrait first: the view on top, a status strip with the E-stop under it, a sheet of tabs below that.
25 Landscape on a phone: the view fills the screen and the strip and the sheet float over it.
26 A wider screen: the sheet becomes a column beside the view. The forge pill owns the bottom-right corner. */
24 /* Phone portrait first: the camera on top (16:9), the status strip with the one STOP under it, the 3D model filling
25 the space below, then the open tab's tray and the tabs. Nothing is drawn over the camera or the model but their own
26 labels: notes collapse into a pill in the strip, a stop is a row of its own.
27 Landscape on a phone: the strip on top, the camera and the model side by side, the sheet a column when shown.
28 A wider screen: camera, model and the sheet as three columns. The forge pill owns the bottom-right corner. */
2729 :root {
2830 color-scheme: dark; --bg: #0b0d10; --surface: #0d1117; --raised: #161b22; --fg: #e8eaed; --fg2: #c9d1d9; --dim: #9aa4ae;
2931 --line: #30363d; --btn: #21262d; --btn-hover: #30363d; --link: #58a6ff; --blue: #388bfd; --on-blue: #fff;
3032 --ok: #3fb950; --warn: #d29922; --bad: #f85149; --bad-soft: rgba(248,81,73,.18); --blue-soft: rgba(56,139,253,.18);
31 --tap: 44px; --pill: 68px; --view: min(42svh, 75vw);
33 --tap: 44px; --pill: 68px; --tray: clamp(150px, 30dvh, 260px);
3234 --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
3335 }
3436 @media (prefers-color-scheme: light) {
@@ -53,16 +55,21 @@
5355 [hidden] { display: none !important; }
5456 [inert] { opacity: .5; }
5557
56 #shell { position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); height: var(--vv-h, 100dvh); display: grid; grid-template-columns: 100%; grid-template-rows: minmax(0, var(--view)) auto minmax(0, 1fr); grid-template-areas: "view" "strip" "sheet"; }
57 #shell.typing { --view: 24%; }
58 #shell { position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); height: var(--vv-h, 100dvh); display: grid; grid-template-columns: 100%; grid-template-rows: auto auto auto minmax(0, 1fr) auto; grid-template-areas: "view" "strip" "banner" "model" "sheet"; }
59 #shell.typing #app { aspect-ratio: auto; height: 16svh; }
5860
59 /* the view: cameras and the 3D model, always on black */
60 #app { grid-area: view; position: relative; min-height: 0; background: #000; color: #e8eaed; overflow: hidden; }
61 /* the camera, and the 3D model in a box of its own, always on black */
62 #app { grid-area: view; position: relative; min-height: 0; aspect-ratio: 16 / 9; background: #000; color: #e8eaed; overflow: hidden; }
63 #shell.nocam #app { display: none; }
64 #modelBox { grid-area: model; position: relative; min-height: 0; background: #000; color: #e8eaed; overflow: hidden; touch-action: none; }
65 #modelBox .pane { position: absolute; inset: 0; }
66 #shell.no3d #modelBox { display: none; }
6167 #stage { position: absolute; inset: 0; display: flex; gap: 2px; }
62 /* the emergency stop's held state, and the banner that says who pressed it */
68 /* the emergency stop's held state, and the full-width row that says who pressed it: a row, never over the picture */
6369 .estop:disabled { opacity: .5; cursor: not-allowed; } .estop.on { background: #7d1410; box-shadow: 0 0 0 3px var(--bad); }
64 #banner.stop { display: block; border: 2px solid var(--bad); background: rgba(80,10,8,.92); color: #fff; font-weight: 600; }
65 #banner button { margin-left: 10px; min-height: 32px; padding: 2px 10px; }
70 #banner { grid-area: banner; display: none; }
71 #banner.stop { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 8px calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l)); background: #8e1519; color: #fff; font-size: 14px; font-weight: 600; }
72 #banner button { flex: none; min-height: var(--tap); padding: 0 14px; }
6673 .pane { flex: 1; min-width: 0; position: relative; background: #000; display: none; }
6774 .pane.on { display: block; }
6875 .pane img { width: 100%; height: 100%; object-fit: contain; display: block; }
@@ -72,23 +79,30 @@
7279 #top > * { pointer-events: auto; }
7380 #top button { background: rgba(0,0,0,.6); border-color: rgba(255,255,255,.18); color: #e8eaed; min-height: 36px; padding: 0 10px; border-radius: 8px; font-size: 13px; }
7481 #top .seg { display: inline-flex; flex-wrap: wrap; gap: 2px; } #top .seg button { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } #top .seg button.on { background: #388bfd; border-color: #388bfd; color: #fff; }
75 #top .info { display: inline-flex; gap: 6px; align-items: center; background: rgba(0,0,0,.6); padding: 0 10px; min-height: 36px; border-radius: 8px; max-width: 100%; }
76 #link { color: #9aa4ae; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: min(36ch, 46vw); } #link.on { color: #3fb950; } #link.warn { color: #d29922; } #link.bad { color: #f85149; font-weight: 700; }
82 #armLine { display: flex; gap: 6px; align-items: center; min-width: 0; color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; }
83 #armLine > * { flex: none; } #armLine #link { flex: 0 1 auto; }
84 #link { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #link.on { color: var(--ok); } #link.warn { color: var(--warn); } #link.bad { color: var(--bad); font-weight: 700; }
7785 .dot { width: 8px; height: 8px; border-radius: 50%; background: #f85149; display: inline-block; flex: none; } .dot.on { background: #3fb950; } .dot.warn { background: #d29922; }
78 #banner { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); z-index: 5; width: max-content; max-width: min(640px, calc(100% - 16px)); padding: 8px 12px; border-radius: 8px; font-size: 13px; background: rgba(0,0,0,.8); border: 1px solid #30363d; display: none; }
79 #banner.bad { display: block; border-color: #f85149; color: #ffb3ad; } #banner.warn { display: block; border-color: #d29922; color: #f2cc60; }
80 #msg { position: absolute; left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); bottom: 8px; z-index: 6; margin: 0 auto; width: max-content; max-width: calc(100% - 16px); padding: 8px 12px; border-radius: 8px; font-size: 13px; background: rgba(13,17,23,.9); color: #e8eaed; border: 1px solid #30363d; }
81 #msg:empty { display: none; } #msg.bad { border-color: #f85149; color: #ffb3ad; }
86 /* for a screen reader only: every note is also said aloud as it comes */
87 .sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
88 /* the notes pill: warnings and messages, counted in the strip, read in a sheet */
89 #notes { flex: none; min-width: var(--tap); padding: 0 12px; border-radius: 22px; font-size: 13px; font-weight: 650; white-space: nowrap; }
90 #notes.warn { border-color: var(--warn); color: var(--warn); } #notes.bad { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
91 @media (prefers-reduced-motion: no-preference) { #notes.new { animation: pulse .5s ease-in-out 3; } }
92 #notesList { display: grid; gap: 8px; margin: 8px 0; max-height: 50vh; overflow: auto; overflow-wrap: anywhere; }
93 #notesList p { margin: 0; padding: 8px 10px; border-radius: 8px; border-left: 3px solid var(--blue); background: var(--blue-soft); color: var(--fg); font-size: 14px; }
94 #notesList p.warn { border-color: var(--warn); } #notesList p.bad { border-color: var(--bad); background: var(--bad-soft); }
95 #notesList small { display: block; color: var(--dim); font-size: 12px; }
8296
83 /* the status strip: who drives, your place, time left, the turn's action and the E-stop */
84 #strip { grid-area: strip; display: flex; align-items: center; gap: 10px; padding: 8px calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l)); background: var(--surface); border-bottom: 1px solid var(--line); min-height: 64px; }
97 /* the status strip: who drives, your place, time left, the arm's link, the turn's action, the notes and the one STOP */
98 #strip { grid-area: strip; display: flex; align-items: center; gap: 8px; padding: 4px calc(12px + var(--safe-r)) 4px calc(12px + var(--safe-l)); background: var(--surface); border-bottom: 1px solid var(--line); min-height: 64px; }
8599 #strip .who { flex: 1; min-width: 0; }
86100 #driverLine { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #driverLine.none { color: var(--dim); font-weight: 500; }
87101 #clock { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #clock.idle { color: var(--warn); }
88 #capLine { color: var(--dim); font-size: 12px; } #capLine:empty { display: none; }
89102 #driverLine.paused { color: var(--warn); }
90103 #turnActions { display: flex; gap: 6px; } #turnActions:empty { display: none; }
91 .estop { flex: none; min-width: 72px; min-height: 52px; border: 0; border-radius: 12px; background: #d1242f; color: #fff; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; box-shadow: 0 0 0 3px rgba(209,36,47,.25), 0 2px 8px rgba(0,0,0,.35); }
104 @media (max-width: 640px) { #turnActions .extra { display: none; } }
105 .estop { flex: none; min-width: 72px; min-height: 56px; border: 0; border-radius: 12px; background: #d1242f; color: #fff; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; box-shadow: 0 0 0 3px rgba(209,36,47,.25), 0 2px 8px rgba(0,0,0,.35); }
92106 .estop:hover { background: #e5323d; } .estop:active { transform: scale(.97); }
93107 #sheetToggle { flex: none; }
94108 /* the turn ring: time left as a sweep around the seconds; the driver's name over the video for everyone */
@@ -102,7 +116,10 @@
102116
103117 /* the sheet: one panel at a time, the tabs under the thumb */
104118 #sheet { grid-area: sheet; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
105 .tab { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 12px calc(12px + var(--safe-r)) 16px calc(12px + var(--safe-l)); display: flex; flex-direction: column; gap: 12px; }
119 /* Under the model on a phone the open tab is a tray of one fixed height, so nothing shifts as it fills; tapping
120 the open tab again folds it away and the model takes the room. */
121 #shell.shut .tab { display: none; }
122 .tab { flex: none; height: var(--tray); min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 12px calc(12px + var(--safe-r)) 16px calc(12px + var(--safe-l)); display: flex; flex-direction: column; gap: 12px; }
106123 .tab h2 { margin: 4px 0 0; font-size: 13px; font-weight: 650; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
107124 .tab p.note { margin: 0; color: var(--dim); font-size: 13px; }
108125 /* teleop: a switch beside the leader, and while it drives, each joint's leader (ring) and follower (dot) on one track */
@@ -124,7 +141,6 @@
124141 #tabs .badge { display: inline-block; min-width: 18px; margin-left: 4px; padding: 0 5px; border-radius: 9px; background: var(--blue); color: var(--on-blue); font-size: 11px; line-height: 18px; }
125142 #tabs .badge:empty { display: none; }
126143
127 #notice { flex: none; padding: 10px calc(12px + var(--safe-r)) 10px calc(12px + var(--safe-l)); border-bottom: 1px solid var(--line); border-left: 3px solid var(--blue); background: var(--blue-soft); font-size: 14px; overflow-wrap: anywhere; }
128144
129145 /* chat */
130146 #tab-chat { padding: 0; gap: 0; }
@@ -149,14 +165,6 @@
149165 #forgeSignin { color: var(--link); font-size: 13px; align-self: flex-start; }
150166
151167 /* controls */
152 #reach { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; }
153 #pad { position: relative; width: min(46vw, 180px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, var(--btn) 0 58%, var(--raised) 59%); border: 1px solid var(--line); touch-action: none; -webkit-user-select: none; user-select: none; }
154 #pad::before, #pad::after { content: ""; position: absolute; background: var(--line); left: 50%; top: 12%; bottom: 12%; width: 1px; } #pad::after { left: 12%; right: 12%; top: 50%; bottom: auto; width: auto; height: 1px; }
155 #knob { position: absolute; left: 50%; top: 50%; width: 38%; aspect-ratio: 1; margin: -19% 0 0 -19%; border-radius: 50%; background: var(--blue); box-shadow: 0 2px 8px rgba(0,0,0,.35); transition: transform .12s ease-out; pointer-events: none; z-index: 1; }
156 #pad.held #knob { transition: none; }
157 #reach .side { display: grid; gap: 8px; }
158 #reach .side button { width: 100%; touch-action: none; -webkit-user-select: none; user-select: none; }
159 #reach .hint { grid-column: 1 / -1; margin: 0; color: var(--dim); font-size: 12px; }
160168 #joints { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 6px 14px; }
161169 .j { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name val" "slide slide"; align-items: center; column-gap: 6px; padding: 4px 6px; border-radius: 10px; }
162170 .j.jam { background: var(--bad-soft); } .j.drag { background: var(--blue-soft); }
@@ -169,40 +177,6 @@
169177 .pose { display: inline-flex; gap: 4px; align-items: center; }
170178 #readout { color: var(--dim); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; } #readout b { color: var(--fg); font-weight: 550; }
171179
172 /* touch driving (src/ui/drive.js): on a phone held upright, pick a joint and push one big lever; let go and it stops */
173 #touch { display: none; gap: 10px; }
174 #chips { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
175 #chips button { min-height: 50px; padding: 0 2px; border-radius: 10px; display: grid; place-content: center; gap: 1px; line-height: 1.1; }
176 #chips button b { font-size: 15px; } #chips button small { font-size: 10.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
177 #chips button[aria-checked=true] { background: var(--blue); border-color: var(--blue); color: var(--on-blue); } #chips button[aria-checked=true] small { color: inherit; opacity: .85; }
178 #one { display: grid; grid-template-columns: minmax(0, 1fr) 84px minmax(0, 1fr); gap: 12px; height: clamp(210px, 36svh, 360px); }
179 #one .nudges { display: grid; grid-template-rows: 1fr 1fr; gap: 10px; }
180 #one .nudges button { display: grid; place-content: center; gap: 2px; font-size: 22px; line-height: 1; touch-action: none; -webkit-user-select: none; user-select: none; }
181 #one .nudges small { font-size: 12px; color: var(--dim); }
182 #lever { position: relative; border-radius: 42px; background: var(--btn); border: 1px solid var(--line); touch-action: none; -webkit-user-select: none; user-select: none; overflow: hidden; cursor: ns-resize; }
183 #lever::before { content: ""; position: absolute; left: 16px; right: 16px; top: 50%; height: 2px; margin-top: -1px; background: var(--line); }
184 #leverAt { position: absolute; left: 0; bottom: 0; width: 5px; height: 100%; background: var(--ok); transform-origin: bottom; transform: scaleY(var(--at, .5)); }
185 #leverKnob { position: absolute; left: 7px; right: 7px; top: 50%; height: 68px; margin-top: -34px; border-radius: 34px; background: var(--blue); color: var(--on-blue); display: grid; place-content: center; font-size: 22px; box-shadow: 0 2px 10px rgba(0,0,0,.3); transition: transform .14s ease-out; pointer-events: none; }
186 #lever.held { border-color: var(--blue); background: var(--blue-soft); } #lever.held #leverKnob { transition: none; }
187 #lever.end, .stick.end { box-shadow: 0 0 0 3px var(--warn); }
188 #one .about { display: grid; align-content: center; gap: 4px; min-width: 0; }
189 #oneName { font-size: 20px; font-weight: 700; } #onePos { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; }
190 #oneHint { color: var(--dim); font-size: 12px; }
191 #lag { color: #f2cc60; font-variant-numeric: tabular-nums; }
192 #chat .earlier { display: block; margin: 2px auto 8px; font-size: 13px; }
193 /* on a phone on its side: two thumb sticks over the picture, the gripper between them */
194 #sticks { display: none; position: absolute; inset: 0; z-index: 6; pointer-events: none; --stick: min(40vh, 164px); }
195 #sticks > * { pointer-events: auto; }
196 .stick { position: absolute; bottom: calc(14px + var(--safe-b)); width: var(--stick); height: var(--stick); border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.08) 0 54%, rgba(255,255,255,.03) 55%); border: 1px solid rgba(255,255,255,.24); touch-action: none; -webkit-user-select: none; user-select: none; }
197 #stickL { left: calc(18px + var(--safe-l)); } #stickR { right: calc(var(--pill) + var(--safe-r)); }
198 .stick .knob { position: absolute; left: 50%; top: 50%; width: 42%; height: 42%; margin: -21% 0 0 -21%; border-radius: 50%; background: rgba(56,139,253,.8); box-shadow: 0 2px 10px rgba(0,0,0,.45); transition: transform .14s ease-out; pointer-events: none; }
199 .stick.held { border-color: #388bfd; } .stick.held .knob { background: #388bfd; transition: none; }
200 .stick .cap { position: absolute; left: -20px; right: -20px; bottom: 100%; margin-bottom: 4px; text-align: center; font-size: 11px; color: #e8eaed; text-shadow: 0 1px 2px #000; pointer-events: none; white-space: nowrap; }
201 #sticks button { background: rgba(0,0,0,.55); border-color: rgba(255,255,255,.24); color: #e8eaed; touch-action: none; -webkit-user-select: none; user-select: none; }
202 #sticks button.held { background: #388bfd; border-color: #388bfd; }
203 #swap { position: absolute; right: calc(var(--pill) + var(--safe-r)); bottom: calc(var(--stick) + 40px + var(--safe-b)); min-height: 40px; font-size: 13px; }
204 #grips { position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%); display: flex; gap: 10px; }
205 #grips button { min-width: 80px; min-height: 72px; font-weight: 650; }
206180
207181 /* admin */
208182 .card { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--raised); }
@@ -257,75 +231,74 @@
257231 #lcFlips small { color: var(--dim); font-variant-numeric: tabular-nums; }
258232 #lcErr { color: var(--bad); } #lcErr:empty { display: none; }
259233
260 /* A wide screen: the sheet is a column beside the view. */
234 /* A wide screen: camera, model and the sheet side by side; either view can be put away. */
261235 @media (orientation: landscape) and (min-width: 900px) and (min-height: 501px) {
262 #shell { --view: 1fr; grid-template-columns: minmax(0, 1fr) min(400px, 36vw); grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "view sheet" "strip sheet"; }
263 #shell.typing { --view: 1fr; }
236 #shell { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) min(400px, 36vw); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "banner banner sheet" "view model sheet" "strip strip sheet"; }
237 #shell.no3d, #shell.nocam { grid-template-columns: minmax(0, 1fr) min(400px, 36vw); grid-template-areas: "banner sheet" "view sheet" "strip sheet"; }
238 #shell.nocam { grid-template-areas: "banner sheet" "model sheet" "strip sheet"; }
239 #app, #shell.typing #app { aspect-ratio: auto; height: auto; }
264240 #sheet { border-left: 1px solid var(--line); }
265241 #strip { border-bottom: 0; border-top: 1px solid var(--line); }
242 .tab, #shell.shut .tab { flex: 1; height: auto; display: flex; }
266243 }
267 /* A phone on its side: the view fills the screen, the controls float over it. */
244 /* A phone on its side: the strip with the STOP across the top, the camera and the model side by side under it, and
245 the sheet a third column only while it is shown. */
268246 @media (orientation: landscape) and (max-height: 500px) {
269 #shell, #shell.typing { grid-template-columns: 100%; grid-template-rows: 100%; grid-template-areas: "view"; }
270 #app, #strip, #sheet { grid-area: auto; }
271 #strip { position: absolute; z-index: 7; top: 6px; left: calc(6px + var(--safe-l)); max-width: calc(100% - min(380px, 48vw) - 18px - var(--safe-l) - var(--safe-r)); min-height: 0; padding: 6px 6px 6px 12px; border: 1px solid rgba(255,255,255,.12); border-radius: 14px; background: rgba(13,17,23,.82); color: #e8eaed; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
272 #shell.bare #strip { max-width: calc(100% - 12px - var(--safe-l) - var(--safe-r)); }
273 #strip #clock { color: #9aa4ae; }
274 #sheetToggle { display: inline-flex !important; align-items: center; background: rgba(255,255,255,.08); color: #e8eaed; border-color: rgba(255,255,255,.18); }
275 #sheet { position: absolute; z-index: 7; top: 0; bottom: 0; right: 0; width: calc(min(380px, 48vw) + var(--safe-r)); background: rgba(13,17,23,.9); background: color-mix(in srgb, var(--surface) 90%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-left: 1px solid var(--line); transition: transform .2s ease-out; }
276 #shell.bare #sheet { transform: translateX(100%); visibility: hidden; transition: transform .2s ease-out, visibility 0s .2s; }
277 #top { top: auto; bottom: 6px; justify-content: flex-start; right: calc(min(380px, 48vw) + 12px + var(--safe-r)); }
278 #shell.bare #top { right: calc(var(--pill) + var(--safe-r)); }
279 #banner { top: 64px; }
280 #msg { bottom: 52px; }
281 .tab { padding-top: 8px; }
282 #pad { width: min(30vh, 150px); }
247 #shell, #shell.typing { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) min(340px, 40vw); grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "strip strip strip" "banner banner banner" "view model sheet"; }
248 #shell.nocam { grid-template-areas: "strip strip strip" "banner banner banner" "model model sheet"; }
249 #shell.bare { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "strip strip" "banner banner" "view model"; }
250 #shell.bare.nocam { grid-template-areas: "strip strip" "banner banner" "model model"; }
251 #shell.bare #sheet { display: none; }
252 #app, #shell.typing #app { aspect-ratio: auto; height: auto; }
253 #strip { min-height: 60px; padding-top: calc(2px + env(safe-area-inset-top, 0px)); padding-bottom: 2px; }
254 #sheetToggle { display: inline-flex !important; align-items: center; }
255 #sheet { border-left: 1px solid var(--line); }
256 #tabs button { font-size: 13px; }
257 .tab, #shell.shut .tab { flex: 1; height: auto; display: flex; padding-top: 8px; }
258 #shell.bare #modelBox .tag { right: calc(var(--pill) + var(--safe-r)); }
283259 }
284 @media (max-width: 640px) and (orientation: portrait) { #touch { display: grid; } #reach, #joints { display: none !important; } }
285 /* One STOP in every layout; it holds until Resume. */
286 @media (orientation: landscape) and (max-height: 500px) {
287 #shell.driving.bare #sticks { display: block; }
288 #shell.driving.bare #top { top: 6px; bottom: auto; left: auto; right: calc(6px + var(--safe-r)); max-width: 42%; justify-content: flex-end; }
289 #shell.driving.bare #strip { max-width: calc(58% - 18px - var(--safe-l)); }
290 #shell.driving.bare #msg { bottom: auto; top: 110px; }
260 /* The joints on a phone: every one at once, one compact row each (name, slider, value); a vertical swipe scrolls the tray. */
261 @media (max-width: 640px), (max-height: 500px) {
262 #joints { grid-template-columns: 100%; gap: 0; }
263 .j { grid-template-columns: 58px minmax(0, 1fr) 46px; grid-template-areas: "name slide val"; padding: 0 2px; }
264 .j .v { justify-content: flex-end; } .j small, .j .jog { display: none; }
265 .j input[type=range] { height: 36px; touch-action: pan-y; }
266 .tab#tab-controls { gap: 6px; padding-top: 6px; }
267 #top #fs { display: none; }
291268 }
292 @media (max-width: 420px) { #top .label { display: none; } #link { max-width: 30vw; } }
269 /* The model is put away only on a wide screen; anywhere smaller it is the main control and always there. */
270 @media not all and (orientation: landscape) and (min-width: 900px) and (min-height: 501px) { #v3 { display: none; } }
293271 @media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
294272 </style>
295273 </head>
296274 <body>
297275 <div id="shell">
298276 <div id="app">
299 <div id="stage">
300 <div class="pane" id="pane3" data-key="pane3"><urdf-viewer id="model" up="Z" ignore-limits display-shadow ambient-color="#b9c0c8"></urdf-viewer><span class="tag" id="tag3">3D · drag a joint to move it · drag around it to orbit</span></div>
301 </div>
277 <div id="stage"></div>
302278 <div id="top">
303279 <span class="seg" role="group" aria-label="Views"><button id="v3" aria-pressed="false">3D</button></span>
304 <span class="info"><span id="link" hidden></span><span id="live" class="label"></span><span class="dot" id="dot"></span><span id="state">…</span><span id="lag" hidden></span></span>
305280 <button id="quality" type="button" hidden title="Video quality: Auto follows the connection, Saver sends 2 frames a second, Full every frame">Auto</button>
306281 <button id="fs" title="F">Fullscreen</button>
307282 </div>
308283 <div id="driverTag" aria-hidden="true"></div>
309 <div id="banner" role="alert"></div>
310 <div id="msg" role="status"></div>
311 <div id="sticks" role="group" aria-label="Thumb sticks">
312 <div class="stick" id="stickL" role="group" aria-label="Left stick: sideways turns the base, up and down lifts the shoulder"><span class="cap">J1 base ↔ · J2 shoulder ↕</span><span class="knob"></span></div>
313 <div class="stick" id="stickR" role="group" aria-label="Right stick"><span class="cap" id="capR"></span><span class="knob"></span></div>
314 <button id="swap" type="button" aria-pressed="false">Wrist</button>
315 <div id="grips" role="group" aria-label="Gripper"><button id="gripOpen" type="button">Open</button><button id="gripClose" type="button">Close</button></div>
316 </div>
317284 </div>
318285
319 <section id="strip" aria-label="Who drives" aria-live="polite">
286 <section id="strip" aria-label="Who drives">
320287 <div id="ring" hidden aria-hidden="true"><span id="ringN"></span></div>
321 <div class="who"><div id="driverLine" class="none">Connecting…</div><div id="clock" aria-live="off"></div><div id="capLine"></div></div>
288 <div class="who" aria-live="polite"><div id="driverLine" class="none">Connecting…</div><div id="clock" aria-live="off"></div><div id="armLine"><span class="dot" id="dot"></span><span id="state">…</span><span id="link" hidden></span><span id="live"></span><span id="lag" hidden></span></div></div>
322289 <div id="turnActions"></div>
323290 <button id="sheetToggle" hidden aria-controls="sheet" aria-expanded="true">Hide</button>
291 <button id="notes" type="button" hidden aria-haspopup="dialog" aria-controls="notesDlg"></button>
324292 <button id="stop" class="estop" data-stop title="Stop (space or Esc): halt everything, hold with torque, until someone resumes" aria-label="Stop the arm">Stop</button>
325293 </section>
294 <div id="banner" role="alert"></div>
295 <div id="msg" class="sr" role="status"></div>
296
297 <div id="modelBox">
298 <div class="pane" id="pane3" data-key="pane3"><urdf-viewer id="model" up="Z" ignore-limits display-shadow ambient-color="#b9c0c8"></urdf-viewer><span class="tag" id="tag3">3D · drag a part to move its joint · two fingers turn the view</span></div>
299 </div>
326300
327301 <section id="sheet" aria-label="Chat, queue and controls">
328 <div id="notice" role="status" hidden></div>
329302 <div class="tab" id="tab-chat" role="tabpanel" aria-labelledby="t-chat">
330303 <div id="chat" role="log" aria-label="Chat"></div>
331304 <form id="say" hidden><input id="sayText" type="text" maxlength="500" autocomplete="off" enterkeyhint="send" placeholder="Say something" aria-label="Message"><button class="go">Send</button></form>
@@ -340,31 +313,13 @@
340313 <a id="forgeSignin" hidden>Have a forge account? Sign in instead</a>
341314 <h2>Waiting</h2>
342315 <ol id="queue" aria-label="Queue"></ol>
343 <p class="note">A turn lasts a few minutes and ends early when the arm sits idle. When yours comes, the Controls tab appears.</p>
316 <p class="note">A turn lasts a few minutes and ends early when the arm sits idle. When yours comes, the Drive tab opens: drag the 3D model, or a joint's slider.</p>
344317 <h2>Leader arm</h2>
345318 <div class="row"><button id="leaderBtn" title="read a leader arm plugged into this computer or phone (Chrome, Edge)">Connect leader arm</button><label class="switch" id="teleopRow" hidden title="on your turn, the arm follows the leader live"><input type="checkbox" role="switch" id="teleop"> Teleop</label><button id="leaderCal" hidden title="teach this page your own leader arm: once, kept with your name">Calibrate leader</button></div>
346319 <p class="lag" id="teleopLag" hidden></p>
347320 <p class="note">Plug an SO-101 leader into this computer or Android phone. The 3D model mirrors it while you wait; switch Teleop on and, on your turn, the arm follows it live. Hiding this tab or unplugging the leader stops the arm where it is.</p>
348321 </div>
349322 <div class="tab" id="tab-controls" role="tabpanel" aria-labelledby="t-controls" hidden>
350 <section id="touch" aria-label="Drive one joint">
351 <div id="chips" role="radiogroup" aria-label="Joint"></div>
352 <div id="one">
353 <div class="nudges"><button type="button" data-nudge="1" id="nudgeUp">▲<small></small></button><button type="button" data-nudge="-1" id="nudgeDown">▼<small></small></button></div>
354 <div id="lever" role="slider" tabindex="0" aria-orientation="vertical" aria-valuemin="-100" aria-valuemax="100" aria-valuenow="0"><span id="leverAt"></span><span id="leverKnob" aria-hidden="true">⇕</span></div>
355 <div class="about"><span id="oneName"></span><span id="onePos">—</span><span id="oneHint">Push the lever: further is faster. Let go and it stops.</span></div>
356 </div>
357 </section>
358 <div id="reach" hidden>
359 <div id="pad" role="application" aria-label="Move the gripper: up reaches out, down pulls in, sideways swings around the base"><span id="knob"></span></div>
360 <div class="side">
361 <button data-lift="1" aria-label="Gripper up">▲ Up</button>
362 <button data-lift="-1" aria-label="Gripper down">▼ Down</button>
363 <button data-grip="1">Open</button>
364 <button data-grip="-1">Close</button>
365 </div>
366 <p class="hint">Hold the pad to move the gripper: up reaches out, sideways swings around the base. The jog speed sets how fast.</p>
367 </div>
368323 <p id="why" role="status"></p>
369324 <div id="joints"></div>
370325 <div class="row" id="poses"></div>
@@ -447,9 +402,9 @@
447402 <p class="note">The arm as its servos report it, and every command on its way in and out, pushed as it happens. Read-only.</p>
448403 </div>
449404 <nav id="tabs" role="tablist" aria-label="Sheet">
450 <button role="tab" id="t-chat" data-tab="chat" aria-controls="tab-chat" aria-selected="true">Chat<span class="badge" id="unread"></span></button>
405 <button role="tab" id="t-controls" data-tab="controls" aria-controls="tab-controls" aria-selected="false" hidden>Drive</button>
451406 <button role="tab" id="t-queue" data-tab="queue" aria-controls="tab-queue" aria-selected="false">Queue<span class="badge" id="waiting"></span></button>
452 <button role="tab" id="t-controls" data-tab="controls" aria-controls="tab-controls" aria-selected="false" hidden>Controls</button>
407 <button role="tab" id="t-chat" data-tab="chat" aria-controls="tab-chat" aria-selected="true">Chat<span class="badge" id="unread"></span></button>
453408 <button role="tab" id="t-admin" data-tab="admin" aria-controls="tab-admin" aria-selected="false" hidden>Admin</button>
454409 <button role="tab" id="t-machine" data-tab="machine" aria-controls="tab-machine" aria-selected="false">Machine</button>
455410 </nav>
@@ -505,6 +460,13 @@
505460 <div class="list" id="recList"></div>
506461 <div class="actions"><label class="inline">rate <select id="playRate"><option value="0.5">0.5×</option><option value="1" selected>1×</option><option value="1.5">1.5×</option></select></label><button id="playClose">Close</button></div>
507462 </dialog>
463 <dialog id="notesDlg" aria-labelledby="notesTitle">
464 <form method="dialog">
465 <h3 id="notesTitle">Notes</h3>
466 <div id="notesList"></div>
467 <div class="actions two"><button value="clear" id="notesClear">Clear messages</button><button value="ok" class="go">Close</button></div>
468 </form>
469 </dialog>
508470 <dialog id="modDlg">
509471 <form method="dialog">
510472 <h3 id="modTitle">Message</h3>
@@ -515,16 +477,35 @@
515477 </div>
516478 <script type="module">
517479 import { cameraPlan, QUALITIES, samePlan } from "/ui/__VERSION__/camera-plan.js";
518 import { bindSurface, canDrive, Driver, shape, UP } from "/ui/__VERSION__/drive.js";
519480 import { Frames } from "/ui/__VERSION__/frames.js";
481 import { Notes, pill } from "/ui/__VERSION__/notes.js";
520482
521483 const $ = (id) => document.getElementById(id);
522484 const q = new URLSearchParams(location.search);
523 let msgTimer = null;
485 // ---------------------------------------------------------------- notes: nothing is drawn over the camera or the model
486 // What the arm, the link and the room say (a zone warning, reconnecting, the speed cap, the announcement) and the page's
487 // own messages are counted in one pill in the strip; a tap opens them in a sheet. A screen reader hears each as it comes.
488 const notes = new Notes();
489 function renderNotes() {
490 const all = notes.list(Date.now()), look = pill(all), button = $("notes");
491 button.hidden = look.hidden; button.className = look.level === "info" ? "" : look.level;
492 button.textContent = look.text; button.setAttribute("aria-label", `${look.text}: open`);
493 if ($("notesDlg").open) $("notesList").replaceChildren(...(all.length ? all.map((n) => el("p", { className: n.level },
494 ...(n.at ? [el("small", { textContent: new Date(n.at).toLocaleTimeString() })] : []), n.text)) : [el("p", { textContent: "Nothing to note." })]));
495 }
496 /** A standing note, there while its condition holds: null clears it. */
497 const note = (key, text, level) => { if (notes.set(key, text, level)) renderNotes(); };
498 let pulse = null;
524499 const msg = (text, bad = false) => {
525 $("msg").textContent = text; $("msg").className = bad ? "bad" : "";
526 clearTimeout(msgTimer); if (text) msgTimer = setTimeout(() => ($("msg").textContent = ""), bad ? 9000 : 5000);
500 if (!text) return;
501 $("msg").textContent = text;
502 notes.say(text, bad ? "bad" : "info", Date.now());
503 renderNotes();
504 $("notes").classList.add("new"); clearTimeout(pulse); pulse = setTimeout(() => $("notes").classList.remove("new"), 1600);
527505 };
506 setInterval(renderNotes, 10000); // a message goes from the count a minute after it came
507 $("notes").onclick = () => { $("notesDlg").showModal(); renderNotes(); };
508 $("notesDlg").addEventListener("close", () => { if ($("notesDlg").returnValue === "clear") { notes.clear(); renderNotes(); } });
528509 const api = async (path, body, method = body === undefined ? "GET" : "POST") => {
529510 const r = await fetch(path, { method, body: body === undefined ? undefined : JSON.stringify(body), cache: "no-store" });
530511 const data = await r.json().catch(() => ({}));
@@ -534,6 +515,8 @@
534515 const NAMES = { 1: "shoulder_pan", 2: "shoulder_lift", 3: "elbow_flex", 4: "wrist_flex", 5: "wrist_roll", 6: "gripper" };
535516 const IDS = Object.fromEntries(Object.entries(NAMES).map(([id, n]) => [n, Number(id)]));
536517 const narrow = matchMedia("(max-width: 760px), (max-height: 500px)");
518 /** The one layout where the 3D model can be put away; everywhere else it is the main control and always shown. */
519 const wide = matchMedia("(orientation: landscape) and (min-width: 900px) and (min-height: 501px)");
537520
538521 // ---------------------------------------------------------------- the screen: the keyboard, the sheet, the tabs
539522 // The shell follows the visual viewport, so the on-screen keyboard shrinks the sheet instead of covering the chat.
@@ -553,6 +536,7 @@
553536 function showTab(name, focus = false) {
554537 if ($(`t-${name}`).hidden) name = ["controls", "chat", "admin"].find((t) => !$(`t-${t}`).hidden) ?? "chat";
555538 tab = name;
539 shell.classList.remove("shut");
556540 for (const b of $("tabs").querySelectorAll("[role=tab]")) {
557541 const on = b.dataset.tab === name;
558542 b.setAttribute("aria-selected", String(on)); b.tabIndex = on ? 0 : -1;
@@ -564,7 +548,7 @@
564548 if (name === "admin") loadSettings();
565549 if (name === "machine") machineOpen(); else machineClose();
566550 }
567 for (const b of $("tabs").querySelectorAll("[role=tab]")) b.onclick = () => showTab(b.dataset.tab);
551 for (const b of $("tabs").querySelectorAll("[role=tab]")) b.onclick = () => (b.dataset.tab === tab && !shell.classList.contains("shut") ? shell.classList.add("shut") : showTab(b.dataset.tab));
568552 $("tabs").addEventListener("keydown", (e) => {
569553 if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
570554 const shown = [...$("tabs").querySelectorAll("[role=tab]:not([hidden])")];
@@ -592,6 +576,7 @@
592576 : l.mode === "offline" ? `OFFLINE · simulated arm · ${l.problem}` : l.problem ? `Simulated · ${l.problem}` : "Simulated";
593577 el.title = el.textContent;
594578 el.className = l.mode === "live" ? "on" : l.mode === "offline" ? "bad" : l.mode === "reconnecting" || l.problem ? "warn" : "";
579 note("link", l.mode === "live" || (l.mode === "simulated" && !l.problem) ? null : el.textContent, l.mode === "offline" ? "bad" : "warn");
595580 // Another arm has other limits, poses and joints: start the page over on it, once nothing on the page is driving.
596581 // So does a page that opened while reconnecting and never got the arm's limits.
597582 const other = linkMode !== null && realArm(l.mode) !== realArm(linkMode);
@@ -642,8 +627,11 @@
642627 } catch { c.live = false; }
643628 if (plan.mode === "snapshot") c.timer = setTimeout(() => snap(c), Math.max(0, plan.everyMs - (performance.now() - started)));
644629 }
630 /** The shell's columns follow what is on: no camera on, the model takes its room; no model (a wide screen only), the camera. */
631 const syncViews = () => { shell.classList.toggle("nocam", !cams.some(paneOn)); shell.classList.toggle("no3d", !$("pane3").classList.contains("on")); };
645632 const showCam = (c, on) => {
646633 c.pane.classList.toggle("on", on); c.btn.classList.toggle("on", on); c.btn.setAttribute("aria-pressed", String(on));
634 syncViews();
647635 clearTimeout(c.timer);
648636 if (!on || document.hidden) c.img.src = "";
649637 else if (plan.mode === "snapshot" && c.snapshot) snap(c);
@@ -652,27 +640,31 @@
652640 function setPane(key, on) {
653641 if (key === "pane3") {
654642 $("pane3").classList.toggle("on", on); $("v3").classList.toggle("on", on); $("v3").setAttribute("aria-pressed", String(on));
643 syncViews();
655644 if (on) load3D();
656645 } else { const c = cams.find((x) => x.pane.dataset.key === key); if (c) showCam(c, on); }
657646 }
658 /** A view button: on or off; a phone shows one view at a time, so picking one there puts the other away. */
647 /** A view button: on or off. The model stays on below a wide screen; a phone shows one camera at a time, so picking one there puts the other away. */
659648 function pick(key) {
660649 const pane = key === "pane3" ? $("pane3") : cams.find((x) => x.pane.dataset.key === key)?.pane;
661650 if (!pane) return;
662651 const on = !pane.classList.contains("on");
652 if (key === "pane3" && !on && !wide.matches) return;
653 if (key !== "pane3" && !on && !wide.matches && cams.filter(paneOn).length === 1) return; // its button is on the camera: put away, nothing would bring it back
663654 if (!on && shown() === 1) return; // keep one pane
664 if (on && narrow.matches) for (const other of document.querySelectorAll(".pane.on")) setPane(other.dataset.key, false);
655 if (on && narrow.matches && key !== "pane3") for (const other of cams) if (paneOn(other)) showCam(other, false);
665656 setPane(key, on);
666657 keep(); viewer.recenter?.();
667658 }
668 /** Whether a view is on when it first appears: the viewer's last choice, else the camera when there is a real one, and the model beside it on a wide screen. */
659 /** Whether a view is on when it first appears: the model always below a wide screen, else the viewer's last choice; the camera when there is a real one. */
669660 function wanted(key) {
670 if (narrow.matches && shown() >= 1) return false;
671 if (key === "pane3" && !modelInfo?.ok) return false;
672 if (chosen) return chosen.has(key);
673 if (key === "pane3") return !narrow.matches || !cameraFirst || !cams.length;
674 return cameraFirst && key === cams[0]?.pane.dataset.key;
661 if (key === "pane3") return Boolean(modelInfo?.ok) && (!wide.matches || !chosen || chosen.has(key) || !cams.length);
662 if (narrow.matches && cams.some(paneOn)) return false;
663 if (chosen?.size && [...chosen].some((k) => cams.some((c) => c.pane.dataset.key === k))) return chosen.has(key);
664 return (cameraFirst || !wide.matches) && key === cams[0]?.pane.dataset.key; // below a wide screen there is room for both
675665 }
666 // Off a wide screen the model comes back: it is the main control there.
667 wide.addEventListener("change", () => { if (!wide.matches && viewsReady && modelInfo?.ok) setPane("pane3", true); });
676668 /** At least one view on: the first camera, else the model. */
677669 function fallback() {
678670 if (shown() || !viewsReady) return;
@@ -689,7 +681,7 @@
689681 c.btn = el("button", { type: "button" }); c.btn.setAttribute("aria-pressed", "false");
690682 c.img.onerror = () => { if (paneOn(c) && plan.mode === "stream" && c.img.getAttribute("src")) setTimeout(() => { if (paneOn(c) && plan.mode === "stream" && !document.hidden) c.img.src = streamUrl(c); }, 3000); };
691683 c.btn.onclick = () => pick(c.pane.dataset.key);
692 $("stage").insertBefore(c.pane, $("pane3"));
684 $("stage").append(c.pane);
693685 $("top").querySelector(".seg").insertBefore(c.btn, $("v3"));
694686 cams.push(c);
695687 return c;
@@ -698,6 +690,7 @@
698690 clearTimeout(c.timer); c.img.src = ""; if (c.blob) URL.revokeObjectURL(c.blob);
699691 c.pane.remove(); c.btn.remove();
700692 cams.splice(cams.indexOf(c), 1);
693 syncViews();
701694 fallback();
702695 }
703696 function label(c, info) {
@@ -780,7 +773,7 @@
780773 $("v3").onclick = () => pick("pane3");
781774
782775 // ---------------------------------------------------------------- the stream: the page as a leader
783 // Opened while a slider, a jog button, the joystick or a model joint is held; frames go at most every 33 ms; closed shortly after letting go.
776 // Opened while a slider, a jog button or a model joint is held; frames go at most every 33 ms; closed shortly after letting go.
784777 // Stamped targets (src/ui/frames.js): while the socket opens only the newest waits, and goes only if still fresh.
785778 const stream = {
786779 ws: null, closeTimer: null, halted: false, waiting: null,
@@ -872,8 +865,6 @@
872865 // STOP: drop what this page would still send, then the server halts and holds the arm until Resume.
873866 async function stop() {
874867 stream.halt();
875 driver.releaseAll();
876 reachEnd();
877868 stopLeaderDrive("stopped");
878869 const r = await api("/stop", {});
879870 msg(r.ok ? `STOPPED${r.stopped ? ` ${r.stopped}` : ""}${r.saved ? `; saved recording ${r.saved}` : ""}: the arm holds until you resume` : r.error, true);
@@ -1206,20 +1197,23 @@
12061197 // ---------------------------------------------------------------- the 3D model
12071198 // three.js is most of what the page downloads, so it comes after the first view: the room and the camera work without it.
12081199 const viewer = $("model");
1209 let THREE = null, model3D = null, dragging = null, table = null, marker = null;
1200 let THREE = null, model3D = null, dragging = null, table = null, marker = null, ghost = null;
12101201 function load3D() {
12111202 if (!modelInfo?.ok) return Promise.resolve(false);
12121203 return (model3D ??= (async () => {
1213 const [three, { STLLoader }, { default: URDFManipulator }, reach] = await Promise.all([
1214 import("three"), import("three/examples/jsm/loaders/STLLoader.js"), import("urdf-loader/manipulator"), import("/ui/__VERSION__/reach.js"),
1204 const [three, { STLLoader }, { default: URDFManipulator }] = await Promise.all([
1205 import("three"), import("three/examples/jsm/loaders/STLLoader.js"), import("urdf-loader/manipulator"),
12151206 ]);
1216 THREE = three; reachMath = reach;
1207 THREE = three;
12171208 if (!customElements.get("urdf-viewer")) customElements.define("urdf-viewer", URDFManipulator);
12181209 viewer.loadMeshFunc = (path, manager, material, done) => {
12191210 new STLLoader(manager).load(path, (geometry) => done(new THREE.Mesh(geometry, material ?? new THREE.MeshPhongMaterial({ color: 0x9aa4ae, shininess: 30 }))), undefined, (err) => done(null, err));
12201211 };
12211212 const canvas = viewer.renderer.domElement;
12221213 canvas.style.touchAction = "none";
1214 // One finger is for the arm: on a part it turns that part's joint, on empty space it does nothing. Two fingers
1215 // turn the view and pinch zooms; neither sends a thing to the arm.
1216 viewer.controls.touches = { ONE: -1, TWO: THREE.TOUCH.DOLLY_ROTATE };
12231217 const asMouse = (type, t) => canvas.dispatchEvent(new MouseEvent(type, { clientX: t.clientX, clientY: t.clientY, bubbles: true }));
12241218 canvas.addEventListener("touchstart", (e) => { if (e.touches.length === 1) asMouse("mousedown", e.touches[0]); }, { passive: true });
12251219 canvas.addEventListener("touchmove", (e) => { if (e.touches.length === 1 && dragging) { e.preventDefault(); asMouse("mousemove", e.touches[0]); } }, { passive: false });
@@ -1244,8 +1238,28 @@
12441238 viewer.controls.target.set(0.08, 0.1, 0);
12451239 viewer.controls.update();
12461240 viewer.recenter();
1247 $("reach").hidden = !tipLink();
1241 makeGhost();
12481242 });
1243 viewer.addEventListener("urdf-change", () => { ghost?.removeFromParent(); ghost = null; });
1244 /**
1245 * The real arm, drawn faint behind the model: the model is where you asked the arm to be, the ghost where it is, so
1246 * the lag shows while you drag. A copy of the model's links that no pointer can pick, shown only while they differ.
1247 */
1248 function makeGhost() {
1249 const robot = viewer.robot;
1250 if (!robot || !THREE) return;
1251 ghost?.removeFromParent();
1252 const look = new THREE.MeshBasicMaterial({ color: 0x58a6ff, transparent: true, opacity: 0.25, depthWrite: false });
1253 ghost = robot.clone();
1254 ghost.traverse((o) => {
1255 o.raycast = () => {};
1256 if (o.isMesh) { o.material = look; o.castShadow = o.receiveShadow = false; }
1257 if (o.isURDFJoint) o.ignoreLimits = true;
1258 });
1259 ghost.visible = false;
1260 robot.parent.add(ghost);
1261 if (status) applyModel(status);
1262 }
12491263 viewer.addEventListener("manipulate-start", (e) => { dragging = e.detail; stream.open(); });
12501264 viewer.addEventListener("manipulate-end", () => { const id = IDS[dragging]; if (id) intent.release(id, performance.now()); dragging = null; stream.end(); });
12511265 viewer.addEventListener("angle-change", (e) => {
@@ -1256,14 +1270,19 @@
12561270 stream.send({ [id]: ticks });
12571271 });
12581272 function applyModel(d) {
1259 if (!viewer.robot || calib) return; // while calibrating, the model shows the pose to copy
1260 for (const j of leaderMirrored() ? [] : d.joints) {
1273 if (!viewer.robot) return;
1274 let ahead = false;
1275 for (const j of leaderMirrored() || calib ? [] : d.joints) { // calibrating, the model shows the pose to copy
12611276 const name = NAMES[j.id];
1262 if (!name || j.position == null || name === dragging || !limits[j.id]) continue;
1263 if (reachState.timer && j.id <= 3) continue; // the joystick is ahead of the arm; snapping back would make it stutter
1277 if (!name || j.position == null || !limits[j.id]) continue;
1278 ghost?.setJointValue(name, toRad(j.id, j.position));
1279 if (name === dragging) { ahead = true; continue; }
12641280 const want = intent.target(j.id, j.position, performance.now());
1281 if (want !== null && Math.abs(want - j.position) > 12) ahead = true;
12651282 viewer.setJointValue(name, toRad(j.id, want ?? j.position));
12661283 }
1284 if (ghost && ghost.visible !== ahead) { ghost.visible = ahead; viewer.redraw(); }
1285 else if (ahead) viewer.redraw();
12671286 if (marker) {
12681287 const v = d.blocked ?? d.violation;
12691288 marker.visible = Boolean(v);
@@ -1271,192 +1290,9 @@
12711290 }
12721291 }
12731292
1274 // ---------------------------------------------------------------- the joystick: move the gripper, not a joint
1275 // The pad's deflection becomes a displacement of the gripper (src/ui/reach.js), solved onto pan, lift and elbow.
1276 let reachMath = null;
1277 const REACH = [1, 2, 3];
1278 const SPEED = { 100: 0.02, 300: 0.05, 800: 0.1 }; // m/s at full deflection, by jog speed
1279 const reachState = { stick: { x: 0, y: 0, lift: 0 }, angles: null, timer: null, holders: 0 };
1280 const tipLink = () => viewer.robot?.links?.gripper_frame_link ?? viewer.robot?.links?.gripper_link ?? null;
1281 /** Where the gripper would be with pan, lift and elbow at `angles`, in the arm's base frame: the model is posed, read and put back. */
1282 function tipAt(angles) {
1283 const robot = viewer.robot, link = tipLink();
1284 const saved = REACH.map((id) => robot.joints[NAMES[id]].jointValue[0]);
1285 REACH.forEach((id, i) => robot.joints[NAMES[id]].setJointValue(angles[i]));
1286 robot.updateMatrixWorld(true);
1287 const p = robot.worldToLocal(link.getWorldPosition(new THREE.Vector3()));
1288 REACH.forEach((id, i) => robot.joints[NAMES[id]].setJointValue(saved[i]));
1289 robot.updateMatrixWorld(true);
1290 return [p.x, p.y, p.z];
1291 }
1292 function reachBegin() {
1293 if (reachState.timer) { reachState.holders++; return; }
1294 if (!viewer.robot || !reachMath || !tipLink()) return msg("the 3D model is still loading", true);
1295 const at = REACH.map((id) => status?.joints.find((j) => j.id === id)?.position);
1296 if (at.some((p) => p == null) || REACH.some((id) => !limits[id])) return msg("no position for the arm yet", true);
1297 reachState.angles = REACH.map((id, i) => toRad(id, at[i]));
1298 reachState.holders = 1;
1299 stream.open();
1300 reachState.timer = setInterval(() => {
1301 const { stick } = reachState;
1302 if (!stick.x && !stick.y && !stick.lift) return;
1303 const delta = reachMath.stickToDelta(stick, tipAt(reachState.angles), SPEED[$("rate").value] ?? 0.05, 0.05);
1304 const dq = reachMath.reachStep(tipAt, reachState.angles, delta);
1305 const frame = {};
1306 REACH.forEach((id, i) => { frame[id] = clampTicks(id, toTicks(id, reachState.angles[i] + dq[i])); });
1307 reachState.angles = REACH.map((id) => toRad(id, frame[id])); // a joint at its limit stays there
1308 REACH.forEach((id, i) => viewer.setJointValue(NAMES[id], reachState.angles[i]));
1309 stream.send(frame);
1310 }, 50);
1311 }
1312 function reachEnd(all = true) {
1313 if (!reachState.timer) return;
1314 if (!all && --reachState.holders > 0) return;
1315 clearInterval(reachState.timer); reachState.timer = null; reachState.holders = 0;
1316 reachState.stick = { x: 0, y: 0, lift: 0 };
1317 stream.end();
1318 }
1319 {
1320 const pad = $("pad"), knob = $("knob");
1321 let pointer = null;
1322 const place = (e) => {
1323 const r = pad.getBoundingClientRect(), radius = r.width / 2;
1324 let x = (e.clientX - r.left - radius) / radius, y = -(e.clientY - r.top - radius) / radius;
1325 const length = Math.hypot(x, y);
1326 if (length > 1) { x /= length; y /= length; }
1327 reachState.stick.x = Math.abs(x) < 0.12 ? 0 : x; reachState.stick.y = Math.abs(y) < 0.12 ? 0 : y; // a dead zone around the middle
1328 knob.style.transform = `translate(${x * radius * 0.62}px, ${-y * radius * 0.62}px)`;
1329 };
1330 const release = () => {
1331 if (pointer === null) return;
1332 pointer = null; pad.classList.remove("held"); knob.style.transform = "";
1333 reachState.stick.x = reachState.stick.y = 0; reachEnd(false);
1334 };
1335 pad.addEventListener("pointerdown", (e) => {
1336 if (pointer !== null) return;
1337 e.preventDefault(); pointer = e.pointerId;
1338 try { pad.setPointerCapture(e.pointerId); } catch {}
1339 pad.classList.add("held"); place(e); reachBegin();
1340 });
1341 pad.addEventListener("pointermove", (e) => { if (e.pointerId === pointer) place(e); });
1342 for (const ev of ["pointerup", "pointercancel", "lostpointercapture"]) pad.addEventListener(ev, (e) => { if (e.pointerId === pointer) release(); });
1343 addEventListener("blur", release);
1344 for (const b of document.querySelectorAll("#reach [data-lift]")) {
1345 let held = false;
1346 const up = () => { if (!held) return; held = false; reachState.stick.lift = 0; reachEnd(false); };
1347 b.addEventListener("pointerdown", (e) => { e.preventDefault(); if (held) return; held = true; try { b.setPointerCapture(e.pointerId); } catch {} reachState.stick.lift = Number(b.dataset.lift); reachBegin(); });
1348 for (const ev of ["pointerup", "pointercancel", "lostpointercapture"]) b.addEventListener(ev, up);
1349 b.addEventListener("contextmenu", (e) => e.preventDefault());
1350 }
1351 for (const b of document.querySelectorAll("#reach [data-grip]")) jog(b, 6, () => Number(b.dataset.grip));
1352 }
13531293
1354 // ---------------------------------------------------------------- touch driving (src/ui/drive.js)
1355 // Upright: a chip picks the joint, the lever's deflection is its speed, ▲ and ▼ nudge it and jog when held.
1356 const driver = new Driver({
1357 send: (f) => stream.send(f),
1358 flush: (f) => stream.flush(f),
1359 end: () => stream.end(),
1360 begin: () => {
1361 if (!canDrive({ mayDrive: mayDrive(), estop: status?.estop, held: status?.held, reconnecting: status?.reconnecting, limits })) return false;
1362 stream.open();
1363 return true;
1364 },
1365 limits: () => limits,
1366 speed: () => Number($("rate").value) || 300,
1367 onStop: (id) => {
1368 navigator.vibrate?.(30);
1369 for (const e of [$("lever"), $("stickL"), $("stickR")]) { e.classList.add("end"); setTimeout(() => e.classList.remove("end"), 400); }
1370 msg(`${LABEL[id]?.[1] ?? id} is at the end of its range`);
1371 },
1372 });
1373 driver.watch(window, document);
1374 // Turning the phone swaps the controls under the thumbs: whatever was held stops, and on its side the sticks come up.
1375 sideways.addEventListener("change", () => { driver.releaseAll(); if (sideways.matches && shell.classList.contains("driving")) setBare(true); });
1376 const tap = () => navigator.vibrate?.(8);
1377 const LABEL = { 1: ["J1", "Base"], 2: ["J2", "Shoulder"], 3: ["J3", "Elbow"], 4: ["J4", "Wrist"], 5: ["J5", "Roll"], 6: ["Grip", "Gripper"] };
1378 const ENDS = { 1: ["right", "left"], 2: ["up", "down"], 3: ["up", "down"], 4: ["up", "down"], 5: ["roll +", "roll −"], 6: ["open", "close"] };
1379 let picked = (() => { try { const n = Number(localStorage.getItem("so101.joint")); return LABEL[n] ? n : 2; } catch { return 2; } })();
1380 const lever = $("lever");
1381 function pickJoint(id) {
1382 if (driver.drive.holders.has("lever")) driver.hold("lever", { [id]: 0 }); // the joint that was moving stops; the finger now drives this one
1383 picked = id;
1384 try { localStorage.setItem("so101.joint", String(id)); } catch {}
1385 for (const b of $("chips").children) { const on = Number(b.dataset.id) === id; b.setAttribute("aria-checked", String(on)); b.tabIndex = on ? 0 : -1; }
1386 $("oneName").textContent = LABEL[id][1];
1387 $("nudgeUp").querySelector("small").textContent = ENDS[id][0]; $("nudgeDown").querySelector("small").textContent = ENDS[id][1];
1388 $("nudgeUp").setAttribute("aria-label", `${LABEL[id][1]} a step ${ENDS[id][0]}`); $("nudgeDown").setAttribute("aria-label", `${LABEL[id][1]} a step ${ENDS[id][1]}`);
1389 lever.setAttribute("aria-label", `${LABEL[id][1]}: push ${ENDS[id][0]} or ${ENDS[id][1]}, let go to stop`);
1390 if (status) renderTouch(status);
1391 }
1392 $("chips").replaceChildren(...Object.entries(LABEL).map(([id, [short, long]]) => {
1393 const b = el("button", { type: "button", onclick: () => { tap(); pickJoint(Number(id)); } }, el("b", { textContent: short }), el("small", { textContent: long }));
1394 b.dataset.id = id; b.setAttribute("role", "radio"); b.setAttribute("aria-label", `${short} ${long}`);
1395 return b;
1396 }));
1397 $("chips").addEventListener("keydown", (e) => {
1398 const d = e.key === "ArrowRight" || e.key === "ArrowDown" ? 1 : e.key === "ArrowLeft" || e.key === "ArrowUp" ? -1 : 0;
1399 if (!d) return;
1400 e.preventDefault(); pickJoint(((picked - 1 + d + 6) % 6) + 1); $("chips").children[picked - 1]?.focus();
1401 });
1402 pickJoint(picked);
1403 /** Where the picked joint is: degrees from the middle of its range, the gripper as how far open; the green bar on the lever likewise. */
1404 function renderTouch(d) {
1405 const j = d.joints.find((x) => x.id === picked), l = limits[picked];
1406 if (!j || j.position == null || !l) { $("onePos").textContent = "—"; return; }
1407 const share = (j.position - l.min) / (l.max - l.min);
1408 const up = UP[picked] > 0 ? share : 1 - share; // the bar fills toward the lever's top end
1409 lever.style.setProperty("--at", String(Math.max(0, Math.min(1, up)).toFixed(3)));
1410 $("onePos").textContent = picked === 6 ? `${Math.round(share * 100)}% open` : `${(((j.position - mid(picked)) * 360) / 4096).toFixed(0)}°`;
1411 }
1412 bindSurface(lever, driver, "lever", (_, y) => ({ [picked]: shape(y) * UP[picked] }), {
1413 haptic: tap,
1414 show: (_, y) => {
1415 $("leverKnob").style.transform = `translateY(${(-y * (lever.clientHeight / 2 - 38)).toFixed(1)}px)`;
1416 lever.setAttribute("aria-valuenow", String(Math.round(y * 100)));
1417 },
1418 });
1419 // ▲ ▼: a tap is one step, a hold jogs at half speed; arrow keys on the lever step too.
1420 const step = () => Math.max(5, Math.round((Number($("rate").value) || 300) / 15));
1421 for (const b of [$("nudgeUp"), $("nudgeDown")]) {
1422 let pointer = null, timer = null;
1423 const dir = () => Number(b.dataset.nudge) * UP[picked];
1424 b.addEventListener("pointerdown", (e) => {
1425 if (pointer !== null) return;
1426 e.preventDefault(); pointer = e.pointerId;
1427 try { b.setPointerCapture(e.pointerId); } catch {}
1428 tap(); b.classList.add("held");
1429 driver.nudge(picked, dir() * step());
1430 timer = setTimeout(() => { timer = null; if (pointer !== null) driver.hold("nudge", { [picked]: dir() * 0.5 }); }, 350);
1431 });
1432 const up = (e) => { if (e.pointerId !== pointer) return; pointer = null; clearTimeout(timer); b.classList.remove("held"); driver.release("nudge"); };
1433 for (const ev of ["pointerup", "pointercancel", "lostpointercapture"]) b.addEventListener(ev, up);
1434 b.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); e.stopPropagation(); driver.nudge(picked, dir() * step()); } });
1435 b.addEventListener("contextmenu", (e) => e.preventDefault());
1436 }
1437 lever.addEventListener("keydown", (e) => {
1438 const d = e.key === "ArrowUp" ? 1 : e.key === "ArrowDown" ? -1 : 0;
1439 if (d) { e.preventDefault(); driver.nudge(picked, d * UP[picked] * step()); }
1440 });
1441 // The sticks: a disc, so a corner is no faster than an edge; each stick has its own finger.
1442 const disc = (x, y) => { const r = Math.hypot(x, y); return r > 1 ? [x / r, y / r] : [x, y]; };
1443 const knob = (stick) => (x, y) => {
1444 const [dx, dy] = disc(x, y), r = stick.clientWidth * 0.3;
1445 stick.querySelector(".knob").style.transform = `translate(${(dx * r).toFixed(1)}px, ${(-dy * r).toFixed(1)}px)`;
1446 };
1447 bindSurface($("stickL"), driver, "left", (x, y) => { const [dx, dy] = disc(x, y); return { 1: shape(dx) * UP[1], 2: shape(dy) * UP[2] }; }, { show: knob($("stickL")), haptic: tap });
1448 let wrist = false;
1449 const right = () => (wrist ? { x: 5, y: 6 } : { x: 4, y: 3 });
1450 const rightStick = bindSurface($("stickR"), driver, "right", (x, y) => { const [dx, dy] = disc(x, y), m = right(); return { [m.x]: shape(dx) * UP[m.x], [m.y]: shape(dy) * UP[m.y] }; }, { show: knob($("stickR")), haptic: tap });
1451 const labelRight = () => {
1452 $("capR").textContent = wrist ? "J5 roll ↔ · grip ↕" : "J4 wrist ↔ · J3 elbow ↕";
1453 $("stickR").setAttribute("aria-label", wrist ? "Right stick: sideways rolls the wrist, up opens the gripper" : "Right stick: sideways bends the wrist, up and down lifts the elbow");
1454 $("swap").textContent = wrist ? "Arm" : "Wrist"; $("swap").setAttribute("aria-pressed", String(wrist));
1455 };
1456 $("swap").onclick = () => { rightStick.end(); wrist = !wrist; tap(); labelRight(); };
1457 labelRight();
1458 bindSurface($("gripOpen"), driver, "open", () => ({ 6: UP[6] }), { haptic: tap });
1459 bindSurface($("gripClose"), driver, "close", () => ({ 6: -UP[6] }), { haptic: tap });
1294 // Turning the phone on its side during a turn puts the sheet away: the camera and the model take the screen.
1295 sideways.addEventListener("change", () => { if (sideways.matches && shell.classList.contains("driving")) setBare(true); });
14601296
14611297 // Keep the screen on while it is your turn: a phone that dims mid-drive is a hand off the controls.
14621298 let wakeLock = null, waking = false, wantAwake = false;
@@ -1571,22 +1407,20 @@
15711407 $("t-controls").hidden = !mayDrive();
15721408 $("t-admin").hidden = !owner;
15731409 $("t-chat").hidden = $("t-queue").hidden = !relayed;
1574 for (const id of ["joints", "poses", "drive", "reach", "touch", "sticks"]) $(id).inert = !can;
1410 for (const id of ["joints", "poses", "drive"]) $(id).inert = !can;
15751411 shell.classList.toggle("driving", can);
1576 if (!can) driver.releaseAll();
15771412 wake(can);
15781413 $("stop").disabled = !(mayDrive() || owner);
15791414 $("stop").title = $("stop").disabled ? "Stop: the driver and the admins can press it" : "Stop (space or Esc): halt everything, hold with torque, until someone resumes";
15801415 // The server takes settings, the safety limits among them, from admins only.
15811416 for (const id of ["zoneRow", "trims", "safety", "jointLimits"]) $(id).inert = !owner;
15821417 viewer.toggleAttribute("disable-dragging", !can);
1583 if (!can) reachEnd();
15841418 teleop?.update(); // the turn ended: teleop stops at once (the server closes it too; the page need not wait for that)
15851419 // Your turn just came: open the controls. It just ended: back to the chat.
15861420 if (mayDrive() !== drove) {
15871421 drove = mayDrive();
15881422 if (relayed) showTab(drove ? "controls" : "chat");
1589 if (drove && sideways.matches) setBare(true); // on its side, a turn starts on the thumb sticks
1423 if (drove && sideways.matches) setBare(true); // on its side, a turn starts on the camera and the model
15901424 }
15911425 else if ($(`t-${tab}`).hidden) showTab(tab);
15921426 }
@@ -1641,7 +1475,8 @@
16411475 if (!st || !lobby.hello?.signin) return []; // a run on one's own machine: everyone drives, nobody queues
16421476 if (!me) return [button("Join to drive", "go", () => { showTab("queue"); $("joinName").focus(); })];
16431477 if (lobby.hello.banned) return []; // banned: watching only
1644 if (d?.id === me.id) return [...(d.readyBy ? [button("Ready", "go ready", () => say({ type: "ready" }))] : []), ...(!st.queue.length && !d.readyBy ? [button("+30 s", "", () => say({ type: "extend" }))] : []), button("Hand back", "", () => say({ type: "leave" }))];
1478 // On a phone the strip keeps one: Ready when it is asked for, else Hand back; the Queue tab has them all.
1479 if (d?.id === me.id) return [...(d.readyBy ? [button("Ready", "go ready", () => say({ type: "ready" }))] : []), ...(!st.queue.length && !d.readyBy ? [button("+30 s", "extra", () => say({ type: "extend" }))] : []), button("Hand back", d.readyBy ? "extra" : "", () => say({ type: "leave" }))];
16451480 if (st.queue.some((x) => x.id === me.id)) return [button("Leave", "", () => say({ type: "leave" }))];
16461481 return [button(me.owner && d ? "Take over" : d || (st.paused && !me.owner) ? "Join queue" : "Take control", "go", () => say({ type: "join" }))];
16471482 }
@@ -1659,9 +1494,8 @@
16591494 $("driverTag").textContent = d ? `🎮 ${d.name}${driving ? " (you)" : ""}` : "";
16601495 $("strip").classList.toggle("ready", Boolean(driving && d.readyBy));
16611496 alertNext(Boolean(mine && mine.place === 1 && !st.paused));
1662 $("notice").hidden = !st.announcement;
1663 $("notice").textContent = st.announcement ?? "";
1664 $("capLine").textContent = st.maxSpeedPercent < 100 ? `Speed limited to ${st.maxSpeedPercent}% of full` : "";
1497 note("announce", st.announcement ? `Announcement: ${st.announcement}` : null);
1498 note("cap", st.maxSpeedPercent < 100 ? `Speed limited to ${st.maxSpeedPercent}% of full` : null);
16651499 $("turnActions").replaceChildren(...turnButtons());
16661500 $("quiet").checked = quiet();
16671501 $("queueActions").replaceChildren(el("span", { textContent: d ? (me && d.id === me.id ? "You" : d.name) : "Nobody", style: "flex:1;font-weight:600" }), ...turnButtons());
@@ -1910,6 +1744,8 @@
19101744 if (beyond > 0) return `${part} is ${beyond.toFixed(0)} mm ${v.what === "table" ? "below the table" : "inside the base"} (plus the ${marginMm} mm margin)`;
19111745 return `${part} is ${(-beyond).toFixed(0)} mm ${v.what === "table" ? "above the table" : "from the base"}, inside the ${marginMm} mm margin`;
19121746 };
1747 // A stop is the full-width row under the strip; anything else the arm says is a note.
1748 if (d.estop || d.held) note("arm", null);
19131749 if (d.estop) {
19141750 b.dataset.held = "";
19151751 b.className = "stop";
@@ -1923,16 +1759,17 @@
19231759 b.dataset.held = key;
19241760 if (d.held) {
19251761 b.className = "stop";
1926 b.replaceChildren(`STOPPED by ${d.held.by} at ${new Date(d.held.at).toLocaleTimeString()}. The arm holds where it is; nothing sent before a resume will move it.`);
1762 b.replaceChildren(`STOPPED by ${d.held.by} at ${new Date(d.held.at).toLocaleTimeString()}. The arm holds; nothing sent before a resume moves it.`);
19271763 if (mayDrive() || isOwner()) b.append(el("button", { id: "resume", textContent: resumeArmed ? "Tap again to resume" : "Resume driving", className: "go", onclick: (e) => resume(e.currentTarget) }));
19281764 return;
19291765 }
1930 if (d.reconnecting) { b.className = "warn"; b.textContent = `Reconnecting to the arm… showing where it was at ${new Date(d.seenAt).toLocaleTimeString()}. Driving is paused, and the arm holds where it is.`; return; }
1931 if (typeof d.source === "string" && d.source.startsWith("simulated: offline")) { b.className = "bad"; b.textContent = "The arm has been unreachable for over a minute. This is the SIMULATION, not the real arm."; return; }
1932 if (d.jammed?.length) { b.className = "bad"; b.textContent = `jam: ${d.jammed.map((id) => NAMES[id] ?? id).join(", ")} pushed against something and stopped — back the leader off`; }
1933 else if (d.blocked) { b.className = d.zone === "enforce" ? "bad" : "warn"; b.textContent = `${d.zone === "enforce" ? "held at the boundary" : "warning"}: ${say(d.blocked)}`; }
1934 else if (d.violation) { b.className = "warn"; b.textContent = `the arm is ${say(d.violation)} (zone: ${d.zone})`; }
1935 else b.className = "";
1766 b.className = ""; b.replaceChildren();
1767 if (d.reconnecting) note("arm", `Reconnecting to the arm… showing where it was at ${new Date(d.seenAt).toLocaleTimeString()}. Driving is paused, and the arm holds where it is.`, "warn");
1768 else if (typeof d.source === "string" && d.source.startsWith("simulated: offline")) note("arm", "The arm has been unreachable for over a minute. This is the SIMULATION, not the real arm.", "bad");
1769 else if (d.jammed?.length) note("arm", `Jam: ${d.jammed.map((id) => NAMES[id] ?? id).join(", ")} pushed against something and stopped — back off`, "bad");
1770 else if (d.blocked) note("arm", `${d.zone === "enforce" ? "Held at the boundary" : "Warning"}: ${say(d.blocked)}`, d.zone === "enforce" ? "bad" : "warn");
1771 else if (d.violation) note("arm", `The arm is ${say(d.violation)} (zone: ${d.zone})`, "warn");
1772 else note("arm", null);
19361773 }
19371774 /** The arm's status, from /live (pushed when it changes) or, without it, from polling /status. */
19381775 // Until the limits, the settings and the model are in, a status is kept aside, not drawn; then it is applied whole,
@@ -1943,10 +1780,7 @@
19431780 {
19441781 const was = $("why").textContent;
19451782 status = d;
1946 driver.seed(d.joints.filter((j) => j.position != null).map((j) => [j.id, j.position]));
19471783 if ((explainLock() ?? "") !== was) applyLock();
1948 // Stopped, reconnecting or no longer this person's turn: a held thumb lets go, and its zero goes out now.
1949 if (!canDrive({ mayDrive: mayDrive(), estop: d.estop, held: d.held, reconnecting: d.reconnecting, limits })) driver.releaseAll();
19501784 // The round trip to the arm, which every command also makes: shown once it is long enough to feel.
19511785 const lag = [...rtts].sort((a, b) => a - b)[rtts.length >> 1] ?? 0;
19521786 $("lag").hidden = rtts.length < 3 || lag <= 250; $("lag").textContent = `· ${Math.round(lag)} ms lag`;
@@ -1960,7 +1794,7 @@
19601794 $("stop").classList.toggle("on", Boolean(d.estop || d.held)); $("stop").textContent = d.estop || d.held ? "Stopped" : "Stop";
19611795 $("record").textContent = d.driving === "record" ? "■ Stop recording" : "● Record";
19621796 for (const id of ["hold", "releaseBtn", "play"]) $(id).disabled = d.driving !== null;
1963 if (tab === "controls") { render(d); renderTouch(d); }
1797 if (tab === "controls") render(d);
19641798 banner(d); applyModel(d);
19651799 $("readout").innerHTML = `<span>lowest part <b>${Number.isFinite(d.lowestMm) ? d.lowestMm : "—"} mm</b> above the table</span><span>zone <b>${d.zone === "enforce" || d.zone === "warn" || d.zone === "off" ? d.zone : "—"}</b></span>`;
19661800 }
@@ -1998,7 +1832,7 @@
19981832 if (early) applyStatus(early);
19991833 poll();
20001834 if (relayed) pollLink();
2001 // The model is fetched once the first view is up, whether or not it is on screen: the joystick needs it.
1835 // The model is fetched once the first view is up, whether or not it is on screen.
20021836 if (modelInfo.ok) (window.requestIdleCallback ?? setTimeout)(() => load3D(), { timeout: 3000 });
20031837 })();
20041838 </script>

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs