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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

/admin offers a three-touch table calibration beside 'The arm rests on the table now' #490

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

smith/arm:smith/448-admin-offers-a-three-touch-table-calibra → main 1 commit fork

  • Merged. smith/448-admin-offers-a-three-touch-table-calibra was merged into main as f3755ca.

Review

Sign in to review this change.
2 files changed +51 −0
Software/so101/src/admin-page.test.ts +31
@@ -61,3 +61,34 @@ test("a moderator sees no Unmute or Unban beside a moderator's mute or ban; the
6161 expect(owner.match(/Unmute<\/button>/g)?.length).toBe(2);
6262 expect(owner).toContain("Unban");
6363 });
64
65 test("the three touch steps post n=1,2,3 and the third shows height and tilt, or the refusal; moderators get none", async () => {
66 const owner = page(true);
67 for (const n of [1, 2, 3]) expect(owner).toContain(`id="touch-${n}"`);
68 expect(page(false)).not.toContain("table-touch");
69 const code = /<script>([\s\S]*?)<\/script>/.exec(owner)![1]!;
70 const els = new Map<string, any>();
71 const el = (id: string) => els.get(id) ?? (els.set(id, { id, textContent: "", value: "", disabled: false, on: {} as Record<string, () => Promise<void>>, addEventListener(t: string, f: () => Promise<void>) { this.on[t] = f; } }), els.get(id));
72 const posted: unknown[] = [];
73 let refuse = false;
74 const fetchFake = async (url: string, init?: { body?: string }) => {
75 if (url !== "/settings/table-touch") return { ok: true, json: async () => ({ tableOffsetMm: 5 }) };
76 const n = JSON.parse(init!.body!).n;
77 posted.push(n);
78 if (n < 3) return { ok: true, json: async () => ({ n }) };
79 return refuse ? { ok: false, status: 409, json: async () => ({ error: "the table tilts 9° (over 3°): not applied" }) }
80 : { ok: true, json: async () => ({ tableOffsetMm: 12, heightMm: 11.5, tiltDeg: 0.2, applied: true }) };
81 };
82 new Function("document", "fetch", "setInterval", code)({ getElementById: el }, fetchFake, () => 0);
83 await Bun.sleep(0);
84 await el("touch-1").on.click();
85 expect(el("touch-note").textContent).toContain("Touch 1 stored");
86 await el("touch-2").on.click();
87 await el("touch-3").on.click();
88 expect(posted).toEqual([1, 2, 3]);
89 expect(el("touch-note").textContent).toBe("The table is 11.5 mm above the model's floor, tilted 0.2°. Offset 12 mm.");
90 expect(el("table-mm").value).toBe("12");
91 refuse = true;
92 await el("touch-3").on.click();
93 expect(el("touch-note").textContent).toContain("tilts 9°");
94 });
Software/so101/src/admin-page.ts +20
@@ -111,6 +111,19 @@ const TABLE_SCRIPT = `
111111 say("The table is here: " + s.tableOffsetMm + " mm.");
112112 } catch (e) { say(e.message); }
113113 });
114 const touchNote = document.getElementById("touch-note");
115 for (const n of [1, 2, 3]) {
116 const b = document.getElementById("touch-" + n);
117 b.addEventListener("click", async () => {
118 b.disabled = true;
119 try {
120 const s = await settings({ method: "POST", url: "/settings/table-touch", headers: { "content-type": "application/json" }, body: JSON.stringify({ n }) });
121 if (n < 3) { touchNote.textContent = "Touch " + n + " stored. On to step " + (n + 1) + "."; return; }
122 input.value = String(s.tableOffsetMm);
123 touchNote.textContent = "The table is " + s.heightMm + " mm above the model's floor, tilted " + s.tiltDeg + "°. Offset " + s.tableOffsetMm + " mm.";
124 } catch (e) { touchNote.textContent = e.message; } finally { b.disabled = false; }
125 });
126 }
114127 document.getElementById("table-save").addEventListener("click", async () => {
115128 if (!input.reportValidity()) return;
116129 try {
@@ -282,6 +295,13 @@ ${p.canEdit ? `<div class="save"><button class="go">Save settings</button></div>
282295 ${p.canEdit ? `<section aria-labelledby="table"><h2 id="table">Table height</h2>
283296 <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>
284297 <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>
298 <h3>Touch the table</h3>
299 <ol>
300 <li>Put the gripper tip on the table, near the left of the arm's reach. <button type="button" id="touch-1">Touch 1</button></li>
301 <li>Put the gripper tip on the table straight ahead, farther out. <button type="button" id="touch-2">Touch 2</button></li>
302 <li>Put the gripper tip on the table, near the right of the arm's reach. <button type="button" id="touch-3">Touch 3</button></li>
303 </ol>
304 <p id="touch-note" role="status">Each touch must come within a minute of the last; the third sets the table height and reports its tilt.</p>
285305 </section>` : ""}
286306 ${p.canEdit && p.visitors ? visitorsSection(p.visitors) : ""}
287307 ${p.precision !== undefined ? precisionSection(p.precision, esc) : ""}

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs