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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Precision, forever: calibrate the model to the arm, tune the servos against the scorecard, report weekly #441

Parked opened this in answer to
Closed without merging

smith/arm:smith/439-precision-forever-calibrate-the-model-to → main 7 commits fork 2 threads · 2 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
11 files changed +183 −15
Software/README.md +7
@@ -543,6 +543,13 @@ watches. A line you type is said in the chat; commands start with `/`:
543543 `POST /settings/table-here`: the table plane goes under the arm's lowest
544544 link now. `/table <mm>`, owner: sets `tableOffsetMm` (-100 to 100) by
545545 `PUT /settings`. Both print the offset the server now holds, or its refusal.
546 - `/table touch`, owner: the page's "Touch the table (3 points)", the same
547 `POST /settings/table-touch`. Put the arm on the table, call it, move to
548 another point, and again; the third call sets `tableOffsetMm` from the mean
549 of the three lowest-link heights less the floor margin (to the whole mm), or
550 is refused, naming why, when the three differ by over 5 mm. A touch is kept
551 for 60 s; `/table reset` (the page's "Start the touches over") drops
552 them. `/table here` and the three touches round down to the whole mm the same way, so the table is never above the arm.
546553 - `/zero <joint> [degrees]`, owner: `POST /settings/joint-zero` for that joint
547554 (default 0°); prints the offset applied, or the refusal.
548555 - `/machine`: the Machine panel, the same rows the page's Machine tab shows
Software/so101/src/admin-page.test.ts +3
@@ -28,6 +28,9 @@ test("the Table height field is the owner's alone", () => {
2828 expect(owner).toContain('id="table-save"');
2929 expect(owner).toContain('id="table-here"');
3030 expect(owner).toContain("/settings/table-here");
31 expect(owner).toContain('id="table-touch"');
32 expect(owner).toContain('id="table-reset"');
33 expect(owner).toContain("/settings/table-touch");
3134 const mod = page(false);
3235 expect(mod).not.toContain("table-here");
3336 expect(mod).not.toContain("table-mm");
Software/so101/src/admin-page.ts +15 −1
@@ -109,6 +109,20 @@ const TABLE_SCRIPT = `
109109 say("The table is here: " + s.tableOffsetMm + " mm.");
110110 } catch (e) { say(e.message); }
111111 });
112 document.getElementById("table-touch").addEventListener("click", async () => {
113 try {
114 const s = await settings({ method: "POST", url: "/settings/table-touch", headers: { "content-type": "application/json" }, body: "{}" });
115 if (s.tableOffsetMm === undefined) return say("Touch " + s.touches + " of " + s.of + " (each is kept for a minute): move the arm onto another point of the table and touch again.");
116 input.value = String(s.tableOffsetMm);
117 say("Three touches agree within " + s.spreadMm + " mm. The table is here: " + s.tableOffsetMm + " mm.");
118 } catch (e) { say(e.message); }
119 });
120 document.getElementById("table-reset").addEventListener("click", async () => {
121 try {
122 await settings({ method: "POST", url: "/settings/table-touch", headers: { "content-type": "application/json" }, body: JSON.stringify({ reset: true }) });
123 say("Touches cleared. Touch the table again from the first point.");
124 } catch (e) { say(e.message); }
125 });
112126 document.getElementById("table-save").addEventListener("click", async () => {
113127 if (!input.reportValidity()) return;
114128 try {
@@ -275,7 +289,7 @@ ${p.canEdit ? `<div class="save"><button class="go">Save settings</button></div>
275289 </section>
276290 ${p.canEdit ? `<section aria-labelledby="table"><h2 id="table">Table height</h2>
277291 <div class="grid"><label>Table height<small>mm above the model's floor, -100 to 100; the safe zone keeps the arm above it</small><input id="table-mm" type="number" inputmode="numeric" min="-100" max="100" step="1"></label></div>
278 <div class="save"><button type="button" class="go" id="table-save">Save</button> <button type="button" id="table-here">The arm rests on the table now</button> <span id="table-note" role="status"></span></div>
292 <div class="save"><button type="button" class="go" id="table-save">Save</button> <button type="button" id="table-here">The arm rests on the table now</button> <button type="button" id="table-touch">Touch the table (3 points)</button> <button type="button" id="table-reset">Start the touches over</button> <span id="table-note" role="status"></span></div>
279293 </section>` : ""}
280294 ${p.canEdit && p.visitors ? visitorsSection(p.visitors) : ""}
281295 ${p.precision !== undefined ? precisionSection(p.precision, esc) : ""}
Software/so101/src/calibration-fit.test.ts added +26
@@ -0,0 +1,26 @@
1 import { expect, test } from "bun:test";
2 import { fitTable } from "./calibration-fit";
3
4 test("three agreeing touches give the table offset less the margin, rounded down to the millimetre", () => {
5 expect(fitTable([30, 31, 29], 15)).toEqual({ offsetMm: 15, spreadMm: 2, ok: true });
6 expect(fitTable([30, 31, 30], 15).offsetMm).toBe(15); // 15.33 rounds down
7 expect(fitTable([31, 31, 30], 15).offsetMm).toBe(15); // 15.67 rounds down too
8 });
9
10 test("touches that disagree are not accepted", () => {
11 const fit = fitTable([20, 40, 30], 15);
12 expect(fit.ok).toBe(false);
13 expect(fit.problem).toContain("differ");
14 });
15
16 test("an offset past ±100 mm is refused; the wrong count throws", () => {
17 expect(fitTable([200, 200, 200], 15).ok).toBe(false);
18 expect(() => fitTable([1, 2], 15)).toThrow();
19 expect(() => fitTable([1, 2, NaN], 15)).toThrow();
20 });
21
22 test("one rounding rule: down to the millimetre, less the margin, so the table is never above the arm", async () => {
23 const { tableOffsetFor } = await import("./calibration-fit");
24 expect(tableOffsetFor(30.4, 15)).toBe(15);
25 expect(tableOffsetFor(30.6, 15)).toBe(15);
26 });
Software/so101/src/calibration-fit.ts added +41
@@ -0,0 +1,41 @@
1 /**
2 * Calibrating the table plane by touching it (#439), apart from the bus and the page.
3 *
4 * The arm touches the table at three points; at each, the model says how high its lowest link is above the model
5 * floor. The table is their mean less the zone's margin, rounded down to the whole millimetre,
6 * and the spread says whether three touches agree (a flat table, the pose right) or the pose in the model is off.
7 */
8
9 export const TABLE_POINTS = 3;
10 export const TABLE_SPREAD_MM = 5;
11 /** The table offset `/settings` accepts, either way. */
12 export const TABLE_RANGE_MM = 100;
13 /** The joint offset `/settings` accepts, either way. */
14 export const JOINT_OFFSET_RANGE_DEG = 30;
15
16 export interface TableFit {
17 offsetMm: number;
18 spreadMm: number;
19 ok: boolean;
20 problem?: string;
21 }
22
23 /** The table offset under a lowest link `heightMm` above the model floor: less the margin, rounded down to the whole millimetre so the table is never above the arm
24 * that touched it (a resting arm is not flagged). One rule for every route. */
25 export const tableOffsetFor = (heightMm: number, marginMm: number): number => Math.floor(heightMm - marginMm);
26
27 /** A touch older than this is forgotten: the pose or the table may have changed since. */
28 export const TOUCH_TTL_MS = 60_000;
29
30 /** `heightsMm`: the lowest link's height above the model floor at each touch. */
31 export function fitTable(heightsMm: readonly number[], marginMm: number): TableFit {
32 if (heightsMm.length !== TABLE_POINTS || heightsMm.some((h) => !Number.isFinite(h))) {
33 throw new RangeError(`touch the table at exactly ${TABLE_POINTS} points`);
34 }
35 const mean = heightsMm.reduce((a, b) => a + b, 0) / TABLE_POINTS;
outdated

Math.floor biases every table offset downward by up to 1 mm and is not documented. Round to the resolution /settings stores, and say so.

36 const spreadMm = Math.max(...heightsMm) - Math.min(...heightsMm);
37 const offsetMm = tableOffsetFor(mean, marginMm);
38 if (Math.abs(offsetMm) > TABLE_RANGE_MM) return { offsetMm, spreadMm, ok: false, problem: `the table would be ${offsetMm} mm from the model's, past ±${TABLE_RANGE_MM}` };
39 if (spreadMm > TABLE_SPREAD_MM) return { offsetMm, spreadMm, ok: false, problem: `the three touches differ by ${spreadMm.toFixed(1)} mm, past ${TABLE_SPREAD_MM}: the pose in the model is off, or the table is not flat` };
40 return { offsetMm, spreadMm, ok: true };
41 }
Software/so101/src/lobby.test.ts +4
@@ -780,6 +780,10 @@ describe("lobby", () => {
780780 expect((await post("/settings/table-here", {})).status).toBe(401);
781781 expect((await post("/settings/table-here", ALICE)).status).toBe(403);
782782 expect((await post("/settings/table-here", OWNER)).status).toBe(200); // an admin gets through
783 expect((await post("/settings/table-touch", {})).status).toBe(401);
784 expect((await post("/settings/table-touch", ALICE)).status).toBe(403);
785 expect((await post("/settings/table-touch", { ...OWNER, origin: "https://evil.example" })).status).toBe(403); // an admin's cookie from another site
786 expect((await post("/settings/table-touch", { ...OWNER, "sec-fetch-site": "cross-site" })).status).toBe(403);
783787 expect((await post("/settings/joint-zero", ALICE)).status).toBe(403);
784788 expect((await post("/settings", OWNER, { tableOffsetMm: 0 }, "PUT")).status).toBe(200);
785789 expect((await post("/settings", OWNER, { maxSpeedDegS: 60 }, "PUT")).status).toBe(200);
Software/so101/src/relay.ts +1 −1
@@ -166,7 +166,7 @@ const PAGE = /^\/(?:index\.html)?$/;
166166 const STATIC = /^\/(?:index\.html)?$|^\/(?:model|vendor|ui)\//;
167167 const LEADER = "/leader/calibration";
168168 /** Admins only: clearing an emergency stop and changing the settings (the safety limits among them). */
169 const ADMIN_ONLY = new Set(["POST /estop/clear", "PUT /settings", "POST /settings/table-here", "POST /settings/joint-zero", "PUT /servo-params", "POST /servo-params/factory"]);
169 const ADMIN_ONLY = new Set(["POST /estop/clear", "PUT /settings", "POST /settings/table-here", "POST /settings/table-touch", "POST /settings/joint-zero", "PUT /servo-params", "POST /servo-params/factory"]);
170170 /** Routes only the owner may reach; anyone else is told there is no such page. */
171171 const OWNER_READS = new Set(["GET /servo-params", "PUT /servo-params", "POST /servo-params/factory"]);
172172 /** The driver's, and any admin's at any time. */
Software/so101/src/server.test.ts +40
@@ -626,6 +626,46 @@ describe("the safe zone, the jam watch, and the model routes", () => {
626626 }
627627 });
628628
629 test("table-touch takes three touches and sets the table from them; touches that differ are refused, naming why", async () => {
630 const saved = (await (await fetch(`${zurl}/settings`)).json()) as { tableOffsetMm: number; zone: string };
631 await zcall("/settings", { zone: "off" }, "PUT"); // the touches below move the arm through the table; no block is counted
632 try {
633 for (const n of [1, 2]) expect(await (await zcall("/settings/table-touch", {})).json()).toEqual({ touches: n, of: 3 });
634 const third = await zcall("/settings/table-touch", {});
635 expect(third.status).toBe(200);
636 const set = (await third.json()) as { tableOffsetMm: number; touches: number; spreadMm: number };
637 expect(set).toMatchObject({ touches: 3, spreadMm: 0 });
638 expect(((await (await fetch(`${zurl}/settings`)).json()) as { tableOffsetMm: number }).tableOffsetMm).toBe(set.tableOffsetMm);
639 // the same pose three times agrees with table-here, the one-touch way,, by one rounding rule
640 const here = (await (await zcall("/settings/table-here", {})).json()) as { tableOffsetMm: number };
641 expect(set.tableOffsetMm).toBe(here.tableOffsetMm);
642 // a reset drops the touches held; {"count": true} reads them without adding one
643 expect(await (await zcall("/settings/table-touch", {})).json()).toEqual({ touches: 1, of: 3 });
644 expect(await (await zcall("/settings/table-touch", { count: true })).json()).toEqual({ touches: 1, of: 3 });
645 expect(await (await zcall("/settings/table-touch", { reset: true })).json()).toEqual({ touches: 0, of: 3 });
646 // a touch is forgotten after a minute
647 await zcall("/settings/table-touch", {});
648 const realNow = Date.now;
649 Date.now = () => realNow() + 61_000;
650 try {
651 expect(await (await zcall("/settings/table-touch", { count: true })).json()).toEqual({ touches: 0, of: 3 });
652 } finally {
653 Date.now = realNow;
654 }
655 // move between touches: the lowest link is no longer at one height
656 expect((await zcall("/settings/table-touch", {})).status).toBe(200);
657 await zcall("/move", { targets: { "2": ticks(2, 40) } });
658 await zcall("/settings/table-touch", {});
659 await zcall("/move", { targets: { "2": ticks(2, 60) } });
660 const refused = await zcall("/settings/table-touch", {});
661 expect(refused.status).toBe(409);
662 expect(((await refused.json()) as { error: string }).error).toMatch(/differ by .* mm.*start again|past ±100/);
663 } finally {
664 await zcall("/move", { targets: { "2": mid(2) } });
665 await zcall("/settings", { zone: saved.zone, tableOffsetMm: saved.tableOffsetMm }, "PUT");
666 }
667 });
668
629669 test("a move into the table is refused in enforce mode and only reported in warn mode", async () => {
630670 const down = { targets: { "2": ticks(2, 80) } }; // shoulder lift far forward with the elbow straight: the gripper goes under the table
631671 const refused = await zcall("/move", down);
Software/so101/src/server.ts +28 −3
@@ -31,6 +31,9 @@
3131 * GET /settings the safe zone: {"zone": "enforce"|"warn"|"off", "floorMarginMm", "baseMarginMm", "jointOffsetsDeg"},
3232 * and the safety limits of src/safety.ts (speed, acceleration, rate, dead-man, park, gripper force, joint limits)
3333 * PUT /settings change any of those
34 * POST /settings/table-touch admin: record the arm's lowest link as one of three touches on the table (each good for 60 s; {"reset": true} drops them,
35 * {"count": true} reads how many are held); the third sets
36 * tableOffsetMm from their mean (src/calibration-fit.ts), or is refused, naming why, when they disagree
3437 * POST /settings/table-here put the table (tableOffsetMm, -100..100) under the arm's lowest link now, the margin below it
3538 * POST /settings/joint-zero {"joint": "shoulder_pan", "referenceDeg": 0} trim that joint's offset so the model reads referenceDeg at the pose it is in now
3639 * (owner only; 409 when the offset would pass ±15°: put the arm at the reference first)
@@ -81,6 +84,7 @@ import { ARRIVE_TICKS, parseSnapBack, type Cause, type Tracker } from "./precisi
8184 import { PrecisionHistory } from "./precision-history.ts";
8285 import { MotionError, moveToPose, playTrajectory, recordTrajectory, STALL_SPAN_TICKS } from "./motion.ts";
8386 import { assertPoseName, parsePoseFile, serializePoseFile, type PoseFile } from "./poses.ts";
87 import { JOINT_OFFSET_RANGE_DEG, TABLE_POINTS, TABLE_RANGE_MM, TOUCH_TTL_MS, fitTable, tableOffsetFor } from "./calibration-fit.ts";
8488 import { MAX_ZERO_OFFSET_DEG, zeroOffsetDeg } from "./joint-zero.ts";
8589 import { JOINTS, registerName, STS3215, ticksToDegrees } from "./sts3215.ts";
8690 import { largestStep, parseTrajectory, serializeTrajectory, type Trajectory } from "./trajectory.ts";
@@ -531,6 +535,9 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}):
531535 }
532536 return [...new Set(value as number[])];
533537 };
538 /** The lowest link's height above the model floor, mm, at each touch of the table so far. */
539 const tableTouches: Array<{ mm: number; at: number }> = [];
540
534541 function validateSettings(s: Partial<Settings>): Settings {
535542 let safety: SafetySettings;
536543 try {
@@ -550,14 +557,14 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}):
550557 out[key] = s[key]!;
551558 }
552559 if (s.tableOffsetMm !== undefined) {
553 if (typeof s.tableOffsetMm !== "number" || !Number.isFinite(s.tableOffsetMm) || s.tableOffsetMm < -100 || s.tableOffsetMm > 100) throw new HttpError(400, "tableOffsetMm must be -100 to 100");
560 if (typeof s.tableOffsetMm !== "number" || !Number.isFinite(s.tableOffsetMm) || Math.abs(s.tableOffsetMm) > TABLE_RANGE_MM) throw new HttpError(400, `tableOffsetMm must be -${TABLE_RANGE_MM} to ${TABLE_RANGE_MM}`);
554561 out.tableOffsetMm = s.tableOffsetMm;
555562 }
556563 if (s.jointOffsetsDeg !== undefined) {
557564 if (typeof s.jointOffsetsDeg !== "object" || s.jointOffsetsDeg === null || Array.isArray(s.jointOffsetsDeg)) throw new HttpError(400, "jointOffsetsDeg must be an object");
558565 for (const [name, deg] of Object.entries(s.jointOffsetsDeg)) {
559566 if (!Object.values(JOINTS).includes(name)) throw new HttpError(400, `no joint "${name}"`);
560 if (typeof deg !== "number" || !Number.isFinite(deg) || Math.abs(deg) > 30) throw new HttpError(400, `offset for ${name} must be within ±30 degrees`);
567 if (typeof deg !== "number" || !Number.isFinite(deg) || Math.abs(deg) > JOINT_OFFSET_RANGE_DEG) throw new HttpError(400, `offset for ${name} must be within ±${JOINT_OFFSET_RANGE_DEG} degrees`);
561568 if (deg !== 0) out.jointOffsetsDeg[name] = deg;
562569 }
563570 }
@@ -818,7 +825,7 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}):
818825 // The table is where the arm's lowest link is now, less the margin the zone keeps above it, so the resting arm is not flagged.
819826 if (!model) throw new HttpError(409, "no model loaded on this server");
820827 const lowest = model.lowest(toQ(await bus.syncRead(ids, STS3215.Present_Position)));
821 const offset = Math.floor((lowest.z - model.floorZ) * 1000 - settings.floorMarginMm);
828 const offset = tableOffsetFor((lowest.z - model.floorZ) * 1000, settings.floorMarginMm);
822829 if (offset < -100 || offset > 100) {
823830 throw new HttpError(409, `the table would be ${offset} mm from the model's, past ±100: lowest point ${Math.round((lowest.z - model.floorZ) * 1000)} mm above the model floor (${lowest.link.replace(/_link$/, "")}); put the arm near the table first`);
824831 }
@@ -826,6 +833,24 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}):
826833 writeAtomic(settingsFile, JSON.stringify(settings, null, 1));
827834 return json(res, 200, { ...settings, model: true });
828835 }
836 case "POST /settings/table-touch": {
837 if (!model) throw new HttpError(409, "no model loaded on this server");
838 const body = await readBody(req);
839 const now = Date.now();
840 while (tableTouches.length && now - tableTouches[0]!.at > TOUCH_TTL_MS) tableTouches.shift();
841 if (body.reset === true || body.count === true) {
842 if (body.reset === true) tableTouches.length = 0;
843 return json(res, 200, { touches: tableTouches.length, of: TABLE_POINTS });
844 }
845 const lowest = model.lowest(toQ(await bus.syncRead(ids, STS3215.Present_Position)));
846 tableTouches.push({ mm: (lowest.z - model.floorZ) * 1000, at: now });
847 if (tableTouches.length < TABLE_POINTS) return json(res, 200, { touches: tableTouches.length, of: TABLE_POINTS });
848 const fit = fitTable(tableTouches.splice(0).map((t) => t.mm), settings.floorMarginMm);
849 if (!fit.ok) throw new HttpError(409, `${fit.problem}; start again`);
850 settings = validateSettings({ ...settings, tableOffsetMm: fit.offsetMm });
851 writeAtomic(settingsFile, JSON.stringify(settings, null, 1));
852 return json(res, 200, { ...settings, model: true, touches: TABLE_POINTS, of: TABLE_POINTS, spreadMm: Math.round(fit.spreadMm * 10) / 10 });
853 }
829854 case "POST /settings/joint-zero": {
830855 const body = await readBody(req);
831856 if (typeof body.joint !== "string") throw new HttpError(400, "joint must be a joint name");
Software/so101/src/terminal.test.ts +3 −1
@@ -127,9 +127,11 @@ describe("terminal table", () => {
127127 test("/table here and /table <mm> are asked for; anything else is a usage line", () => {
128128 const room = emptyRoom();
129129 expect(typed(room, "/table here")).toEqual({ table: "here" });
130 expect(typed(room, "/table touch")).toEqual({ table: "touch" });
131 expect(typed(room, "/table reset")).toEqual({ table: "reset" });
130132 expect(typed(room, "/table -12")).toEqual({ table: -12 });
131133 expect(typed(room, "/table 0")).toEqual({ table: 0 });
132 for (const bad of ["/table", "/table 101", "/table -101", "/table 1.5", "/table abc", "/table 1e2"]) expect(typed(room, bad)).toEqual({ print: "usage: /table here | /table <mm, -100 to 100>" });
134 for (const bad of ["/table", "/table 101", "/table -101", "/table 1.5", "/table abc", "/table 1e2"]) expect(typed(room, bad)).toEqual({ print: "usage: /table here | /table touch | /table reset | /table <mm, -100 to 100>" });
133135 });
134136
135137 test("/zero <joint> [deg] is asked for with a default of 0; anything else is a usage line", () => {
Software/so101/src/terminal.ts +15 −9
@@ -29,6 +29,8 @@
2929 * /visitors owner: today's peak viewers and joins per hour for the last 24 h (the counts /admin shows)
3030 * /restore #<n> owner: put a removed line back for everyone (Lobby.restoreLine; it is logged)
3131 * /table here admin: put the table under the arm's lowest link now (POST /settings/table-here)
32 * /table touch admin: touch the table at 3 points, one call each; the third sets the offset from them (POST /settings/table-touch)
33 * /table reset admin: drop the touches held (each also expires after 60 s)
3234 * /table <mm> admin: set the table offset, -100..100 mm (PUT /settings tableOffsetMm)
3335 * /zero <joint> [deg] admin: make the model read deg (default 0) for that joint at the pose it is in now (POST /settings/joint-zero)
3436 * /health owner or moderator: each open page's link as it last reported it (GET /admin/health, the page's Admin -> Health)
@@ -80,17 +82,17 @@ function appPort(env: Env): number {
8082 return port;
8183 }
8284
83 export type Path = "/stop" | "/resume" | "/settings/table-here" | "/settings/joint-zero" | "/settings";
85 export type Path = "/stop" | "/resume" | "/settings/table-here" | "/settings/table-touch" | "/settings/joint-zero" | "/settings";
8486 /** `tableOffsetMm` is the offset the server holds after a settings call, when it said. */
85 export type Post = (path: Path, body?: Record<string, unknown>) => Promise<{ status: number; error: string | null; tableOffsetMm?: number; offsetDeg?: number }>;
87 export type Post = (path: Path, body?: Record<string, unknown>) => Promise<{ status: number; error: string | null; tableOffsetMm?: number; touches?: number; offsetDeg?: number }>;
8688
8789 /** POST to the app as the page does (PUT for /settings), signed afresh for each request (a signature is good for a minute). */
8890 export function poster(env: Env, fetcher: typeof fetch = fetch): Post {
8991 return async (path, payload = {}) => {
9092 try {
9193 const r = await fetcher(`${appUrl(env)}${path}`, { method: path === "/settings" ? "PUT" : "POST", headers: { "content-type": "application/json", ...terminalHeaders(env) }, body: JSON.stringify(payload), signal: AbortSignal.timeout(5000) });
92 const body = (await r.json().catch(() => ({}))) as { error?: unknown; tableOffsetMm?: unknown; offsetDeg?: unknown };
93 return { status: r.status, error: r.ok ? null : plain(body.error ?? `status ${r.status}`), ...(typeof body.tableOffsetMm === "number" ? { tableOffsetMm: body.tableOffsetMm } : {}), ...(typeof body.offsetDeg === "number" ? { offsetDeg: body.offsetDeg } : {}) };
94 const body = (await r.json().catch(() => ({}))) as { error?: unknown; tableOffsetMm?: unknown; touches?: unknown; offsetDeg?: unknown };
95 return { status: r.status, error: r.ok ? null : plain(body.error ?? `status ${r.status}`), ...(typeof body.tableOffsetMm === "number" ? { tableOffsetMm: body.tableOffsetMm } : {}), ...(typeof body.touches === "number" ? { touches: body.touches } : {}), ...(typeof body.offsetDeg === "number" ? { offsetDeg: body.offsetDeg } : {}) };
9496 } catch (err) {
9597 return { status: 0, error: plain((err as Error).message) };
9698 }
@@ -211,7 +213,7 @@ const said = (room: Room, m: unknown): string => {
211213 };
212214
213215 const ZERO_USAGE = "usage: /zero <joint, e.g. shoulder_pan> [degrees the model should read, default 0]";
214 export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /table here|<mm> /zero <joint> [deg] (owner) · /mute <who> /unmute <who> (owner, moderator) · /delete <who|#id> (owner, moderator) · /report <who|#id> · /reports /dismiss #<id> (owner, moderator) · /removed /restore #<id> /visitors (owner) · /health /precision (owner, moderator) · /machine [off] · /who · /quit";
216 export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /table here|touch|reset|<mm> /zero <joint> [deg] (owner) · /mute <who> /unmute <who> (owner, moderator) · /delete <who|#id> (owner, moderator) · /report <who|#id> · /reports /dismiss #<id> (owner, moderator) · /removed /restore #<id> /visitors (owner) · /health /precision (owner, moderator) · /machine [off] · /who · /quit";
215217
216218 /** The Machine feed's socket beside the lobby's: same app, same port. */
217219 export const machineUrl = (live: string): string => live.replace(/\/live$/, "/machine");
@@ -354,7 +356,7 @@ function target(room: Room, word: string): string | null {
354356 return ID.test(word) ? word : null;
355357 }
356358
357 export type Typed = { send: Frame } | { post: "/stop" | "/resume" } | { table: "here" | number } | { zero: { joint: string; referenceDeg: number } } | { print: string } | { lines: string[] } | { machine: boolean } | { health: true } | { precision: true } | { quit: true } | null;
359 export type Typed = { send: Frame } | { post: "/stop" | "/resume" } | { table: "here" | "touch" | "reset" | number } | { zero: { joint: string; referenceDeg: number } } | { print: string } | { lines: string[] } | { machine: boolean } | { health: true } | { precision: true } | { quit: true } | null;
358360
359361 /** What a typed line asks for. Validation the server repeats anyway; this only saves a round trip on a typo. */
360362 export function typed(room: Room, input: string): Typed {
@@ -421,8 +423,10 @@ export function typed(room: Room, input: string): Typed {
421423 return { post: `/${verb.toLowerCase()}` as "/stop" | "/resume" };
422424 case "table": {
423425 if (arg.toLowerCase() === "here") return { table: "here" };
426 if (arg.toLowerCase() === "touch") return { table: "touch" };
427 if (arg.toLowerCase() === "reset") return { table: "reset" };
424428 if (/^-?\d{1,3}$/.test(arg) && Math.abs(Number(arg)) <= 100) return { table: Number(arg) };
425 return { print: "usage: /table here | /table <mm, -100 to 100>" };
429 return { print: "usage: /table here | /table touch | /table reset | /table <mm, -100 to 100>" };
426430 }
427431 case "health":
428432 return { health: true };
@@ -532,10 +536,12 @@ export class Door {
532536 }
533537
534538 /** The server decides who may; a refusal is printed, success says the offset the server now holds. */
535 private async table(what: "here" | number): Promise<void> {
539 private async table(what: "here" | "touch" | "reset" | number): Promise<void> {
536540 if (!this.post) return this.print("error: the table is not available here");
537 const r = await (what === "here" ? this.post("/settings/table-here") : this.post("/settings", { tableOffsetMm: what }));
541 const r = await (what === "here" ? this.post("/settings/table-here") : what === "touch" ? this.post("/settings/table-touch") : what === "reset" ? this.post("/settings/table-touch", { reset: true }) : this.post("/settings", { tableOffsetMm: what }));
538542 if (r.error) this.print(`error: ${r.error}`);
543 else if (what === "reset") this.print("touches cleared");
544 else if (what === "touch" && r.tableOffsetMm === undefined) this.print(`touch ${r.touches ?? "?"} of 3: move onto another point of the table and /table touch again`);
539545 else this.print(r.tableOffsetMm === undefined ? "table set" : `table offset is ${r.tableOffsetMm} mm`);
540546 }
541547

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs