Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
Exactly one STOP on every layout: red, >= 56 px, fires on pointerdown, resume asks for a second tap, a full-width stopped banner #101
quill/arm:quill/91-exactly-one-stop-on-every-layout-red-56 → main 1 commit fork
6 files
changed +145
−6
Software/README.md +9 −3
| @@ -237,9 +237,15 @@ at a time. The **Auto / Saver / Full** button in the top bar overrides this, | ||
| 237 | 237 | and the choice is kept in the browser. A hidden page (another tab, a locked |
| 238 | 238 | phone) fetches no video at all. |
| 239 | 239 | |
| 240 | There is one **Stop** on screen: the red emergency stop. A second button | |
| 241 | appears only while a move, a playback, a recording or a park is running, and | |
| 242 | says which one it ends (**End playback**, …). It holds the arm where it is. | |
| 240 | There is one **Stop** on screen, in every layout: the red emergency stop, at | |
| 241 | least 56 px, in the status strip. It acts on the press (pointerdown), not the | |
| 242 | release, and ends whatever runs: a move, a playback, a recording, a park, | |
| 243 | teleop. While the arm is held a red banner spans the whole view and says who | |
| 244 | stopped it; its **Resume driving** asks for a second tap before it resumes. | |
| 245 | `src/stop-layout.test.ts` checks this in Chromium at 390x844 and 412x915, upright | |
| 246 | and sideways, and on a desktop, through `playwright-core` (a dev dependency for | |
| 247 | that test only: it drives the system's Chromium, `CHROMIUM_PATH` to name | |
| 248 | another, and downloads no browser). | |
| 243 | 249 | |
| 244 | 250 | **Cameras are a list the owner edits** on `/admin/camera-list` (name + source, such as |
| 245 | 251 | `<arm host>:8080`), kept in `cameras.json` under `FORGE_APP_DATA`; the first |
Software/so101/bun.lock +3
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | "devDependencies": { |
| 14 | 14 | "@types/bun": "^1.4.2", |
| 15 | 15 | "@types/ws": "^8.18.2", |
| 16 | "playwright-core": "^1.64.1", | |
| 16 | 17 | "typescript": "^7.0.2", |
| 17 | 18 | }, |
| 18 | 19 | }, |
| @@ -102,6 +103,8 @@ | ||
| 102 | 103 | |
| 103 | 104 | "node-gyp-build": ["[email protected]", "", { "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", "node-gyp-build-test": "build-test.js" } }, "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ=="], |
| 104 | 105 | |
| 106 | "playwright-core": ["[email protected]", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ=="], | |
| 107 | ||
| 105 | 108 | "serialport": ["[email protected]", "", { "dependencies": { "@serialport/binding-mock": "10.2.2", "@serialport/bindings-cpp": "13.0.0", "@serialport/parser-byte-length": "13.0.0", "@serialport/parser-cctalk": "13.0.0", "@serialport/parser-delimiter": "13.0.0", "@serialport/parser-inter-byte-timeout": "13.0.0", "@serialport/parser-packet-length": "13.0.0", "@serialport/parser-readline": "13.0.0", "@serialport/parser-ready": "13.0.0", "@serialport/parser-regex": "13.0.0", "@serialport/parser-slip-encoder": "13.0.0", "@serialport/parser-spacepacket": "13.0.0", "@serialport/stream": "13.0.0", "debug": "4.4.0" } }, "sha512-PHpnTd8isMGPfFTZNCzOZp9m4mAJSNWle9Jxu6BPTcWq7YXl5qN7tp8Sgn0h+WIGcD6JFz5QDgixC2s4VW7vzg=="], |
| 106 | 109 | |
| 107 | 110 | "three": ["[email protected]", "", {}, "sha512-blFeqb49wRCSGUGj7gtpfnSGHy2lwDk94RhUmS1c/hTby70kvChbWpkJ4Pm1390LqzzvTmzgXKHPEafJwCb8jA=="], |
Software/so101/package.json +1
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | "devDependencies": { |
| 21 | 21 | "@types/bun": "^1.4.2", |
| 22 | 22 | "@types/ws": "^8.18.2", |
| 23 | "playwright-core": "^1.64.1", | |
| 23 | 24 | "typescript": "^7.0.2" |
| 24 | 25 | } |
| 25 | 26 | } |
Software/so101/src/server.test.ts +2
| @@ -212,6 +212,8 @@ describe("viewer page", () => { | ||
| 212 | 212 | expect(page).toContain('api("/resume", {})'); |
| 213 | 213 | expect(page).toContain("Resume driving"); |
| 214 | 214 | expect(page.match(/>Stop</g)?.length).toBe(1); |
| 215 | expect(page).toMatch(/\.estop \{[^}]*min-height: (5[6-9]|[6-9]\d)px/); // a thumb-sized STOP, at least 56 px | |
| 216 | expect(page).toMatch(/#banner\.stop \{[^}]*left: 0; right: 0;[^}]*max-width: none/); // stopped: edge to edge | |
| 215 | 217 | }); |
| 216 | 218 | }); |
| 217 | 219 |
Software/so101/src/stop-layout.test.ts added +125
| @@ -0,0 +1,125 @@ | ||
| 1 | /** | |
| 2 | * One STOP on every layout (issue #91), in a real browser: on two phones, upright and on their side, and on a desktop, | |
| 3 | * exactly one `[data-stop]` is visible and in reach; it is red and at least 56 px; a pointerdown on it holds the arm | |
| 4 | * (no click needed); while held a full-width banner says so; and resume takes a second, confirming tap. | |
| 5 | * | |
| 6 | * Chromium comes from CHROMIUM_PATH, the system's chromium, or Playwright's own download; with none, the suite is | |
| 7 | * skipped and says so; so it is where unix sockets may not be bound (FORGE_TEST_SOCKET), which Chromium needs. | |
| 8 | */ | |
| 9 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 10 | import { existsSync, mkdtempSync } from "node:fs"; | |
| 11 | import { tmpdir } from "node:os"; | |
| 12 | import { join } from "node:path"; | |
| 13 | import { chromium, type Browser, type BrowserContext, type Page } from "playwright-core"; | |
| 14 | import { FeetechBus } from "./bus.ts"; | |
| 15 | import { FakeBus } from "./fake-bus.ts"; | |
| 16 | import { startServer, type RunningServer } from "./server.ts"; | |
| 17 | ||
| 18 | const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)); | |
| 19 | const shut = (s: { close(): Promise<void> } | undefined) => (s ? Promise.race([s.close(), sleep(500)]) : undefined); | |
| 20 | ||
| 21 | function findChromium(): string | null { | |
| 22 | const named = process.env.CHROMIUM_PATH; | |
| 23 | if (named) return existsSync(named) ? named : null; | |
| 24 | for (const p of ["/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome"]) if (existsSync(p)) return p; | |
| 25 | try { | |
| 26 | const p = chromium.executablePath(); | |
| 27 | return existsSync(p) ? p : null; | |
| 28 | } catch { | |
| 29 | return null; | |
| 30 | } | |
| 31 | } | |
| 32 | // Chromium needs a unix socket for its own processes: where tests may not bind one (FORGE_TEST_SOCKET), it cannot start. | |
| 33 | const executablePath = process.env.FORGE_TEST_SOCKET ? null : findChromium(); | |
| 34 | if (!executablePath) console.warn(`stop-layout.test.ts: skipped, ${process.env.FORGE_TEST_SOCKET ? "no unix sockets here (FORGE_TEST_SOCKET)" : "no chromium (set CHROMIUM_PATH)"}`); | |
| 35 | ||
| 36 | const PHONE = { isMobile: true, hasTouch: true, deviceScaleFactor: 2 }; | |
| 37 | const LAYOUTS: Array<{ name: string; viewport: { width: number; height: number }; touch: boolean }> = [ | |
| 38 | { name: "390x844 portrait", viewport: { width: 390, height: 844 }, touch: true }, | |
| 39 | { name: "844x390 landscape", viewport: { width: 844, height: 390 }, touch: true }, | |
| 40 | { name: "412x915 portrait", viewport: { width: 412, height: 915 }, touch: true }, | |
| 41 | { name: "915x412 landscape", viewport: { width: 915, height: 412 }, touch: true }, | |
| 42 | { name: "1440x900 desktop", viewport: { width: 1440, height: 900 }, touch: false }, | |
| 43 | ]; | |
| 44 | ||
| 45 | describe.skipIf(!executablePath)("one STOP on every layout, in a browser", () => { | |
| 46 | let server: RunningServer; | |
| 47 | let base: string; | |
| 48 | let browser: Browser; | |
| 49 | beforeAll(async () => { | |
| 50 | const dir = mkdtempSync(join(tmpdir(), "so101-stop-layout-")); | |
| 51 | server = await startServer(new FeetechBus(new FakeBus([1, 2, 3, 4, 5, 6])), { host: "127.0.0.1", port: 0, ids: [1, 2, 3, 4, 5, 6], posesFile: join(dir, "poses.json"), modelDir: new URL("../../../Simulation/SO101", import.meta.url).pathname }); | |
| 52 | base = `http://127.0.0.1:${server.port}`; | |
| 53 | browser = await chromium.launch({ executablePath: executablePath!, args: ["--no-sandbox", "--disable-gpu"] }); | |
| 54 | }, 30_000); | |
| 55 | afterAll(async () => { | |
| 56 | await browser?.close(); | |
| 57 | await shut(server); | |
| 58 | }); | |
| 59 | ||
| 60 | const held = async () => ((await (await fetch(`${base}/status`)).json()) as { held: { by: string } | null }).held; | |
| 61 | const open = async (layout: (typeof LAYOUTS)[number]): Promise<{ context: BrowserContext; page: Page }> => { | |
| 62 | const context = await browser.newContext({ viewport: layout.viewport, ...(layout.touch ? PHONE : {}) }); | |
| 63 | const page = await context.newPage(); | |
| 64 | await page.goto(`${base}/`); | |
| 65 | // the page has its status once the stop knows whether it is held | |
| 66 | await page.waitForFunction(`document.getElementById("dot")?.classList.contains("on")`, null, { timeout: 15_000 }); | |
| 67 | return { context, page }; | |
| 68 | }; | |
| 69 | /** Every visible stop: drawn, not hidden by display, visibility or opacity; where it is, and whether a finger lands on it. */ | |
| 70 | const visibleStops = (page: Page) => | |
| 71 | page.evaluate(`[...document.querySelectorAll("[data-stop]")] | |
| 72 | .filter((b) => { const r = b.getBoundingClientRect(), s = getComputedStyle(b); return r.width > 0 && r.height > 0 && s.visibility !== "hidden" && s.display !== "none" && Number(s.opacity) > 0; }) | |
| 73 | .map((b) => { | |
| 74 | const r = b.getBoundingClientRect(), on = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); | |
| 75 | return { width: r.width, height: r.height, inView: r.top >= 0 && r.left >= 0 && r.bottom <= innerHeight && r.right <= innerWidth, reachable: on === b || b.contains(on), background: getComputedStyle(b).backgroundColor }; | |
| 76 | })`) as Promise<Array<{ width: number; height: number; inView: boolean; reachable: boolean; background: string }>>; | |
| 77 | /** The banner, and how far it stops short of each side of the view it sits on. */ | |
| 78 | const banner = (page: Page) => | |
| 79 | page.evaluate(`(() => { | |
| 80 | const r = document.getElementById("banner").getBoundingClientRect(), view = document.getElementById("app").getBoundingClientRect(); | |
| 81 | return { text: document.getElementById("banner").textContent, left: r.left - view.left, right: view.right - r.right }; | |
| 82 | })()`) as Promise<{ text: string; left: number; right: number }>; | |
| 83 | ||
| 84 | for (const layout of LAYOUTS) { | |
| 85 | test(`${layout.name}: exactly one visible STOP, red, ${layout.touch ? ">= 56 px, " : ""}fires on pointerdown; a full-width banner while held; resume takes two taps`, async () => { | |
| 86 | const { context, page } = await open(layout); | |
| 87 | try { | |
| 88 | const stops = await visibleStops(page); | |
| 89 | expect(stops.length).toBe(1); | |
| 90 | const stop = stops[0]!; | |
| 91 | expect({ inView: stop.inView, reachable: stop.reachable }).toEqual({ inView: true, reachable: true }); | |
| 92 | const [r, g, b] = stop.background.match(/\d+/g)!.map(Number) as [number, number, number]; | |
| 93 | expect(r).toBeGreaterThan(180); // red: a strong red channel, the others well under it | |
| 94 | expect(Math.max(g, b)).toBeLessThan(r / 2); | |
| 95 | if (layout.touch) expect(Math.min(stop.width, stop.height)).toBeGreaterThanOrEqual(56); | |
| 96 | ||
| 97 | // A pointerdown alone holds the arm: no pointerup, no click. | |
| 98 | expect(await held()).toBeNull(); | |
| 99 | await page.dispatchEvent("[data-stop]", "pointerdown", { button: 0, isPrimary: true, pointerType: layout.touch ? "touch" : "mouse", bubbles: true }); | |
| 100 | for (let i = 0; i < 50 && !(await held()); i++) await sleep(20); | |
| 101 | expect(await held()).not.toBeNull(); | |
| 102 | ||
| 103 | await page.waitForSelector("#banner.stop #resume", { timeout: 5000 }); | |
| 104 | // The banner spans the view it sits on, edge to edge, and says the arm is stopped. | |
| 105 | const shown = await banner(page); | |
| 106 | expect(shown.text).toContain("STOPPED"); | |
| 107 | expect({ left: shown.left, right: shown.right }).toEqual({ left: 0, right: 0 }); | |
| 108 | // Still exactly one STOP while held. | |
| 109 | expect((await visibleStops(page)).length).toBe(1); | |
| 110 | ||
| 111 | // One tap on resume only asks; the arm stays held. The second tap resumes. | |
| 112 | await page.click("#resume"); | |
| 113 | expect(await page.textContent("#resume")).toBe("Tap again to resume"); | |
| 114 | await sleep(100); | |
| 115 | expect(await held()).not.toBeNull(); | |
| 116 | await page.click("#resume"); | |
| 117 | for (let i = 0; i < 50 && (await held()); i++) await sleep(20); | |
| 118 | expect(await held()).toBeNull(); | |
| 119 | } finally { | |
| 120 | await context.close(); | |
| 121 | await fetch(`${base}/resume`, { method: "POST", body: "{}" }); | |
| 122 | } | |
| 123 | }, 30_000); | |
| 124 | } | |
| 125 | }); |
Software/so101/src/viewer.html +5 −3
| @@ -61,8 +61,10 @@ | ||
| 61 | 61 | #stage { position: absolute; inset: 0; display: flex; gap: 2px; } |
| 62 | 62 | /* the emergency stop's held state, and the banner that says who pressed it */ |
| 63 | 63 | .estop:disabled { opacity: .5; cursor: not-allowed; } .estop.on { background: #7d1410; box-shadow: 0 0 0 3px var(); } |
| 64 | #banner.stop { display: block; border: 2px solid var(); background: rgba(80,10,8,.92); color: #fff; font-weight: 600; } | |
| 64 | /* stopped: the banner spans the whole view, edge to edge, so nobody misses that the arm is held */ | |
| 65 | #banner.stop { display: block; left: 0; right: 0; width: auto; max-width: none; transform: none; border-radius: 0; border: 0; border-block: 2px solid var(); padding: 10px calc(12px + var()) 10px calc(12px + var()); background: rgba(80,10,8,.92); color: #fff; font-size: 14px; font-weight: 600; text-align: center; } | |
| 65 | 66 | #banner button { margin-left: 10px; min-height: 32px; padding: 2px 10px; } |
| 67 | #banner #resume { min-height: 44px; padding: 0 16px; font-weight: 700; } | |
| 66 | 68 | .pane { flex: 1; min-width: 0; position: relative; background: #000; display: none; } |
| 67 | 69 | .pane.on { display: block; } |
| 68 | 70 | .pane img { width: 100%; height: 100%; object-fit: contain; display: block; } |
| @@ -88,7 +90,7 @@ | ||
| 88 | 90 | #capLine { color: var(); font-size: 12px; } #capLine:empty { display: none; } |
| 89 | 91 | #driverLine.paused { color: var(); } |
| 90 | 92 | #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); } | |
| 93 | .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); } | |
| 92 | 94 | .estop:hover { background: #e5323d; } .estop:active { transform: scale(.97); } |
| 93 | 95 | #sheetToggle { flex: none; } |
| 94 | 96 | /* the turn ring: time left as a sweep around the seconds; the driver's name over the video for everyone */ |
| @@ -276,7 +278,7 @@ | ||
| 276 | 278 | #shell.bare #sheet { transform: translateX(100%); visibility: hidden; transition: transform .2s ease-out, visibility 0s .2s; } |
| 277 | 279 | #top { top: auto; bottom: 6px; justify-content: flex-start; right: calc(min(380px, 48vw) + 12px + var()); } |
| 278 | 280 | #shell.bare #top { right: calc(var() + var()); } |
| 279 | #banner { top: 64px; } | |
| 281 | #banner { top: 64px; } #banner.stop { top: 84px; } | |
| 280 | 282 | #msg { bottom: 52px; } |
| 281 | 283 | .tab { padding-top: 8px; } |
| 282 | 284 | #pad { width: min(30vh, 150px); } |
new above
offline