Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
/status names who is driving, including the owner after a take-over #174
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/160-status-names-who-is-driving-including-th → main 2 commits fork 2 threads · 2 unresolved
5 files
changed +47
−3
Software/README.md +5 −1
| @@ -226,7 +226,11 @@ into the page (`<script type="application/json" id="boot">`), so the camera | ||
| 226 | 226 | starts as soon as the script runs. The arm's limits, settings, poses and |
| 227 | 227 | model are all requested at once after that. One WebSocket, `/live`, carries |
| 228 | 228 | the turn, the queue, the chat and the arm's status. The status is pushed only |
| 229 | when it changes, so a page whose socket is open doesn't poll `/status`. A new | |
| 229 | when it changes, so a page whose socket is open doesn't poll `/status`. `/status` and that push both carry | |
| 230 | `driver`: `{id, name, owner}` of whoever holds the turn, or `null` when nobody | |
| 231 | does. The owner shows as driving after a take-over. A 503 while the arm link | |
| 232 | is reconnecting has no status and so no `driver`. The terminal (`src/tty.ts`) | |
| 233 | has no status view, so there is nothing to add there. A new | |
| 230 | 234 | page gets the last 30 chat lines; **Earlier messages** fetches 50 more at a |
| 231 | 235 | time. The camera follows the connection (`src/ui/camera-plan.js`). On a slow |
| 232 | 236 | link (round trips over 400 ms, or the browser reporting 3G or a low |
Software/so101/src/admin-relay.test.ts +18
| @@ -102,3 +102,21 @@ test("reading /link never changes anything; the arm server switches when the set | ||
| 102 | 102 | expect(after.host).toBe("127.0.0.1:1"); |
| 103 | 103 | expect(await (await fetch(`${base}/link`)).json()).toEqual(after); |
| 104 | 104 | }); |
| 105 | ||
| 106 | test("/status names who is driving: null, then alice, then the owner after a take-over", async () => { | |
| 107 | const sim = Bun.serve({ port: 0, fetch: () => Response.json({ joints: [] }) }); | |
| 108 | try { | |
| 109 | dir = mkdtempSync(join(tmpdir(), "so101-admin-relay-")); | |
| 110 | lobby = new Lobby({ identityKey: KEY, adminFile: join(dir, "admin.json") }); | |
| 111 | relay = await startRelay({ port: 0, simulation: `http://127.0.0.1:${sim.port}`, lobby }); | |
| 112 | const base = `http://127.0.0.1:${relay.port}`; | |
| 113 | const driver = async () => ((await (await fetch(`${base}/status`)).json()) as { driver: unknown }).driver; | |
| 114 | expect(await driver()).toBeNull(); | |
| 115 | lobby.takeControl({ id: "id-alice", name: "alice", owner: false }); | |
| 116 | expect(await driver()).toEqual({ id: "id-alice", name: "alice", owner: false }); | |
| 117 | lobby.takeControl({ id: "id-trevato", name: "trevato", owner: true }); | |
| 118 | expect(await driver()).toEqual({ id: "id-trevato", name: "trevato", owner: true }); | |
| 119 | } finally { | |
| 120 | sim.stop(true); | |
| 121 | } | |
| 122 | }); |
Software/so101/src/lobby.test.ts +12
| @@ -329,6 +329,18 @@ describe("lobby", () => { | ||
| 329 | 329 | expect((await moved).status.joints[0].position).toBe(first.status.joints[0].position + 100); |
| 330 | 330 | }); |
| 331 | 331 | |
| 332 | test("the status pushed on /live names the driver, and pushes again when the turn changes hands", async () => { | |
| 333 | const port = await start(); | |
| 334 | const watcher = await join(port); | |
| 335 | expect((await watcher.first((m) => m.type === "status")).status.driver).toBeNull(); | |
| 336 | const alice = await join(port, ALICE); | |
| 337 | alice.send({ type: "join" }); | |
| 338 | expect((await watcher.next((m) => m.type === "status" && m.status.driver?.name === "alice")).status.driver).toEqual({ id: "u-alice", name: "alice", owner: false }); | |
| 339 | const owner = await join(port, OWNER); | |
| 340 | owner.send({ type: "join" }); | |
| 341 | expect((await watcher.next((m) => m.type === "status" && m.status.driver?.owner === true)).status.driver).toEqual({ id: "u-owner", name: "trevato", owner: true }); | |
| 342 | }); | |
| 343 | ||
| 332 | 344 | test("the driver and any admin may hit the emergency stop; only an admin clears it or changes the settings", async () => { |
| 333 | 345 | const port = await start(); |
| 334 | 346 | const alice = await join(port, ALICE); |
Software/so101/src/relay.test.ts +3 −1
| @@ -233,7 +233,9 @@ describe("relay", () => { | ||
| 233 | 233 | expect(l.problem).toContain("unreachable"); |
| 234 | 234 | const s = await fetch(`${base}/status`); |
| 235 | 235 | expect(s.status).toBe(503); |
| 236 | expect(await s.json()).toMatchObject({ reconnecting: true, source: expect.stringContaining(`reconnecting to the arm: 127.0.0.1:${port}`) }); | |
| 236 | const refused = (await s.json()) as Record<string, unknown>; | |
| 237 | expect(refused).toMatchObject({ reconnecting: true, source: expect.stringContaining(`reconnecting to the arm: 127.0.0.1:${port}`) }); | |
| 238 | expect("driver" in refused).toBe(false); // nothing to say about the turn when there is no status to say it in | |
| 237 | 239 | expect((await fetch(`${base}/move`, { method: "POST", body: '{"targets":{"1":2000}}' })).status).toBe(503); |
| 238 | 240 | await sleep(650); |
| 239 | 241 | expect((await link(base)).mode).toBe("offline"); |
Software/so101/src/relay.ts +9 −1
| @@ -358,9 +358,17 @@ export async function startRelay(options: RelayOptions): Promise<RunningRelay> { | ||
| 358 | 358 | const clocks = new Map<string, Clock>(); |
| 359 | 359 | /** |
| 360 | 360 | * The arm's /status, saying which arm it is: from the link while it is live, the last one it had while reconnecting, |
| 361 | * and from the simulation otherwise. | |
| 361 | * and from the simulation otherwise. It also adds `driver`, {id, name, owner} of whoever holds the turn (the owner | |
| 362 | * after a take-over) or null, to every answer that has a status; the 503 has none. /status and the /live push share it. | |
| 362 | 363 | */ |
| 363 | 364 | const statusOf = async (path = "/status"): Promise<{ code: number; body: Record<string, unknown> }> => { |
outdated
Name this wrapper's job in the doc comment above: it now also adds |
||
| 365 | const answer = await ownStatus(path); | |
| 366 | const d = lobby?.turns.snapshot().driver; | |
| 367 | if (answer.code === 200) answer.body.driver = d ? { id: d.id, name: d.name, owner: d.owner } : null; | |
| 368 | return answer; | |
| 369 | }; | |
| 370 | /** The arm's status alone, with no word of the turn. */ | |
| 371 | const ownStatus = async (path: string): Promise<{ code: number; body: Record<string, unknown> }> => { | |
| 364 | 372 | if (onArm()) { |
| 365 | 373 | const last = armLink!.last; |
| 366 | 374 | const reconnecting = mode() === "reconnecting"; |
new above
offline
This only covers GET /status. Add the /live push, which is the other path through statusOf, and check that a reconnecting 503 carries no driver.