Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
TOP: the joint sliders follow your finger and stay where you put them - no snapping back #79
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/64-top-the-joint-sliders-follow-your-finger → main 2 commits fork 3 threads · 3 unresolved
4 files
changed +196
−33
Software/so101/src/server.test.ts +12
| @@ -127,6 +127,18 @@ describe("viewer page", () => { | ||
| 127 | 127 | expect(await r.text()).toContain("Fullscreen"); |
| 128 | 128 | }); |
| 129 | 129 | |
| 130 | test("wires your target past the pose: the intent module, the reason line, the marks and the model's hold", async () => { | |
| 131 | const html = await (await fetch(`${base}/`)).text(); | |
| 132 | expect(html).toMatch(/import\("\/ui\/[^/]+\/intent\.js"\)/); | |
| 133 | expect(html).toContain('id="why"'); | |
| 134 | const module = await fetch(`${base}${html.match(/import\("(\/ui\/[^"]+\/intent\.js)"\)/)![1]}`); | |
| 135 | expect(module.status).toBe(200); | |
| 136 | expect(html).toContain("intent.target(j.id, j.position"); // the slider row and the model both ask before showing the pose | |
| 137 | expect(html.match(/intent\.target\(/g)!.length).toBeGreaterThanOrEqual(2); | |
| 138 | expect(html).toContain("intent.set(j.id, Number(range.value)"); // every input event is a target | |
| 139 | expect(html).toContain("explainLock()"); | |
| 140 | }); | |
| 141 | ||
| 130 | 142 | test("never builds HTML from people's text: event details and E-stop names go in as text nodes", async () => { |
| 131 | 143 | const html = await (await fetch(`${base}/`)).text(); |
| 132 | 144 | const sinks = html.split("\n").filter((line) => /\.innerHTML\s*=/.test(line)); |
Software/so101/src/ui/intent.js added +92
| @@ -0,0 +1,92 @@ | ||
| 1 | /** | |
| 2 | * What the person asked for, kept apart from where the arm is. A joint dragged by a slider or the 3D model has an | |
| 3 | * intent (a target in ticks): while it is held, and after release until the arm arrives or `hold` ms pass, the page | |
| 4 | * shows the intent and never lets a pose update overwrite it. Plain ESM, served at /ui/ and imported by the tests. | |
| 5 | */ | |
| 6 | ||
| 7 | export class Intent { | |
| 8 | /** @param {{ hold?: number, near?: number }} [options] hold: ms an unreached target is kept after release; near: ticks that count as arrived */ | |
| 9 | constructor(options = {}) { | |
| 10 | this.hold = options.hold ?? 2000; | |
| 11 | this.near = options.near ?? 12; | |
| 12 | /** @type {Map<number, { ticks: number, down: boolean, since: number }>} */ | |
| 13 | this.targets = new Map(); | |
| 14 | } | |
| 15 | ||
| 16 | /** The pointer is on the joint and wants `ticks`. @param {number} id @param {number} ticks @param {number} now */ | |
| 17 | set(id, ticks, now) { | |
| 18 | if (Number.isFinite(ticks)) this.targets.set(id, { ticks, down: true, since: now }); | |
| 19 | } | |
| 20 | ||
| 21 | /** The pointer lifted: the target stays, timed from now. @param {number} id @param {number} now */ | |
| 22 | release(id, now) { | |
| 23 | const t = this.targets.get(id); | |
| 24 | if (t) { t.down = false; t.since = now; } | |
| 25 | } | |
| 26 | ||
| 27 | /** Drop everything (stopped, turn over). */ | |
| 28 | clear() { this.targets.clear(); } | |
| 29 | ||
| 30 | /** | |
| 31 | * The target to show for a joint, or null when the real pose is the thing to show. Expires released targets the | |
| 32 | * arm reached or that waited long enough. | |
| 33 | * @param {number} id @param {number | null | undefined} actual @param {number} now | |
| 34 | */ | |
| 35 | target(id, actual, now) { | |
| 36 | const t = this.targets.get(id); | |
| 37 | if (!t) return null; | |
| 38 | if (!t.down && (now - t.since >= this.hold || (Number.isFinite(actual) && Math.abs(/** @type {number} */ (actual) - t.ticks) <= this.near))) { | |
| 39 | this.targets.delete(id); | |
| 40 | return null; | |
| 41 | } | |
| 42 | return t.ticks; | |
| 43 | } | |
| 44 | ||
| 45 | /** Whether the pointer is still on the joint. @param {number} id */ | |
| 46 | held(id) { return this.targets.get(id)?.down === true; } | |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * In words, why the controls are off; null when they are on. | |
| 51 | * @param {{ queued?: boolean, turn: boolean, estop?: unknown, held?: unknown, reconnecting?: unknown }} s | |
| 52 | */ | |
| 53 | export function whyNot(s) { | |
| 54 | if (s.estop) return "Stopped - an admin must clear the emergency stop"; | |
| 55 | if (s.held) return "Stopped - resume first"; | |
| 56 | if (s.reconnecting) return "Arm offline - reconnecting"; | |
| 57 | if (s.turn) return null; | |
| 58 | return s.queued ? "It's not your turn" : "Join the queue to drive"; | |
| 59 | } | |
| 60 | ||
| 61 | /** The marks' look, added with the first mark: the page's own style is spent. */ | |
| 62 | const CSS = ` | |
| 63 | .j .rail { position: relative; flex: 1; min-width: 0; display: flex; } | |
| 64 | .j .rail input[type=range] { width: 100%; } | |
| 65 | .j .mark { position: absolute; top: 2px; bottom: 2px; width: 2px; pointer-events: none; border-radius: 1px; } | |
| 66 | .j .mark.actual { background: var(--fg); opacity: .8; } .j .mark.intent { background: var(--blue); width: 8px; top: -3px; bottom: -3px; border-radius: 4px; border: 2px solid var(--bg, #fff); box-sizing: border-box; margin-left: -3px; } | |
| 67 | #why { margin: 0 0 6px; color: var(--warn); font-size: 13px; } #why:empty { display: none; } | |
| 68 | `; | |
| 69 | ||
| 70 | let styled = false; | |
| 71 | ||
| 72 | /** | |
| 73 | * Place the two marks on a slider's rail: where the arm is, and (when there is one) where it was asked to go. | |
| 74 | * The mark is a tall pill, the arm's a thin line, and the range says both in words. | |
| 75 | * @param {{ range: any, actual?: any, mark?: any }} row | |
| 76 | * @param {number | null} want @param {number | null | undefined} actual | |
| 77 | */ | |
| 78 | export function marks(row, want, actual) { | |
| 79 | const document = /** @type {any} */ (globalThis).document; | |
| 80 | if (!styled && document) { styled = true; document.head.append(Object.assign(document.createElement("style"), { textContent: CSS })); } | |
| 81 | if (!row.actual) { | |
| 82 | row.actual = Object.assign(document.createElement("i"), { className: "mark actual" }); | |
| 83 | row.mark = Object.assign(document.createElement("i"), { className: "mark intent", hidden: true }); | |
| 84 | row.range.parentElement.append(row.actual, row.mark); | |
| 85 | } | |
| 86 | const lo = Number(row.range.min), span = Number(row.range.max) - lo; | |
| 87 | const at = (/** @type {number} */ v) => `calc(${Math.max(0, Math.min(100, ((v - lo) / span) * 100))}% - 1px)`; | |
| 88 | row.range.setAttribute("aria-valuetext", want === null ? `${row.range.value}` : `target ${want}, actual ${actual ?? "unknown"}`); | |
| 89 | row.mark.hidden = want === null; | |
| 90 | if (want !== null) row.mark.style.left = at(want); | |
| 91 | if (typeof actual === "number") row.actual.style.left = at(actual); | |
| 92 | } |
Software/so101/src/ui/intent.test.ts added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { Intent, whyNot } from "./intent.js"; | |
| 3 | ||
| 4 | describe("Intent", () => { | |
| 5 | test("a fake 30 Hz pose stream never moves a held slider", () => { | |
| 6 | const i = new Intent(); | |
| 7 | i.set(1, 3000, 0); | |
| 8 | for (let k = 0; k < 90; k++) expect(i.target(1, 2048, k * 33)).toBe(3000); | |
| 9 | }); | |
| 10 | test("after release the target stays until the arm arrives", () => { | |
| 11 | const i = new Intent(); | |
| 12 | i.set(1, 3000, 0); i.release(1, 100); | |
| 13 | expect(i.target(1, 2048, 500)).toBe(3000); | |
| 14 | expect(i.target(1, 2995, 600)).toBeNull(); | |
| 15 | expect(i.target(1, 2048, 700)).toBeNull(); | |
| 16 | }); | |
| 17 | test("an arm that never arrives is followed again after 2 s", () => { | |
| 18 | const i = new Intent(); | |
| 19 | i.set(2, 3000, 0); i.release(2, 0); | |
| 20 | expect(i.target(2, 2048, 1999)).toBe(3000); | |
| 21 | expect(i.target(2, 2048, 2000)).toBeNull(); | |
| 22 | }); | |
| 23 | test("a held target is not dropped when the arm happens to be there", () => { | |
| 24 | const i = new Intent(); | |
| 25 | i.set(3, 2048, 0); | |
| 26 | expect(i.target(3, 2048, 10)).toBe(2048); | |
| 27 | expect(i.held(3)).toBe(true); | |
| 28 | }); | |
| 29 | test("an unknown joint shows the real pose", () => expect(new Intent().target(9, 1, 0)).toBeNull()); | |
| 30 | }); | |
| 31 | ||
| 32 | describe("whyNot", () => { | |
| 33 | const base = { turn: false }; | |
| 34 | test("a refused command says why", () => { | |
| 35 | expect(whyNot({ ...base })).toBe("Join the queue to drive"); | |
| 36 | expect(whyNot({ ...base, queued: true })).toBe("It's not your turn"); | |
| 37 | expect(whyNot({ turn: true, held: {} })).toBe("Stopped - resume first"); | |
| 38 | expect(whyNot({ turn: true, reconnecting: true })).toBe("Arm offline - reconnecting"); | |
| 39 | }); | |
| 40 | test("your turn drives", () => expect(whyNot({ turn: true })).toBeNull()); | |
| 41 | }); | |
| 42 | ||
| 43 | describe("marks", () => { | |
| 44 | test("intent and actual sit apart on the rail, the intent hidden when there is none", async () => { | |
| 45 | const { marks } = await import("./intent.js"); | |
| 46 | const made: any[] = []; | |
| 47 | (globalThis as any).document = { head: { append() {} }, createElement: () => ({ style: {} }) }; | |
| 48 | const row = { range: { min: "0", max: "100", value: "40", setAttribute(k: string, v: string) { (this as any)[k] = v; }, parentElement: { append: (...n: any[]) => made.push(...n) } } } as any; | |
| 49 | marks(row, 75, 25); | |
| 50 | expect(row.mark.hidden).toBe(false); | |
| 51 | expect(row.mark.style.left).toBe("calc(75% - 1px)"); | |
| 52 | expect(row.actual.style.left).toBe("calc(25% - 1px)"); | |
| 53 | expect(row.range["aria-valuetext"]).toBe("target 75, actual 25"); | |
| 54 | marks(row, null, 30); | |
| 55 | expect(row.range["aria-valuetext"]).toBe("40"); | |
| 56 | expect(row.mark.hidden).toBe(true); | |
| 57 | }); | |
| 58 | }); |
Software/so101/src/viewer.html +34 −33
| @@ -365,6 +365,7 @@ | ||
| 365 | 365 | </div> |
| 366 | 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 | 367 | </div> |
| 368 | <p id="why" role="status"></p> | |
| 368 | 369 | <div id="joints"></div> |
| 369 | 370 | <div class="row" id="poses"></div> |
| 370 | 371 | <div class="row" id="drive"> |
| @@ -575,7 +576,6 @@ | ||
| 575 | 576 | |
| 576 | 577 | // ---------------------------------------------------------------- which arm |
| 577 | 578 | // Behind the hosted app's relay (/link answers), the arm is a live `so101 serve` or the simulation, and the cameras come through the relay. |
| 578 | // The relay writes the link and the camera list into the page (#boot), so the first view needs no round trip to start. | |
| 579 | 579 | const boot = (() => { try { return JSON.parse($("boot")?.textContent ?? "null"); } catch { return null; } })(); |
| 580 | 580 | const relayed = boot !== null || await fetch("/link", { cache: "no-store" }).then((r) => r.ok, () => false); |
| 581 | 581 | // A real arm that drops is "reconnecting": the same arm, its last pose kept, driving paused. Only after a minute down |
| @@ -602,11 +602,7 @@ | ||
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | // ---------------------------------------------------------------- cameras |
| 605 | // The owner lists the cameras (/admin/camera-list); this page polls the list, so a camera added or removed shows within seconds. | |
| 606 | // Which views are on is this viewer's own choice, kept in this browser: one at a time on a phone, several side by side on a wider screen. | |
| 607 | // On a good link a plain <img> stream, which every browser plays; a canvas comparison once a second notices a frozen | |
| 608 | // picture and reconnects. On a slow one (src/ui/camera-plan.js) the relay holds the stream to a few frames a second, | |
| 609 | // and on a crawl one snapshot at a time. The quality button overrides it. A hidden page fetches no video at all. | |
| 605 | // On a good link a plain <img> stream, which every browser plays; a canvas comparison once a second notices a frozen picture and reconnects; a slow link gets fewer frames (src/ui/camera-plan.js). | |
| 610 | 606 | const cams = []; |
| 611 | 607 | const direct = (n) => q.get(`stream${n}`) || q.get(n === 1 ? "stream" : "") || `${location.protocol}//${location.hostname}:${8079 + n}/stream`; |
| 612 | 608 | const canvas = document.createElement("canvas"); canvas.width = 32; canvas.height = 18; |
| @@ -986,9 +982,7 @@ | ||
| 986 | 982 | $("playClose").onclick = () => $("playDlg").close(); |
| 987 | 983 | |
| 988 | 984 | // ---------------------------------------------------------------- the leader arm, plugged into this computer or phone |
| 989 | // src/leader-arm.ts, served at /app/: the CLI's own bus code over Web Serial. Connected, the leader is mirrored by the 3D model | |
| 990 | // and the joint rows. With Teleop on, during your turn, src/teleop.ts streams its pose at 30 Hz, latest wins, through the | |
| 991 | // server's limits and zone; the turn ending, a hidden tab, an unplugged leader or a lost socket stop it and the arm holds. | |
| 985 | // src/leader-arm.ts, served at /app/: the CLI's own bus code over Web Serial. Connected, the leader is mirrored by the 3D model; teleop (src/teleop.ts) streams it during your turn. | |
| 992 | 986 | let leader = null; // { arm, port, stop, pose, targets, calibration } |
| 993 | 987 | let teleop = null; // src/teleop.ts, made when the first leader connects |
| 994 | 988 | let calib = null; // the calibration card, while it is open |
| @@ -1101,9 +1095,7 @@ | ||
| 1101 | 1095 | teleop.set(true); |
| 1102 | 1096 | } |
| 1103 | 1097 | // ---------------------------------------------------------------- leader calibration (src/leader-map.js) |
| 1104 | // Once per driver: the leader in the follower's middle pose, then each joint at each end the model shows. The ends | |
| 1105 | // carry the direction (a joint whose low end reads higher is mounted backwards) and each side's length; the centre | |
| 1106 | // carries the offset. Kept on the server under the driver's sign-in; the connected leader maps through it from then on. | |
| 1098 | // Once per driver: the leader in the follower's middle pose, then each joint at each end the model shows; kept on the server under the driver's sign-in. | |
| 1107 | 1099 | const LABELS = { 1: "Base rotation", 2: "Shoulder", 3: "Elbow", 4: "Wrist bend", 5: "Wrist roll", 6: "Gripper trigger" }; |
| 1108 | 1100 | const LEADER_IDS = [1, 2, 3, 4, 5, 6]; |
| 1109 | 1101 | const STEPS = ["centre", ...LEADER_IDS.flatMap((id) => [{ id, end: "low" }, { id, end: "high" }]), "check"]; |
| @@ -1223,11 +1215,9 @@ | ||
| 1223 | 1215 | ]); |
| 1224 | 1216 | THREE = three; reachMath = reach; |
| 1225 | 1217 | if (!customElements.get("urdf-viewer")) customElements.define("urdf-viewer", URDFManipulator); |
| 1226 | // The element leaves mesh loading to the page: binary STL through three's loader, the URDF's colour where it names one. | |
| 1227 | 1218 | viewer.loadMeshFunc = (path, manager, material, done) => { |
| 1228 | 1219 | new STLLoader(manager).load(path, (geometry) => done(new THREE.Mesh(geometry, material ?? new THREE.MeshPhongMaterial({ color: 0x9aa4ae, shininess: 30 }))), undefined, (err) => done(null, err)); |
| 1229 | 1220 | }; |
| 1230 | // The drag controls listen for mouse events only. A finger is translated into them, so the model can be dragged on a phone or an iPad. | |
| 1231 | 1221 | const canvas = viewer.renderer.domElement; |
| 1232 | 1222 | canvas.style.touchAction = "none"; |
| 1233 | 1223 | const asMouse = (type, t) => canvas.dispatchEvent(new MouseEvent(type, { clientX: t.clientX, clientY: t.clientY, bubbles: true })); |
| @@ -1246,12 +1236,10 @@ | ||
| 1246 | 1236 | table.position.z = modelInfo.floorZ - 0.0005; |
| 1247 | 1237 | const grid = new THREE.GridHelper(0.9, 18, 0x4a5058, 0x30363d); grid.rotation.x = Math.PI / 2; grid.position.z = modelInfo.floorZ; |
| 1248 | 1238 | marker = new THREE.Mesh(new THREE.SphereGeometry(0.012, 16, 12), new THREE.MeshBasicMaterial({ color: 0xf85149 })); marker.visible = false; |
| 1249 | // Not for the mouse: the drag controls take the first thing a ray hits, and three.js hits a line from a metre away. | |
| 1250 | 1239 | for (const o of [table, grid, marker]) o.raycast = () => {}; |
| 1251 | 1240 | viewer.world.add(table, grid, marker); |
| 1252 | 1241 | viewer.plane.visible = false; // the element's own shadow plane sits under the lowest part, which would be below the table |
| 1253 | 1242 | if (status) applyModel(status); |
| 1254 | // A three-quarter view from the front right, close enough for a 40 cm arm (the element starts 10 m away). | |
| 1255 | 1243 | viewer.camera.position.set(0.5, 0.38, 0.62); |
| 1256 | 1244 | viewer.controls.target.set(0.08, 0.1, 0); |
| 1257 | 1245 | viewer.controls.update(); |
| @@ -1259,11 +1247,13 @@ | ||
| 1259 | 1247 | $("reach").hidden = !tipLink(); |
| 1260 | 1248 | }); |
| 1261 | 1249 | viewer.addEventListener("manipulate-start", (e) => { dragging = e.detail; stream.open(); }); |
| 1262 | viewer.addEventListener("manipulate-end", () => { dragging = null; stream.end(); }); | |
| 1250 | viewer.addEventListener("manipulate-end", () => { const id = IDS[dragging]; if (id) intent.release(id, performance.now()); dragging = null; stream.end(); }); | |
| 1263 | 1251 | viewer.addEventListener("angle-change", (e) => { |
| 1264 | 1252 | if (dragging !== e.detail || !viewer.robot) return; |
| 1265 | 1253 | const id = IDS[e.detail]; if (!id || !limits[id]) return; |
| 1266 | stream.send({ [id]: clampTicks(id, toTicks(id, viewer.robot.joints[e.detail].angle)) }); | |
| 1254 | const ticks = clampTicks(id, toTicks(id, viewer.robot.joints[e.detail].angle)); | |
| 1255 | intent.set(id, ticks, performance.now()); | |
| 1256 | stream.send({ [id]: ticks }); | |
| 1267 | 1257 | }); |
| 1268 | 1258 | function applyModel(d) { |
| 1269 | 1259 | if (!viewer.robot || calib) return; // while calibrating, the model shows the pose to copy |
| @@ -1271,7 +1261,8 @@ | ||
| 1271 | 1261 | const name = NAMES[j.id]; |
| 1272 | 1262 | if (!name || j.position == null || name === dragging || !limits[j.id]) continue; |
| 1273 | 1263 | if (reachState.timer && j.id <= 3) continue; // the joystick is ahead of the arm; snapping back would make it stutter |
| 1274 | viewer.setJointValue(name, toRad(j.id, j.position)); | |
| 1264 | const want = intent.target(j.id, j.position, performance.now()); | |
| 1265 | viewer.setJointValue(name, toRad(j.id, want ?? j.position)); | |
| 1275 | 1266 | } |
| 1276 | 1267 | if (marker) { |
| 1277 | 1268 | const v = d.blocked ?? d.violation; |
| @@ -1281,8 +1272,7 @@ | ||
| 1281 | 1272 | } |
| 1282 | 1273 | |
| 1283 | 1274 | // ---------------------------------------------------------------- the joystick: move the gripper, not a joint |
| 1284 | // The pad's deflection becomes a displacement of the gripper (src/ui/reach.js), solved onto pan, lift and elbow | |
| 1285 | // against the URDF the 3D view already holds. The wrist keeps its own angle; the server's zone checks every frame. | |
| 1275 | // The pad's deflection becomes a displacement of the gripper (src/ui/reach.js), solved onto pan, lift and elbow. | |
| 1286 | 1276 | let reachMath = null; |
| 1287 | 1277 | const REACH = [1, 2, 3]; |
| 1288 | 1278 | const SPEED = { 100: 0.02, 300: 0.05, 800: 0.1 }; // m/s at full deflection, by jog speed |
| @@ -1363,8 +1353,6 @@ | ||
| 1363 | 1353 | |
| 1364 | 1354 | // ---------------------------------------------------------------- touch driving (src/ui/drive.js) |
| 1365 | 1355 | // Upright: a chip picks the joint, the lever's deflection is its speed, ▲ and ▼ nudge it and jog when held. |
| 1366 | // On its side: two thumb sticks over the picture (left J1/J2, right J3/J4 or J5/gripper) and the gripper between them. | |
| 1367 | // Every finger is its own holder; the instant one lifts, its joints' targets go out as they stand and the arm settles there. | |
| 1368 | 1356 | const driver = new Driver({ |
| 1369 | 1357 | send: (f) => stream.send(f), |
| 1370 | 1358 | flush: (f) => stream.flush(f), |
| @@ -1570,8 +1558,16 @@ | ||
| 1570 | 1558 | function isOwner() { return !relayed || Boolean(lobby.hello?.you?.owner); } |
| 1571 | 1559 | const say = (m) => { if (lobby.ws?.readyState === 1) lobby.ws.send(JSON.stringify(m)); }; |
| 1572 | 1560 | let drove = false; |
| 1561 | function explainLock() { | |
| 1562 | const me = lobby.hello?.you, down = linkNow === "offline", st = typeof status?.source === "string" && status.source.startsWith("simulated"); | |
| 1563 | const w = whyNot({ turn: mayDrive(), queued: Boolean(me && lobby.state?.queue?.some((x) => x.id === me.id)), estop: status?.estop, held: status?.held, reconnecting: status?.reconnecting || linkNow === "reconnecting" || (relayed && (down || (st && realArm(linkMode)))) }); | |
| 1564 | $("why").textContent = w ?? ""; | |
| 1565 | return w; | |
| 1566 | } | |
| 1573 | 1567 | function applyLock() { |
| 1574 | const can = mayDrive() && !status?.estop && !status?.held, owner = isOwner(); | |
| 1568 | const why = explainLock(); | |
| 1569 | if (why) intent.clear(); | |
| 1570 | const can = mayDrive() && !why, owner = isOwner(); | |
| 1575 | 1571 | $("t-controls").hidden = !mayDrive(); |
| 1576 | 1572 | $("t-admin").hidden = !owner; |
| 1577 | 1573 | $("t-chat").hidden = $("t-queue").hidden = !relayed; |
| @@ -1868,6 +1864,9 @@ | ||
| 1868 | 1864 | const joints = $("joints"); |
| 1869 | 1865 | const built = new Map(); |
| 1870 | 1866 | let sliding = null; |
| 1867 | // Lazy: the first view's budget is spent. | |
| 1868 | let intent = { set() {}, release() {}, clear() {}, target: () => null }, whyNot = () => null, marks = () => {}; | |
| 1869 | const intentModule = import("/ui/__VERSION__/intent.js").then((m) => { intent = new m.Intent(); whyNot = m.whyNot; marks = m.marks; }, () => {}); | |
| 1871 | 1870 | function render(d) { |
| 1872 | 1871 | for (const j of d.joints) { |
| 1873 | 1872 | let el = built.get(j.id); |
| @@ -1875,13 +1874,13 @@ | ||
| 1875 | 1874 | const lim = limits[j.id] ?? { min: 0, max: 4095 }; |
| 1876 | 1875 | const div = document.createElement("div"); div.className = "j"; |
| 1877 | 1876 | div.innerHTML = `<b></b><div class="v"><span class="pos"></span><small class="ld"></small><small class="t"></small></div> |
| 1878 | <div class="slide"><span class="jog"><button data-d="-1" aria-label="less">−</button></span><input type="range" min="${lim.min + 30}" max="${lim.max - 30}" step="1"><span class="jog"><button data-d="1" aria-label="more">+</button></span></div>`; | |
| 1877 | <div class="slide"><span class="jog"><button data-d="-1" aria-label="less">−</button></span><span class="rail"><input type="range" min="${lim.min + 30}" max="${lim.max - 30}" step="1"></span><span class="jog"><button data-d="1" aria-label="more">+</button></span></div>`; | |
| 1879 | 1878 | div.querySelector("b").textContent = j.joint ?? String(j.id); |
| 1880 | 1879 | const range = div.querySelector("input"); |
| 1881 | 1880 | range.setAttribute("aria-label", j.joint ?? `joint ${j.id}`); |
| 1882 | 1881 | range.addEventListener("pointerdown", () => { sliding = j.id; stream.open(); }); |
| 1883 | range.addEventListener("input", () => { if (sliding === j.id) stream.send({ [j.id]: Number(range.value) }); }); | |
| 1884 | const done = () => { if (sliding === j.id) { sliding = null; stream.end(); } }; | |
| 1882 | range.addEventListener("input", () => { if (sliding === j.id) { intent.set(j.id, Number(range.value), performance.now()); stream.send({ [j.id]: Number(range.value) }); el.pos.textContent = range.value; } }); | |
| 1883 | const done = () => { if (sliding === j.id) { sliding = null; intent.release(j.id, performance.now()); stream.end(); } }; | |
| 1885 | 1884 | range.addEventListener("pointerup", done); range.addEventListener("pointercancel", done); range.addEventListener("change", done); |
| 1886 | 1885 | for (const b of div.querySelectorAll(".jog button")) jog(b, j.id, () => Number(b.dataset.d)); |
| 1887 | 1886 | joints.append(div); |
| @@ -1889,10 +1888,12 @@ | ||
| 1889 | 1888 | built.set(j.id, el); |
| 1890 | 1889 | } |
| 1891 | 1890 | const hot = j.temperature >= 55, load = Math.abs(j.load ?? 0); |
| 1892 | el.pos.textContent = j.position ?? "—"; | |
| 1891 | const want = intent.target(j.id, j.position, performance.now()); | |
| 1892 | el.pos.textContent = want ?? j.position ?? "—"; | |
| 1893 | marks(el, want, j.position); | |
| 1893 | 1894 | el.pos.style.color = hot ? "var(--bad)" : load > 50 ? "var(--warn)" : "var(--fg)"; |
| 1894 | 1895 | el.t.textContent = `${j.temperature ?? "—"}°C · ${load.toFixed(0)}%${j.torque ? " ·T" : ""}`; |
| 1895 | if (sliding !== j.id && j.position != null) el.range.value = j.position; | |
| 1896 | if (want !== null) el.range.value = want; else if (sliding !== j.id && j.position != null) el.range.value = j.position; | |
| 1896 | 1897 | el.div.classList.toggle("jam", d.jammed?.includes(j.id)); |
| 1897 | 1898 | el.div.classList.toggle("drag", dragging === j.joint || sliding === j.id); |
| 1898 | 1899 | const locked = (d.driving !== null && d.driving !== "stream") || leaderStreaming(); // the page's own stream may run; a leader's may not be fought |
| @@ -1940,10 +1941,10 @@ | ||
| 1940 | 1941 | function applyStatus(d) { |
| 1941 | 1942 | if (!started) return void (early = d); |
| 1942 | 1943 | { |
| 1943 | const wasStopped = Boolean(status?.estop || status?.held); | |
| 1944 | const was = $("why").textContent; | |
| 1944 | 1945 | status = d; |
| 1945 | 1946 | driver.seed(d.joints.filter((j) => j.position != null).map((j) => [j.id, j.position])); |
| 1946 | if (Boolean(d.estop || d.held) !== wasStopped) applyLock(); | |
| 1947 | if ((explainLock() ?? "") !== was) applyLock(); | |
| 1947 | 1948 | // Stopped, reconnecting or no longer this person's turn: a held thumb lets go, and its zero goes out now. |
| 1948 | 1949 | if (!canDrive({ mayDrive: mayDrive(), estop: d.estop, held: d.held, reconnecting: d.reconnecting, limits })) driver.releaseAll(); |
| 1949 | 1950 | // The round trip to the arm, which every command also makes: shown once it is long enough to feel. |
| @@ -1984,13 +1985,13 @@ | ||
| 1984 | 1985 | applyLock(); |
| 1985 | 1986 | if (relayed) lobbyConnect(); else showTab("controls"); |
| 1986 | 1987 | // The views: the ones chosen last time, else one on a phone (the camera when there is a real one), else the camera and the model. |
| 1987 | // With the page's own facts (#boot) the camera starts now, before anything else is asked; the rest is asked all at once. | |
| 1988 | 1988 | const linked = boot ? Promise.resolve(boot.link) : relayed ? api("/link").catch(() => ({})) : Promise.resolve(null); |
| 1989 | 1989 | if (boot) { |
| 1990 | 1990 | cameraFirst = boot.link.mode === "live" || q.has("stream"); |
| 1991 | 1991 | if (cameraFirst) { viewsReady = true; for (const c of cams) if (!paneOn(c) && wanted(c.pane.dataset.key)) showCam(c, true); } |
| 1992 | 1992 | } |
| 1993 | const [l, mi, link] = await Promise.all([api("/limits"), api("/model.json"), linked, loadSettings(), loadPoses()]); | |
| 1993 | const [, l, mi, link] = await Promise.all([intentModule, api("/limits"), api("/model.json"), linked, loadSettings(), loadPoses()]); | |
| 1994 | applyLock(); | |
| 1994 | 1995 | limits = l; modelInfo = mi; started = true; |
| 1995 | 1996 | cameraFirst = !relayed || link?.mode === "live" || q.has("stream"); |
| 1996 | 1997 | startViews(); |
new above
offline
The JSDoc is attached to
let styledinstead of marks(). The marks differ by colour only: add aria-valuetext on the range and make the intent mark taller or a different shape.