Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
A safety hold shows in its own reserved status-strip row, wrapping to 3 lines, beside a driver name that stays visible; the camera box never changes size #338
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/335-a-safety-hold-shows-in-its-own-reserved → main 2 commits fork 2 threads · 2 unresolved
5 files
changed +120
−9
Software/so101/src/server.test.ts +2 −2
| @@ -150,7 +150,7 @@ describe("viewer page", () => { | ||
| 150 | 150 | expect(module).toContain('$("events").replaceChildren('); |
| 151 | 151 | }); |
| 152 | 152 | |
| 153 | test("a first visit downloads under 52 KB gzipped: the page and the modules it imports up front; the rest comes when needed", async () => { | |
| 153 | test("a first visit downloads under 52.5 KB gzipped: the page and the modules it imports up front; the rest comes when needed", async () => { | |
| 154 | 154 | const page = await (await fetch(`${base}/`)).text(); |
| 155 | 155 | const script = page.slice(page.indexOf('<script type="module">')); |
| 156 | 156 | const upfront = new Set([...page.matchAll(/<link rel="modulepreload" href="([^"]+)">/g), ...script.matchAll(/^\s*import [^;]*? from "([^"]+)";/gm)].map((m) => m[1]!)); |
| @@ -161,7 +161,7 @@ describe("viewer page", () => { | ||
| 161 | 161 | expect(r.status).toBe(200); |
| 162 | 162 | bytes += gzipSync(Buffer.from(await r.arrayBuffer()), { level: 6 }).length; |
| 163 | 163 | } |
| 164 | expect(bytes).toBeLessThan(52_000); | |
| 164 | expect(bytes).toBeLessThan(52_500); | |
| 165 | 165 | // three.js, the leader's mapping, the calibration panel and the Machine panel are imported where they are used, not up front. |
| 166 | 166 | for (const lazy of ["three", "/leader-map.js", "leader-calib.js", "calibration.js", "reach.js", "machine-panel.js", "machine.js", "metrics-panel.js"]) expect([...upfront].some((p) => p === lazy || p.endsWith(`/${lazy}`))).toBe(false); |
| 167 | 167 | expect(script).toContain('import("/leader-map.js")'); |
Software/so101/src/stop-layout.test.ts +34
| @@ -110,3 +110,37 @@ describe("the served page's STOP", () => { | ||
| 110 | 110 | if (click) expect(click).toMatch(/e\.detail\s*===\s*0/); |
| 111 | 111 | }); |
| 112 | 112 | }); |
| 113 | ||
| 114 | describe("the hold line", () => { | |
| 115 | const css = () => [...html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((m) => m[1]!).join("\n"); | |
| 116 | const bodyOf = (id: string) => flatRules(css()).filter((r) => r.selector.split(",").some((s) => s.trim() === `#${id}`)).map((r) => r.body).join(";"); | |
| 117 | ||
| 118 | test("it sits in the status strip beside the driver line and wraps, clamped to 3 lines", () => { | |
| 119 | const strip = /<section id="strip"[\s\S]*?<\/section>/.exec(html)![0]; | |
| 120 | expect(strip).toContain('id="holdLine"'); | |
| 121 | expect(strip).toContain('id="driverLine"'); | |
| 122 | const body = bodyOf("holdLine"); | |
| 123 | expect(body).toMatch(/white-space\s*:\s*normal/); | |
| 124 | expect(body).toMatch(/-webkit-line-clamp\s*:\s*3/); | |
| 125 | expect(body).toMatch(/min-height\s*:\s*3\.6em/); | |
| 126 | }); | |
| 127 | ||
| 128 | test("nothing hides the driver line or the hold line", () => { | |
| 129 | const chain = (id: string): El => ({ tag: "div", id, classes: [], attrs: { id } }); | |
| 130 | for (const id of ["driverLine", "holdLine"]) { | |
| 131 | const offenders = flatRules(css()).filter((r) => hides(r.body)).flatMap((r) => r.selector.split(",").filter((s) => matches(s, chain(id)))); | |
| 132 | expect(offenders.filter((s) => !/:empty/.test(s))).toEqual([]); | |
| 133 | } | |
| 134 | expect(html).not.toMatch(/\$\("driverLine"\)\.hidden|driverLine[^\n]{0,40}style\.display/); | |
| 135 | }); | |
| 136 | ||
| 137 | test("the reserved height does not depend on a hold showing: the camera box is the same size at 360 px", () => { | |
| 138 | // Heights are em-based and fixed on the empty and the filled line alike; no rule keyed on a hold state sizes the strip or the stage. | |
| 139 | const rules = flatRules(css()).filter((r) => /#holdLine/.test(r.selector)); | |
| 140 | for (const r of rules) expect(r.body).not.toMatch(/(^|;)\s*(display|height|min-height|max-height)\s*:\s*(0|none|auto)\b/); | |
| 141 | expect(rules.some((r) => /\.bad/.test(r.selector) && /(^|;)\s*(font-size|line-height|padding|margin[\w-]*|height|min-height)\s*:/.test(r.body))).toBe(false); | |
| 142 | expect(bodyOf("holdLine")).not.toMatch(/position\s*:\s*(absolute|fixed)/); | |
| 143 | // the 360 px phone: no media rule narrows or resizes the line | |
| 144 | expect(css()).not.toMatch(/@media[^{]*360[^{]*\{[^}]*#holdLine/); | |
| 145 | }); | |
| 146 | }); |
Software/so101/src/ui/hold-line.js added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | // A stop-like hold takes the status strip's row; a warn-only notice stays in the banner. E-stop and manual stop are the page's. | |
| 2 | const lost = "The arm has been unreachable for over a minute. This is the SIMULATION, not the real arm."; | |
| 3 | ||
| 4 | /** @returns {{ bad: boolean, text: string } | null} */ | |
| 5 | export function holdText(/** @type {any} */ d, /** @type {(v: any) => string} */ say, /** @type {Record<number, string>} */ names) { | |
| 6 | if (d.reconnecting) return { bad: false, text: `Reconnecting to the arm… showing where it was at ${new Date(d.seenAt ?? 0).toLocaleTimeString()}. Driving is paused, and the arm holds where it is.` }; | |
| 7 | if (typeof d.source === "string" && d.source.startsWith("simulated: offline")) return { bad: true, text: lost }; | |
| 8 | if (d.jammed?.length) return { bad: true, text: `jam: ${d.jammed.map((/** @type {number} */ id) => names[id] ?? id).join(", ")} pushed against something and stopped — back the leader off` }; | |
| 9 | if (d.blocked && d.zone === "enforce") return { bad: true, text: `held at the boundary: ${say(d.blocked)}` }; | |
| 10 | return null; | |
| 11 | } | |
| 12 | ||
| 13 | /** @returns {string | null} */ | |
| 14 | export function warnText(/** @type {any} */ d, /** @type {(v: any) => string} */ say) { | |
| 15 | return d.blocked ? `warning: ${say(d.blocked)}` : d.violation ? `the arm is ${say(d.violation)} (zone: ${d.zone})` : null; | |
| 16 | } |
Software/so101/src/ui/hold-line.test.ts added +55
| @@ -0,0 +1,55 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { holdText, warnText } from "./hold-line.js"; | |
| 3 | ||
| 4 | const say = (v: unknown) => `<${String(v)}>`; | |
| 5 | const names = { 1: "shoulder_pan", 6: "gripper" }; | |
| 6 | ||
| 7 | describe("which notices take the status strip's hold row", () => { | |
| 8 | test("reconnecting", () => { | |
| 9 | const h = holdText({ reconnecting: true, seenAt: 0 }, say, names)!; | |
| 10 | expect(h.bad).toBe(false); | |
| 11 | expect(h.text).toStartWith("Reconnecting to the arm…"); | |
| 12 | }); | |
| 13 | test("the arm unreachable for over a minute", () => { | |
| 14 | expect(holdText({ source: "simulated: offline (x)" }, say, names)).toEqual({ bad: true, text: expect.stringContaining("unreachable for over a minute") }); | |
| 15 | expect(holdText({ source: "live" }, say, names)).toBeNull(); | |
| 16 | }); | |
| 17 | test("a jam names the joints", () => { | |
| 18 | expect(holdText({ jammed: [1, 6] }, say, names)).toEqual({ bad: true, text: expect.stringContaining("jam: shoulder_pan, gripper") }); | |
| 19 | expect(holdText({ jammed: [] }, say, names)).toBeNull(); | |
| 20 | }); | |
| 21 | test("an enforce boundary hold", () => { | |
| 22 | expect(holdText({ blocked: "b", zone: "enforce" }, say, names)).toEqual({ bad: true, text: "held at the boundary: <b>" }); | |
| 23 | }); | |
| 24 | test("warn-mode and off-mode blocks, a violation, and nothing are not holds", () => { | |
| 25 | expect(holdText({ blocked: "b", zone: "warn" }, say, names)).toBeNull(); | |
| 26 | expect(holdText({ blocked: "b", zone: "off" }, say, names)).toBeNull(); | |
| 27 | expect(holdText({ violation: "v", zone: "warn" }, say, names)).toBeNull(); | |
| 28 | expect(holdText({}, say, names)).toBeNull(); | |
| 29 | }); | |
| 30 | test("reconnecting wins over a jam, so one line shows", () => { | |
| 31 | expect(holdText({ reconnecting: true, jammed: [1] }, say, names)!.text).toStartWith("Reconnecting"); | |
| 32 | }); | |
| 33 | }); | |
| 34 | ||
| 35 | describe("what stays in the banner", () => { | |
| 36 | test("warn-only lines", () => { | |
| 37 | expect(warnText({ blocked: "b", zone: "warn" }, say)).toBe("warning: <b>"); | |
| 38 | expect(warnText({ violation: "v", zone: "warn" }, say)).toBe("the arm is <v> (zone: warn)"); | |
| 39 | expect(warnText({}, say)).toBeNull(); | |
| 40 | }); | |
| 41 | }); | |
| 42 | ||
| 43 | const html = await Bun.file(new URL("../viewer.html", import.meta.url)).text(); | |
| 44 | const banner = /function banner\(d\) \{[\s\S]*?\n \}\n/.exec(html)![0]; | |
| 45 | ||
| 46 | describe("the page wires banner() to them", () => { | |
| 47 | test("holds go to #holdLine, warnings to #banner, and a stop clears the row", () => { | |
| 48 | expect(html).toContain('from "/ui/__VERSION__/hold-line.js"'); | |
| 49 | expect(banner).toMatch(/holdText\(d, say, NAMES\)/); | |
| 50 | expect(banner).toMatch(/\$\("holdLine"\);\s*h\.textContent = hold\?\.text \?\? ""/); | |
| 51 | expect(banner).toMatch(/warnText\(d, say\)/); | |
| 52 | expect(banner.match(/\$\("holdLine"\)\.textContent = ""/g)?.length).toBe(2); // estop and manual hold | |
| 53 | expect(banner).not.toMatch(/b\.textContent = hold/); // a hold never lands in the banner | |
| 54 | }); | |
| 55 | }); |
Software/so101/src/viewer.html +13 −7
| @@ -92,6 +92,8 @@ | ||
| 92 | 92 | #capLine { color: var(); font-size: 12px; } #capLine:empty { display: none; } |
| 93 | 93 | #armLine { display: none; gap: 6px; align-items: center; color: var(); font-size: 12px; white-space: nowrap; } #armText { min-width: 0; overflow: hidden; text-overflow: ellipsis; } /* shown on a phone held upright (ui/mobile.css) */ |
| 94 | 94 | #reconnect { align-self: flex-start; padding: 0 8px; border-radius: 9px; font-size: 11px; line-height: 16px; background: var(); color: #000; visibility: hidden; } #reconnect.on { visibility: visible; } |
| 95 | /* a safety hold's own row: space is reserved (three lines) whether or not one shows, so the strip, and the camera box under it, never change size */ | |
| 96 | #holdLine { box-sizing: content-box; min-height: 3.6em; margin-top: 2px; font-size: 12px; line-height: 1.2; color: var(); white-space: normal; overflow-wrap: anywhere; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; } #holdLine.bad { color: var(); } | |
| 95 | 97 | #driverLine.paused { color: var(); } |
| 96 | 98 | #turnActions { display: flex; gap: 6px; } #turnActions:empty { display: none; } |
| 97 | 99 | .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); } |
| @@ -316,7 +318,7 @@ | ||
| 316 | 318 | |
| 317 | 319 | <section id="strip" aria-label="Who drives" aria-live="polite"> |
| 318 | 320 | <div id="ring" hidden aria-hidden="true"><span id="ringN"></span></div> |
| 319 | <div class="who"><div id="driverLine" class="none">Connecting…</div><span id="reconnect" role="status">reconnecting…</span><div id="clock" aria-live="off"></div><div id="capLine"></div><div id="armLine" aria-live="off"><span class="dot" id="armDot"></span><span id="armText"></span></div></div> | |
| 321 | <div class="who"><div id="driverLine" class="none">Connecting…</div><span id="reconnect" role="status">reconnecting…</span><div id="clock" aria-live="off"></div><div id="capLine"></div><div id="holdLine"></div><div id="armLine" aria-live="off"><span class="dot" id="armDot"></span><span id="armText"></span></div></div> | |
| 320 | 322 | <div id="turnActions"></div> |
| 321 | 323 | <button id="sheetToggle" hidden aria-controls="sheet" aria-expanded="true">Hide</button> |
| 322 | 324 | <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> |
| @@ -521,6 +523,7 @@ | ||
| 521 | 523 | import { cameraPlan, QUALITIES, samePlan } from "/ui/__VERSION__/camera-plan.js"; |
| 522 | 524 | import { bindSurface, canDrive, Driver, shape, UP } from "/ui/__VERSION__/drive.js"; |
| 523 | 525 | import { Frames } from "/ui/__VERSION__/frames.js"; |
| 526 | import { holdText, warnText } from "/ui/__VERSION__/hold-line.js"; | |
| 524 | 527 | import { createRoom } from "/ui/__VERSION__/lobby-panel.js"; |
| 525 | 528 | |
| 526 | 529 | const $ = (id) => document.getElementById(id); |
| @@ -1650,12 +1653,14 @@ | ||
| 1650 | 1653 | const b = $("banner"); |
| 1651 | 1654 | const say = sayViolation; |
| 1652 | 1655 | if (d.estop) { |
| 1656 | $("holdLine").textContent = ""; | |
| 1653 | 1657 | b.dataset.held = ""; |
| 1654 | 1658 | b.className = "stop"; |
| 1655 | 1659 | b.replaceChildren(`EMERGENCY STOP by ${d.estop.by} at ${new Date(d.estop.at).toLocaleTimeString()}. The arm holds with torque on until an admin clears it.`); |
| 1656 | 1660 | if (isOwner()) b.append(el("button", { textContent: "Clear the stop", className: "danger", onclick: clearEStop })); |
| 1657 | 1661 | return; |
| 1658 | 1662 | } |
| 1663 | if (d.held) $("holdLine").textContent = ""; | |
| 1659 | 1664 | // Built once per hold: a button replaced under a finger is never clicked. |
| 1660 | 1665 | const key = d.held ? `${d.held.by} ${d.held.at} ${mayDrive() || isOwner()}` : ""; |
| 1661 | 1666 | if (key && b.dataset.held === key) return; |
| @@ -1666,12 +1671,13 @@ | ||
| 1666 | 1671 | if (mayDrive() || isOwner()) b.append(el("button", { id: "resume", textContent: resumeArmed ? "Tap again to resume" : "Resume driving", className: "go", onclick: (e) => resume(e.currentTarget) })); |
| 1667 | 1672 | return; |
| 1668 | 1673 | } |
| 1669 | 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; } | |
| 1670 | 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; } | |
| 1671 | 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`; } | |
| 1672 | else if (d.blocked) { b.className = d.zone === "enforce" ? "bad" : "warn"; b.textContent = `${d.zone === "enforce" ? "held at the boundary" : "warning"}: ${say(d.blocked)}`; } | |
| 1673 | else if (d.violation) { b.className = "warn"; b.textContent = `the arm is ${say(d.violation)} (zone: ${d.zone})`; } | |
| 1674 | else b.className = ""; | |
| 1674 | const hold = holdText(d, say, NAMES); | |
| 1675 | const h = $("holdLine"); | |
| 1676 | h.textContent = hold?.text ?? ""; h.className = hold?.bad ? "bad" : ""; | |
| 1677 | if (hold) { b.className = ""; return; } | |
| 1678 | const warn = warnText(d, say); | |
| 1679 | b.className = warn ? "warn" : ""; | |
| 1680 | if (warn) b.textContent = warn; | |
| 1675 | 1681 | } |
| 1676 | 1682 | /** The arm's status, from /live (pushed when it changes) or, without it, from polling /status. */ |
| 1677 | 1683 | // Until the limits, the settings and the model are in, a status is kept aside, not drawn; then it is applied whole, |
new above
offline
This checks CSS text only; it would pass with the banner() wiring deleted. Add a behavioural test of which hold lands in #holdLine and which stays in #banner.