Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
POST /settings/joint-zero sets one joint's offset so the model reads a known mechanical reference #463
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/445-post-settings-joint-zero-sets-one-joint → main 3 commits fork 3 threads · 3 unresolved
9 files
changed +159
−7
Software/README.md +13
| @@ -543,6 +543,8 @@ watches. A line you type is said in the chat; commands start with `/`: | ||
| 543 | 543 | `POST /settings/table-here`: the table plane goes under the arm's lowest |
| 544 | 544 | link now. `/table <mm>`, owner: sets `tableOffsetMm` (-100 to 100) by |
| 545 | 545 | `PUT /settings`. Both print the offset the server now holds, or its refusal. |
| 546 | - `/zero <joint> [degrees]`, owner: `POST /settings/joint-zero` for that joint | |
| 547 | (default 0°); prints the offset applied, or the refusal. | |
| 546 | 548 | - `/machine`: the Machine panel, the same rows the page's Machine tab shows |
| 547 | 549 | (one line per joint, then the link and the server), followed by every |
| 548 | 550 | command in and out and every clamp, line by line as it happens. `/machine` |
| @@ -762,6 +764,17 @@ down, so the resting arm is not flagged. The answer is 409 when the arm is | ||
| 762 | 764 | more than 100 mm from where the table could be; lower it first. The 3D |
| 763 | 765 | view draws the table there. |
| 764 | 766 | |
| 767 | To make the model read a known mechanical reference for one joint, put that | |
| 768 | joint at the reference (a mark, a stop) and, as an admin, | |
| 769 | `POST /settings/joint-zero {"joint": "shoulder_pan", "referenceDeg": 0}`, or | |
| 770 | `/zero shoulder_pan 0` in the terminal. The joint's offset in | |
| 771 | `jointOffsetsDeg` becomes whatever makes the model angle equal | |
| 772 | `referenceDeg` now (it replaces the old offset, so repeating it changes | |
| 773 | nothing), is saved, and comes back as `offsetDeg`. `joint` is a known joint | |
| 774 | name and `referenceDeg` is within that joint's limits (400 otherwise). The | |
| 775 | answer is 409 when the offset would pass ±15°, because the arm is not at the | |
| 776 | reference: put the arm at the reference first. | |
| 777 | ||
| 765 | 778 | The stream's targets go through a governor. At the command rate, it moves |
| 766 | 779 | each joint's goal toward the target on a trapezoid: it never goes past the |
| 767 | 780 | speed, never changes speed faster than the acceleration, and brakes in time |
Software/so101/src/joint-zero.test.ts added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { zeroOffsetDeg } from "./joint-zero.ts"; | |
| 3 | ||
| 4 | test("the offset brings the model's angle onto the reference, and is refused past ±15°", () => { | |
| 5 | const rad = (deg: number) => (deg * Math.PI) / 180; | |
| 6 | expect(zeroOffsetDeg(rad(3), 0)).toBe(-3); | |
| 7 | expect(zeroOffsetDeg(rad(-4.126), 0)).toBe(4.13); | |
| 8 | expect(zeroOffsetDeg(rad(10), 12.5)).toBe(2.5); | |
| 9 | expect(zeroOffsetDeg(0, 0)).toBe(0); | |
| 10 | expect(Object.is(zeroOffsetDeg(0, 0), 0)).toBe(true); | |
| 11 | expect(zeroOffsetDeg(rad(15), 0)).toBe(-15); | |
| 12 | expect(zeroOffsetDeg(rad(15.1), 0)).toBeNull(); | |
| 13 | expect(zeroOffsetDeg(rad(-20), 0)).toBeNull(); | |
| 14 | }); |
Software/so101/src/joint-zero.ts added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | /** The offset that makes the model read a known mechanical reference (POST /settings/joint-zero). */ | |
| 2 | ||
| 3 | /** Past this the arm is not at the reference, and an offset would hide that. */ | |
| 4 | export const MAX_ZERO_OFFSET_DEG = 15; | |
| 5 | ||
| 6 | /** Degrees to add to the model's angle `modelRad` so it reads `referenceDeg`, to 0.01°; null when that is past ±15°. */ | |
| 7 | export function zeroOffsetDeg(modelRad: number, referenceDeg: number): number | null { | |
| 8 | const offset = Math.round((referenceDeg - (modelRad * 180) / Math.PI) * 100) / 100; | |
| 9 | return Math.abs(offset) > MAX_ZERO_OFFSET_DEG ? null : offset + 0; // + 0: never -0 | |
| 10 | } |
Software/so101/src/lobby.test.ts +1
| @@ -780,6 +780,7 @@ describe("lobby", () => { | ||
| 780 | 780 | expect((await post("/settings/table-here", {})).status).toBe(401); |
| 781 | 781 | expect((await post("/settings/table-here", ALICE)).status).toBe(403); |
| 782 | 782 | expect((await post("/settings/table-here", OWNER)).status).toBe(200); // an admin gets through |
| 783 | expect((await post("/settings/joint-zero", ALICE)).status).toBe(403); | |
| 783 | 784 | expect((await post("/settings", OWNER, { tableOffsetMm: 0 }, "PUT")).status).toBe(200); |
| 784 | 785 | expect((await post("/settings", OWNER, { maxSpeedDegS: 60 }, "PUT")).status).toBe(200); |
| 785 | 786 | expect((await post("/settings", OWNER, { maxSpeedDegS: 90 }, "PUT")).status).toBe(200); |
Software/so101/src/relay.ts +1 −1
| @@ -163,7 +163,7 @@ const PAGE = /^\/(?:index\.html)?$/; | ||
| 163 | 163 | const STATIC = /^\/(?:index\.html)?$|^\/(?:model|vendor|ui)\//; |
| 164 | 164 | const LEADER = "/leader/calibration"; |
| 165 | 165 | /** Admins only: clearing an emergency stop and changing the settings (the safety limits among them). */ |
| 166 | const ADMIN_ONLY = new Set(["POST /estop/clear", "PUT /settings", "POST /settings/table-here", "PUT /servo-params", "POST /servo-params/factory"]); | |
| 166 | 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"]); | |
| 167 | 167 | /** Routes only the owner may reach; anyone else is told there is no such page. */ |
| 168 | 168 | const OWNER_READS = new Set(["GET /servo-params", "PUT /servo-params", "POST /servo-params/factory"]); |
| 169 | 169 | /** The driver's, and any admin's at any time. */ |
Software/so101/src/server.test.ts +43
| @@ -648,6 +648,49 @@ describe("the safe zone, the jam watch, and the model routes", () => { | ||
| 648 | 648 | await zcall("/settings", { zone: "enforce" }, "PUT"); |
| 649 | 649 | }); |
| 650 | 650 | |
| 651 | test("joint-zero trims one joint so the model reads the reference; a block still fires at the same physical pose", async () => { | |
| 652 | const saved = (await (await fetch(`${zurl}/settings`)).json()) as { zone: string; jointOffsetsDeg: Record<string, number> }; | |
| 653 | const lift = 2; // shoulder_lift | |
| 654 | try { | |
| 655 | expect((await zcall("/settings/joint-zero", { joint: "nope", referenceDeg: 0 })).status).toBe(400); | |
| 656 | expect((await zcall("/settings/joint-zero", { joint: "shoulder_lift", referenceDeg: "0" })).status).toBe(400); | |
| 657 | expect((await zcall("/settings/joint-zero", { joint: "shoulder_lift", referenceDeg: 1e6 })).status).toBe(400); | |
| 658 | // The arm rests 3° off the model's zero; a hand-set trim of -3 is what zeroing should arrive at. | |
| 659 | fake6.servos.get(lift)!.set([ticks(lift, 3) & 0xff, ticks(lift, 3) >> 8], 56); | |
| 660 | await zcall("/settings", { zone: "enforce", jointOffsetsDeg: { shoulder_lift: -3 } }, "PUT"); | |
| 661 | const blockBy = async () => { | |
| 662 | const r = await zcall("/move", { targets: { "2": ticks(2, 80) } }); | |
| 663 | return { status: r.status, what: ((await r.json()) as { violation: { what: string; link: string; depth: number } }).violation }; | |
| 664 | }; | |
| 665 | const before = await blockBy(); | |
| 666 | expect(before.status).toBe(409); | |
| 667 | fake6.servos.get(lift)!.set([ticks(lift, 3) & 0xff, ticks(lift, 3) >> 8], 56); | |
| 668 | await zcall("/settings", { jointOffsetsDeg: { shoulder_lift: 0 } }, "PUT"); | |
| 669 | const res = await zcall("/settings/joint-zero", { joint: "shoulder_lift", referenceDeg: 0 }); | |
| 670 | expect(res.status).toBe(200); | |
| 671 | const set = (await res.json()) as { offsetDeg: number; jointOffsetsDeg: Record<string, number> }; | |
| 672 | expect(Math.abs(set.offsetDeg + 3)).toBeLessThan(0.5); | |
| 673 | expect(set.jointOffsetsDeg.shoulder_lift).toBe(set.offsetDeg); | |
| 674 | const status = (await (await fetch(`${zurl}/status`)).json()) as { joints: Array<{ id: number; position: number }> }; | |
| 675 | const pos = status.joints.find((j) => j.id === lift)!.position; | |
| 676 | expect(Math.abs(((pos - mid(lift)) * 360) / 4095 + set.offsetDeg)).toBeLessThan(0.5); // the model reads the reference | |
| 677 | expect(((await (await fetch(`${zurl}/settings`)).json()) as { jointOffsetsDeg: Record<string, number> }).jointOffsetsDeg.shoulder_lift).toBe(set.offsetDeg); // saved | |
| 678 | const after = await blockBy(); | |
| 679 | expect(after.status).toBe(before.status); // same physical pose, same block | |
| 680 | expect(after.what.link).toBe(before.what.link); | |
| 681 | expect(after.what.what).toBe(before.what.what); | |
| 682 | expect(Math.abs(after.what.depth - before.what.depth)).toBeLessThan(0.001); // the offset is rounded to 0.01° | |
| 683 | // 20° off the reference is the arm not being there. | |
| 684 | fake6.servos.get(lift)!.set([ticks(lift, 20) & 0xff, ticks(lift, 20) >> 8], 56); | |
| 685 | const far = await zcall("/settings/joint-zero", { joint: "shoulder_lift", referenceDeg: 0 }); | |
| 686 | expect(far.status).toBe(409); | |
| 687 | expect(((await far.json()) as { error: string }).error).toMatch(/not at the reference/); | |
| 688 | } finally { | |
| 689 | fake6.servos.get(lift)!.set([mid(lift) & 0xff, mid(lift) >> 8], 56); | |
| 690 | await zcall("/settings", { zone: saved.zone, jointOffsetsDeg: { shoulder_lift: 0, ...saved.jointOffsetsDeg } }, "PUT"); | |
| 691 | } | |
| 692 | }); | |
| 693 | ||
| 651 | 694 | test("an arm already 30 mm in the table can move up, and is refused moving further down", async () => { |
| 652 | 695 | const rest = (await (await fetch(`${zurl}/status`)).json()) as { lowestMm: number }; |
| 653 | 696 | const saved = (await (await fetch(`${zurl}/settings`)).json()) as { floorMarginMm: number }; |
Software/so101/src/server.ts +28
| @@ -32,6 +32,8 @@ | ||
| 32 | 32 | * and the safety limits of src/safety.ts (speed, acceleration, rate, dead-man, park, gripper force, joint limits) |
| 33 | 33 | * PUT /settings change any of those |
| 34 | 34 | * POST /settings/table-here put the table (tableOffsetMm, -100..100) under the arm's lowest link now, the margin below it |
| 35 | * 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 | |
| 36 | * (owner only; 409 when the offset would pass ±15°: put the arm at the reference first) | |
| 35 | 37 | * GET /metrics jams, blocks, stalls, peak load and temperature per joint, recent events |
| 36 | 38 | * GET /precision the precision scorecard (src/precision.ts): tracking error, time to arrive, snap-backs by cause, |
| 37 | 39 | * latency by hop, for the session being driven, the last 10 minutes, and the stored sessions and hours; |
| @@ -78,6 +80,7 @@ import { ARRIVE_TICKS, type Cause, type Tracker } from "./precision.ts"; | ||
| 78 | 80 | import { PrecisionHistory } from "./precision-history.ts"; |
| 79 | 81 | import { MotionError, moveToPose, playTrajectory, recordTrajectory, STALL_SPAN_TICKS } from "./motion.ts"; |
| 80 | 82 | import { assertPoseName, parsePoseFile, serializePoseFile, type PoseFile } from "./poses.ts"; |
| 83 | import { MAX_ZERO_OFFSET_DEG, zeroOffsetDeg } from "./joint-zero.ts"; | |
| 81 | 84 | import { JOINTS, registerName, STS3215, ticksToDegrees } from "./sts3215.ts"; |
| 82 | 85 | import { largestStep, parseTrajectory, serializeTrajectory, type Trajectory } from "./trajectory.ts"; |
| 83 | 86 | import { accelRegister, bound, DEFAULT_SAFETY, Governor, jointBounds, motionLimits, SAFETY_KEYS, SafetyError, TICKS_PER_DEGREE, validateSafety, type SafetySettings } from "./safety.ts"; |
| @@ -815,6 +818,31 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}): | ||
| 815 | 818 | writeAtomic(settingsFile, JSON.stringify(settings, null, 1)); |
| 816 | 819 | return json(res, 200, { ...settings, model: true }); |
| 817 | 820 | } |
| 821 | case "POST /settings/joint-zero": { | |
| 822 | const body = await readBody(req); | |
| 823 | if (typeof body.joint !== "string") throw new HttpError(400, "joint must be a joint name"); | |
| 824 | const name = body.joint; | |
| 825 | const id = Number(Object.entries(JOINTS).find(([, n]) => n === name)?.[0]); | |
| 826 | if (!id || !ids.includes(id)) throw new HttpError(400, `no joint "${name}"`); | |
| 827 | const ref = body.referenceDeg; | |
| 828 | if (typeof ref !== "number" || !Number.isFinite(ref)) throw new HttpError(400, "referenceDeg must be a number"); | |
| 829 | if (!model) throw new HttpError(409, "no model loaded on this server"); | |
| 830 | const joint = model.movable.find((j) => j.name === name); | |
| 831 | if (!joint) throw new HttpError(400, `the model has no joint "${name}"`); | |
| 832 | const [lo, hi] = [(joint.lower * 180) / Math.PI, (joint.upper * 180) / Math.PI]; | |
| 833 | if (ref < lo - 1e-9 || ref > hi + 1e-9) throw new HttpError(400, `referenceDeg for ${name} must be within ${lo.toFixed(1)} to ${hi.toFixed(1)}`); | |
| 834 | const ticks = (await bus.syncRead([id], STS3215.Present_Position)).get(id); | |
| 835 | const lim = limits.get(id); | |
| 836 | if (ticks === undefined || !lim) throw new HttpError(409, `no response from servo ${id}`); | |
| 837 | const rad = name === "gripper" ? gripperTicksToRadians(ticks, lim.min, lim.max, gripperOpen) : ticksToRadians(ticks, lim.min, lim.max); | |
| 838 | const offset = zeroOffsetDeg(rad, ref); | |
| 839 | if (offset === null) { | |
| 840 | throw new HttpError(409, `${name} reads ${Math.round((rad * 180) / Math.PI)}° in the model, more than ${MAX_ZERO_OFFSET_DEG}° from the ${ref}° reference: the arm is not at the reference; put it there first`); | |
| 841 | } | |
| 842 | settings = validateSettings({ ...settings, jointOffsetsDeg: { ...settings.jointOffsetsDeg, [name]: offset } }); | |
| 843 | writeAtomic(settingsFile, JSON.stringify(settings, null, 1)); | |
| 844 | return json(res, 200, { ...settings, model: true, joint: name, offsetDeg: offset }); | |
| 845 | } | |
| 818 | 846 | case "GET /model.json": |
| 819 | 847 | if (!model) return json(res, 404, { error: "no model loaded on this server" }); |
| 820 | 848 | return json(res, 200, { |
Software/so101/src/terminal.test.ts +27
| @@ -125,6 +125,33 @@ describe("terminal table", () => { | ||
| 125 | 125 | 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>" }); |
| 126 | 126 | }); |
| 127 | 127 | |
| 128 | test("/zero <joint> [deg] is asked for with a default of 0; anything else is a usage line", () => { | |
| 129 | const room = emptyRoom(); | |
| 130 | expect(typed(room, "/zero shoulder_pan")).toEqual({ zero: { joint: "shoulder_pan", referenceDeg: 0 } }); | |
| 131 | expect(typed(room, "/zero wrist_flex -90.5")).toEqual({ zero: { joint: "wrist_flex", referenceDeg: -90.5 } }); | |
| 132 | for (const bad of ["/zero", "/zero Pan", "/zero a 1e2", "/zero a b", "/zero a 1 2", "/zero a/b"]) expect(typed(room, bad)).toEqual({ print: expect.stringContaining("usage: /zero") }); | |
| 133 | }); | |
| 134 | ||
| 135 | test("the door posts joint-zero signed-by-the-poster and prints the offset, or the refusal", async () => { | |
| 136 | const printed: string[] = []; | |
| 137 | const asked: unknown[] = []; | |
| 138 | const door = new Door("ws://127.0.0.1:1/live", {}, (l) => printed.push(l), async (path, body) => { | |
| 139 | asked.push([path, body]); | |
| 140 | return body?.joint === "elbow_flex" ? { status: 409, error: "the arm is not at the reference" } : { status: 200, error: null, offsetDeg: -3.2 }; | |
| 141 | }); | |
| 142 | door.input("/zero shoulder_pan 5"); | |
| 143 | door.input("/zero elbow_flex"); | |
| 144 | await Bun.sleep(50); | |
| 145 | expect(printed).toEqual(["shoulder_pan offset is -3.2°", "error: the arm is not at the reference"]); | |
| 146 | expect(asked).toEqual([["/settings/joint-zero", { joint: "shoulder_pan", referenceDeg: 5 }], ["/settings/joint-zero", { joint: "elbow_flex", referenceDeg: 0 }]]); | |
| 147 | }); | |
| 148 | ||
| 149 | test("the poster returns the offset joint-zero applied", async () => { | |
| 150 | const env = { PORT: "9", FORGE_APP_IDENTITY_KEY: "k".repeat(32), FORGE_APP_USER_ID: "u-owner", FORGE_APP_USER: "owner", FORGE_APP_USER_ROLE: "admin" }; | |
| 151 | const fetcher = (async () => new Response(JSON.stringify({ offsetDeg: 2.5 }), { status: 200 })) as never; | |
| 152 | expect(await poster(env, fetcher)("/settings/joint-zero", { joint: "wrist_roll", referenceDeg: 0 })).toEqual({ status: 200, error: null, offsetDeg: 2.5 }); | |
| 153 | }); | |
| 154 | ||
| 128 | 155 | test("the poster sends table-here as a POST and the offset as a PUT /settings, signed; a refusal comes back as its error", async () => { |
| 129 | 156 | const calls: Array<{ url: string; method: string; body: string; signed: boolean }> = []; |
| 130 | 157 | const answer = (status: number, body: unknown) => async (url: unknown, init: RequestInit = {}) => { |
Software/so101/src/terminal.ts +22 −6
| @@ -30,6 +30,7 @@ | ||
| 30 | 30 | * /restore #<n> owner: put a removed line back for everyone (Lobby.restoreLine; it is logged) |
| 31 | 31 | * /table here admin: put the table under the arm's lowest link now (POST /settings/table-here) |
| 32 | 32 | * /table <mm> admin: set the table offset, -100..100 mm (PUT /settings tableOffsetMm) |
| 33 | * /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) | |
| 33 | 34 | * /health owner or moderator: each open page's link as it last reported it (GET /admin/health, the page's Admin -> Health) |
| 34 | 35 | * /precision owner or moderator: the precision scorecard /admin shows (GET /precision, src/precision-panel.ts) |
| 35 | 36 | * /machine [off] the Machine panel (/machine, src/machine-feed.ts): the joints, the link and the server as they are, |
| @@ -79,17 +80,17 @@ function appPort(env: Env): number { | ||
| 79 | 80 | return port; |
| 80 | 81 | } |
| 81 | 82 | |
| 82 | export type Path = "/stop" | "/resume" | "/settings/table-here" | "/settings"; | |
| 83 | export type Path = "/stop" | "/resume" | "/settings/table-here" | "/settings/joint-zero" | "/settings"; | |
| 83 | 84 | /** `tableOffsetMm` is the offset the server holds after a settings call, when it said. */ |
| 84 | export type Post = (path: Path, body?: Record<string, unknown>) => Promise<{ status: number; error: string | null; tableOffsetMm?: number }>; | |
| 85 | export type Post = (path: Path, body?: Record<string, unknown>) => Promise<{ status: number; error: string | null; tableOffsetMm?: number; offsetDeg?: number }>; | |
| 85 | 86 | |
| 86 | 87 | /** POST to the app as the page does (PUT for /settings), signed afresh for each request (a signature is good for a minute). */ |
| 87 | 88 | export function poster(env: Env, fetcher: typeof fetch = fetch): Post { |
| 88 | 89 | return async (path, payload = {}) => { |
| 89 | 90 | try { |
| 90 | 91 | 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) }); |
| 91 | const body = (await r.json().catch(() => ({}))) as { error?: unknown; tableOffsetMm?: unknown }; | |
| 92 | return { status: r.status, error: r.ok ? null : plain(body.error ?? `status ${r.status}`), ...(typeof body.tableOffsetMm === "number" ? { tableOffsetMm: body.tableOffsetMm } : {}) }; | |
| 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 } : {}) }; | |
| 93 | 94 | } catch (err) { |
| 94 | 95 | return { status: 0, error: plain((err as Error).message) }; |
| 95 | 96 | } |
| @@ -207,7 +208,8 @@ const said = (room: Room, m: unknown): string => { | ||
| 207 | 208 | return from ? `${tag}${plain(from.name)}: ${plain(message?.text)}` : `· ${plain(message?.text)}`; |
| 208 | 209 | }; |
| 209 | 210 | |
| 210 | export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /table here|<mm> (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"; | |
| 211 | const ZERO_USAGE = "usage: /zero <joint, e.g. shoulder_pan> [degrees the model should read, default 0]"; | |
| 212 | 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"; | |
| 211 | 213 | |
| 212 | 214 | /** The Machine feed's socket beside the lobby's: same app, same port. */ |
| 213 | 215 | export const machineUrl = (live: string): string => live.replace(/\/live$/, "/machine"); |
| @@ -343,7 +345,7 @@ function target(room: Room, word: string): string | null { | ||
| 343 | 345 | return ID.test(word) ? word : null; |
| 344 | 346 | } |
| 345 | 347 | |
| 346 | export type Typed = { send: Frame } | { post: "/stop" | "/resume" } | { table: "here" | number } | { print: string } | { lines: string[] } | { machine: boolean } | { health: true } | { precision: true } | { quit: true } | null; | |
| 348 | 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; | |
| 347 | 349 | |
| 348 | 350 | /** What a typed line asks for. Validation the server repeats anyway; this only saves a round trip on a typo. */ |
| 349 | 351 | export function typed(room: Room, input: string): Typed { |
| @@ -351,6 +353,11 @@ export function typed(room: Room, input: string): Typed { | ||
| 351 | 353 | if (!line) return null; |
| 352 | 354 | if (!line.startsWith("/")) return { send: { type: "post", text: line } }; |
| 353 | 355 | const [verb = "", arg = "", ...rest] = line.slice(1).split(/\s+/); |
| 356 | if (/^zero$/i.test(verb)) { | |
| 357 | const [deg = "0", ...extra] = rest.length ? [rest[0]!, ...rest.slice(1)] : []; | |
Redundant: |
||
| 358 | if (!/^[a-z_]{1,24}$/.test(arg) || extra.length || !/^-?\d{1,3}(\.\d{1,3})?$/.test(deg)) return { print: ZERO_USAGE }; | |
| 359 | return { zero: { joint: arg, referenceDeg: Number(deg) } }; | |
| 360 | } | |
| 354 | 361 | const timed = /^mute$/i.test(verb) && rest.length === 1 && /^(10m|1h|24h|forever)$/i.test(rest[0]!); |
| 355 | 362 | if (rest.length && !timed && /^unmute$/i.test(verb)) return { print: "usage: /unmute <name>" }; |
| 356 | 363 | if (rest.length && !timed) return { print: `error: one name at a time` }; |
| @@ -484,6 +491,7 @@ export class Door { | ||
| 484 | 491 | else if ("lines" in t) t.lines.forEach((l) => this.print(l)); |
| 485 | 492 | else if ("post" in t) void this.ask(t.post); |
| 486 | 493 | else if ("table" in t) void this.table(t.table); |
| 494 | else if ("zero" in t) void this.zero(t.zero.joint, t.zero.referenceDeg); | |
| 487 | 495 | else if ("health" in t) void this.health(); |
| 488 | 496 | else if ("precision" in t) void this.precision(); |
| 489 | 497 | else if ("machine" in t) this.watchMachine(t.machine); |
| @@ -522,6 +530,14 @@ export class Door { | ||
| 522 | 530 | else this.print(r.tableOffsetMm === undefined ? "table set" : `table offset is ${r.tableOffsetMm} mm`); |
| 523 | 531 | } |
| 524 | 532 | |
| 533 | /** The server decides who may and whether the arm is at the reference; success says the offset it applied. */ | |
| 534 | private async zero(joint: string, referenceDeg: number): Promise<void> { | |
| 535 | if (!this.post) return this.print("error: zeroing is not available here"); | |
| 536 | const r = await this.post("/settings/joint-zero", { joint, referenceDeg }); | |
| 537 | if (r.error) this.print(`error: ${r.error}`); | |
| 538 | else this.print(r.offsetDeg === undefined ? `${joint} zeroed` : `${joint} offset is ${r.offsetDeg}°`); | |
| 539 | } | |
| 540 | ||
| 525 | 541 | close(): void { |
| 526 | 542 | this.ws?.close(); |
| 527 | 543 | this.machineWs?.close(); |
new above
offline
Says owner only; the relay gates it to admins. Match the wording.