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

Migrated from github.com/Trevato/SO-ARM100

The machine, not a magic box: a Machine panel shows the raw arm state and every command in and out, live #71

Merged opened this in answer to

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

Merged

A new Machine tab shows the arm as its servos report it and logs every command going in and out, live. Nothing polls: the Pi already pushes its status on /watch, and the log now travels on that same connection.

Notes

shipped merged

opened this

A new Machine tab shows the arm as its servos report it and logs every command going in and out, live. Nothing polls: the Pi already pushes its status on /watch, and the log now travels on that same connection. The relay sends it all to the page on a new read-only WebSocket, /machine, which is open only while the tab is.

Arm server (src/server.ts, src/bus.ts)

  • A new hook on the bus records every register write, so the panel shows the goals that actually reached the servos, after the governor and the limits.
  • Each joint in /status now also has target (the last goal written), min/max (the calibrated range) and lo/hi (the bounds commands are held inside). /status also gains held (the dead-man hold is on) and machine: {run, seq}.
  • Every clamp is logged the moment it is applied: joint limit (on the stream, moves and grips), the zone, a jump too far in one frame, a jam, and the speed and gripper-force limits. Driver changes, the dead-man hold, E-stop, clearing it, and park are logged too.
  • /watch still sends a status as each watcher's first message (an existing test relies on this). The last 200 log entries come right after it, then new ones in batches every 50 ms.

Relay (src/machine-feed.ts, src/machine-log.ts, src/arm-link.ts, src/relay.ts)

  • The link to the Pi now measures the round trip (a WebSocket ping every second), status frames per second, and reconnects.
  • Log entries from the Pi are checked before they are kept: bad entries are dropped, text is shortened and control characters are removed. Entries the relay has already seen are skipped, and a Pi restart starts the numbering over.
  • The relay adds its own entries: each stream frame it passes on, each request and its answer, the owner's speed cap, and frames it holds back (turn ended, or reconnecting).
  • A viewer that can't keep up misses status messages but never log entries.
  • In simulation mode, the relay opens a watch on the simulated arm only while someone has the tab open.

Page (src/viewer.html, src/ui/machine.js)

  • The tab shows a joints table (ticks, degrees, target, load, temperature, torque, limits, bounds), the link, the server state (whose turn, what drives, held, E-stop, zone, jams, speed cap), and a scrolling log with sequence number and age.
  • Pause freezes the view while the log keeps collecting; Copy puts the last 500 lines on the clipboard as tab-separated text with UTC times.
  • It's a tab on a phone and a column beside the view on a wide screen. Text goes in with textContent. On a bare so101 serve it reads /watch directly.

Choices

  • The panel is visible to everyone, admins and the current driver included, and has nothing in it that can move the arm. The "read-only for watchers" part of the issue is therefore met for everyone.
  • A status is logged only when something in it changed, so an idle arm doesn't bury the commands.
  • The governor's normal smoothing toward each goal is not logged as a clamp; the actual goals on the bus show what it did.
  • I built on /watch because #54's single WebSocket isn't on main yet.

Tests

  • src/machine-feed.test.ts runs a fake Pi with known register values behind the relay. It checks:

- the panel shows servo 2 exactly: 1234 ticks, 108.5°, −12.3% load, 41 °C, torque on, limits 818–3487, bounds 848–3457; - a frame {1: 9999} produces a joint limit clamp entry (asked 9999, sent 3457), then the bounded goal on the bus, and never 9999; - a panel opened later gets the log so far.

  • src/machine-log.test.ts and src/ui/machine.test.ts cover the log, the checks on incoming entries, and the panel's text.
  • I added pingEveryMs to the existing FAST timings in src/arm-link.test.ts because the timings type gained that field. No assertion changed.
  • The type check passes. The full bun test run had one failure, the existing /watch first-message test; after the fix above, the server, relay, link and machine suites pass (74 tests). I didn't rerun the whole suite after that fix.

To try it: PORT=8102 bun run Software/so101/bench/fake-serve.ts, open the page, pick Machine, and drag a joint slider past its end. You'll see → follow frame, ⚠ joint limit … asked=… sent=…, then → Goal_Position with the bounded value. Locally, / answered in 57 ms on a cold start and /machine sent about 10 messages a second against the simulation. I haven't measured it against the real Pi.

🤖 Generated with Claude Code

Closes #67

2 earlier comments · 1 event
commented

A new Machine tab shows the arm as its servos report it and logs every command going in and out, live. Nothing polls: the Pi already pushes its status on /watch, and the log now travels on that same connection. The relay sends it all to the page on a new read-only WebSocket, /machine, which is open only while the tab is.

Arm server (src/server.ts, src/bus.ts)

  • A new hook on the bus records every register write, so the panel shows the goals that actually reached the servos, after the governor and the limits.
  • Each joint in /status now also has target (the last goal written), min/max (the calibrated range) and lo/hi (the bounds commands are held inside). /status also gains held (the dead-man hold is on) and machine: {run, seq}.
  • Every clamp is logged the moment it is applied: joint limit (on the stream, moves and grips), the zone, a jump too far in one frame, a jam, and the speed and gripper-force limits. Driver changes, the dead-man hold, E-stop, clearing it, and park are logged too.
  • /watch still sends a status as each watcher's first message (an existing test relies on this). The last 200 log entries come right after it, then new ones in batches every 50 ms.

Relay (src/machine-feed.ts, src/machine-log.ts, src/arm-link.ts, src/relay.ts)

  • The link to the Pi now measures the round trip (a WebSocket ping every second), status frames per second, and reconnects.
  • Log entries from the Pi are checked before they are kept: bad entries are dropped, text is shortened and control characters are removed. Entries the relay has already seen are skipped, and a Pi restart starts the numbering over.
  • The relay adds its own entries: each stream frame it passes on, each request and its answer, the owner's speed cap, and frames it holds back (turn ended, or reconnecting).
  • A viewer that can't keep up misses status messages but never log entries.
  • In simulation mode, the relay opens a watch on the simulated arm only while someone has the tab open.

Page (src/viewer.html, src/ui/machine.js)

  • The tab shows a joints table (ticks, degrees, target, load, temperature, torque, limits, bounds), the link, the server state (whose turn, what drives, held, E-stop, zone, jams, speed cap), and a scrolling log with sequence number and age.
  • Pause freezes the view while the log keeps collecting; Copy puts the last 500 lines on the clipboard as tab-separated text with UTC times.
  • It's a tab on a phone and a column beside the view on a wide screen. Text goes in with textContent. On a bare so101 serve it reads /watch directly.

Choices

  • The panel is visible to everyone, admins and the current driver included, and has nothing in it that can move the arm. The "read-only for watchers" part of the issue is therefore met for everyone.
  • A status is logged only when something in it changed, so an idle arm doesn't bury the commands.
  • The governor's normal smoothing toward each goal is not logged as a clamp; the actual goals on the bus show what it did.
  • I built on /watch because #54's single WebSocket isn't on main yet.

Tests

  • src/machine-feed.test.ts runs a fake Pi with known register values behind the relay. It checks:

- the panel shows servo 2 exactly: 1234 ticks, 108.5°, −12.3% load, 41 °C, torque on, limits 818–3487, bounds 848–3457; - a frame {1: 9999} produces a joint limit clamp entry (asked 9999, sent 3457), then the bounded goal on the bus, and never 9999; - a panel opened later gets the log so far.

  • src/machine-log.test.ts and src/ui/machine.test.ts cover the log, the checks on incoming entries, and the panel's text.
  • I added pingEveryMs to the existing FAST timings in src/arm-link.test.ts because the timings type gained that field. No assertion changed.
  • The type check passes. The full bun test run had one failure, the existing /watch first-message test; after the fix above, the server, relay, link and machine suites pass (74 tests). I didn't rerun the whole suite after that fix.

To try it: PORT=8102 bun run Software/so101/bench/fake-serve.ts, open the page, pick Machine, and drag a joint slider past its end. You'll see → follow frame, ⚠ joint limit … asked=… sent=…, then → Goal_Position with the bounded value. Locally, / answered in 57 ms on a cold start and /machine sent about 10 messages a second against the simulation. I haven't measured it against the real Pi.

🤖 Generated with Claude Code

Changes requested — before the latest push

The Machine panel is well built on the page side. The log is bounded and entries from the Pi are validated. Output goes in with textContent. /machine is same-origin checked and read-only. The fake-Pi test checks exact raw values and that a clamp comes before the bounded goal. One miss against the list, so changes requested.

Fix first: both doors. The panel exists only on the page. src/tty.ts and src/terminal.ts are untouched, so the terminal has no way to see the joints, the link, the server state or the command log. The checklist requires that anything a person can do on the page they can do in src/tty.ts too. Add a machine command to the terminal Door. It should open /machine with the same headers the door already uses for /live. It should print the joint rows and state rows, then stream log lines using the same entryLine / jointRows / stateRows formatting from ui/machine.js, so the two doors cannot drift. Add it to HELP, add a test for it, and add a line to the README section.

Secondary, to do alongside:

  • /machine is open to any origin-matching client, and room.driver and the by field on logged requests put names in the feed. Say in the README that these names are already public in the lobby, or leave them out of the feed for guests.
  • I could not reach the preview from my sandbox (network denied), so I judged the source and the tests only. I did not see the page working.
  • The pull description says the full bun test was not rerun after the /watch fix. Run it once before you push.
commented

A new Machine tab on the page and a /machine command in the terminal show the arm as its servos report it and log every command in and out, live. Nothing polls: the Pi already pushes its status on /watch, and the log travels on that same connection. The relay sends it on to a new read-only WebSocket, /machine, which the page opens only while the tab is.

Arm server (src/server.ts, src/bus.ts)

  • A new hook on the bus records every register write, so the log shows the goals that actually reached the servos, after the governor and the limits.
  • Each joint in /status now also has target (the last goal written), min/max (the calibrated range) and lo/hi (the bounds commands are held inside). /status also gains held (the dead-man hold is on) and machine: {run, seq}.
  • Every clamp is logged the moment it is applied: joint limit (on the stream, moves and grips), the zone, a jump too far in one frame, a jam, and the speed and gripper-force limits. Driver changes, the dead-man hold, E-stop, clearing it, and park are logged too.
  • /watch still sends a status as each watcher's first message. The last 200 log entries come right after it, then new ones in batches every 50 ms.

Relay (src/machine-feed.ts, src/machine-log.ts, src/arm-link.ts, src/relay.ts)

  • The link to the Pi now measures the round trip (a WebSocket ping every second), status frames per second, and reconnects.
  • Log entries from the Pi are checked before they are kept: bad entries are dropped, text is shortened and control characters are removed. Entries the relay has already seen are skipped, and a Pi restart starts the numbering over.
  • The relay adds its own entries: each stream frame it passes on, each request and its answer, the owner's speed cap, and frames it holds back (turn ended, or reconnecting).
  • A viewer that can't keep up misses status messages but never log entries.
  • In simulation mode, the relay opens a watch on the simulated arm only while someone has the panel open.

Page (src/viewer.html, src/ui/machine.js)

  • The tab shows a joints table (ticks, degrees, target, load, temperature, torque, limits, bounds), the link, the server state (whose turn, what drives, held, E-stop, zone, jams, speed cap), and a scrolling log with sequence number and age.
  • Pause freezes the view while the log keeps collecting; Copy puts the last 500 lines on the clipboard as tab-separated text with UTC times.
  • It's a tab on a phone and a column beside the view on a wide screen. Text goes in with textContent. On a bare so101 serve it reads /watch directly.

Terminal (src/terminal.ts)

  • /machine opens /machine with the same signed headers the door uses for /live. It prints one line per joint, then the link and server rows, then each log line as it arrives.
  • The lines come from the same jointRows, linkRows, stateRows and entryLine in ui/machine.js that the page uses, so the two can't drift. Everything is made plain before it reaches the terminal.
  • /machine again reprints the joints; /machine off stops the stream. If the feed has no status yet when it opens, the joints print with the first one.
  • It's in HELP and in the README's terminal section.

Choices

  • The panel is visible to everyone, admins and the current driver included, and has nothing in it that can move the arm. The "read-only for watchers" part of the issue is therefore met for everyone.
  • The feed carries two kinds of name: whose turn it is, and the by on each logged request. I kept both, because the lobby already shows everyone who drives, who waits and who said what; the README now says so.
  • A status is logged only when something in it changed, so an idle arm doesn't bury the commands.
  • The governor's normal smoothing toward each goal is not logged as a clamp; the goals on the bus show what it did.
  • I built on /watch because #54's single WebSocket isn't on main yet.

Tests

  • src/machine-feed.test.ts runs a fake Pi with known register values behind the relay. It checks:

- the panel shows servo 2 exactly: 1234 ticks, 108.5°, −12.3% load, 41 °C, torque on, limits 818–3487, bounds 848–3457; - a frame {1: 9999} produces a joint limit clamp entry (asked 9999, sent 3457), then the bounded goal on the bus, and never 9999; - a panel opened later gets the log so far.

  • src/terminal.test.ts adds:

- the line formatting, with escape sequences from the arm stripped; - an owner's terminal that opens /machine, sees the joint rows match jointRows of /status, and sees → POST /move, then ⚠ joint limit … asked=9999 sent=4065, then ← POST /move status=200; - /machine off stops the stream.

  • src/machine-log.test.ts and src/ui/machine.test.ts cover the log, the checks on incoming entries, and the panel's text.
  • I added pingEveryMs to the existing FAST timings in src/arm-link.test.ts because the timings type gained that field. No assertion changed.
  • The type check passes, and the full bun test passes after the last change (344 tests). I also ran the real tty against a running app: /machine printed all six joints, the link, the state and the log, and /machine off stopped it.

To try it

  • Run PORT=8102 bun run Software/so101/bench/fake-serve.ts, open Machine on the page, and drag a joint slider past its end. You'll see → follow frame, ⚠ joint limit … asked=… sent=…, then → Goal_Position with the bounded value.
  • In the terminal, PORT=8102 bun run Software/so101/src/tty.ts and type /machine.
  • I haven't measured it against the real Pi.

🤖 Generated with Claude Code

commented

A new Machine tab on the page and a /machine command in the terminal show the arm as its servos report it and log every command in and out, live. Nothing polls: the Pi already pushes its status on /watch, and the log travels on that same connection. The relay sends it on to a new read-only WebSocket, /machine.

Arm server (src/server.ts, src/bus.ts)

  • A new hook on the bus records every register write, so the log shows the goals that actually reached the servos, after the governor and the limits.
  • Each joint in /status now also has target (the last goal written), min/max (the calibrated range) and lo/hi (the bounds commands are held inside). /status also gains held (the dead-man hold is on) and machine: {run, seq}.
  • Every clamp is logged the moment it is applied: joint limit (on the stream, moves and grips), the zone, a jump too far in one frame, a jam, and the speed and gripper-force limits. Driver changes, the dead-man hold, E-stop, clearing it, and park are logged too.
  • /watch still sends a status as each watcher's first message. The last 200 log entries come right after it, then new ones in batches every 50 ms.

Relay (src/machine-feed.ts, src/machine-log.ts, src/arm-link.ts, src/relay.ts)

  • The link to the Pi now measures the round trip (a WebSocket ping every second), status frames per second, and reconnects.
  • Log entries from the Pi are checked before they are kept: bad entries are dropped, text is shortened and control characters are removed. Entries already seen are skipped, and a Pi restart starts the numbering over.
  • The relay adds its own entries: each stream frame it passes on, each request and its answer, the owner's speed cap, and frames it holds back (turn ended, or reconnecting).
  • A viewer that can't keep up misses status messages but never log entries.
  • In simulation mode, the relay opens a watch on the simulated arm only while someone has the panel open.

Page (src/ui/machine-panel.js, src/ui/machine.js, src/viewer.html)

  • The tab shows a joints table (ticks, degrees, target, load, temperature, torque, limits, bounds), the link, the server state (whose turn, what drives, held, E-stop, zone, jams, speed cap), and a scrolling log with sequence number and age.
  • Pause freezes the view while the log keeps collecting; Copy puts the last 500 lines on the clipboard as tab-separated text with UTC times.
  • It's a tab on a phone and a column beside the view on a wide screen. Text goes in with textContent. On a bare so101 serve it reads /watch directly.
  • The panel's code and styles load only the first time the tab opens. The page itself carries just the tab and a small loader, so a first visit pays nothing for it.

Terminal (src/terminal.ts)

  • /machine opens /machine with the same signed headers the door uses for /live. It prints one line per joint, then the link and server rows, then each log line as it arrives.
  • The lines come from the same jointRows, linkRows, stateRows and entryLine in ui/machine.js that the page uses, so the two can't drift. Everything is made plain before it reaches the terminal.
  • /machine again reprints the joints; /machine off stops the stream. It's in HELP and in the README's terminal section.

Merge with main (#69)

  • The only conflict in relay.ts was the header comment: it now lists both main's /live status push and /machine.
  • In viewer.html, main had taken the leader-map preload and import out of the first load; I kept that.
  • Main's new test caps a first visit at 50 KB gzipped, and the inline panel put the page about 1.2 KB over. That's why the panel now loads with the tab.
  • That test now also checks that machine-panel.js and machine.js are not loaded up front, and that the page imports the panel only when the tab opens.

Choices

  • The panel is visible to everyone, admins and the current driver included, and has nothing in it that can move the arm. The "read-only for watchers" part of the issue is therefore met for everyone.
  • The feed carries two kinds of name: whose turn it is, and the by on each logged request. I kept both, because the lobby already shows everyone who drives, who waits and who said what; the README says so.
  • A status is logged only when something in it changed, so an idle arm doesn't bury the commands.
  • The governor's normal smoothing toward each goal is not logged as a clamp; the goals on the bus show what it did.
  • I built on /watch because #54's single WebSocket isn't on main yet.

Tests

  • src/machine-feed.test.ts runs a fake Pi with known register values behind the relay. It checks:

- the panel shows servo 2 exactly: 1234 ticks, 108.5°, −12.3% load, 41 °C, torque on, limits 818–3487, bounds 848–3457; - a frame {1: 9999} produces a joint limit clamp entry (asked 9999, sent 3457), then the bounded goal on the bus, and never 9999; - a panel opened later gets the log so far.

  • src/terminal.test.ts checks that a terminal's /machine prints the same rows the page does, then the request, its clamp and its answer, and that /machine off stops the stream.
  • src/machine-log.test.ts and src/ui/machine.test.ts cover the log, the checks on incoming entries, and the panel's text.
  • I added pingEveryMs to the existing FAST timings in src/arm-link.test.ts because the timings type gained that field. No assertion changed.
  • After the merge, the type check passes and the full bun test passes (358 tests). Both scripts parse, and on a booted app the page links the versioned machine-panel.js and both panel modules are served.
  • I haven't seen the panel in a browser after moving it into its own module; nothing here runs page code in a browser.

To try it

  • Run PORT=8102 bun run Software/so101/bench/fake-serve.ts, open Machine on the page, and drag a joint slider past its end. You'll see → follow frame, ⚠ joint limit … asked=… sent=…, then → Goal_Position with the bounded value.
  • In the terminal, PORT=8102 bun run Software/so101/src/tty.ts and type /machine.
  • I haven't measured any of it against the real Pi.

🤖 Generated with Claude Code

Approved

Read from the diff (the last part of it was cut, and my sandbox cannot reach the preview, so I did not use the page). Read-only /machine with same-origin check on upgrade, ws maxPayload 256, entries validated at the boundary (parseEntries), text via textContent, terminal /machine uses the same row formatters as the page, README covers both doors, and the tests would fail without the change (fake-Pi values, clamp-then-bounded-goal, late joiner, terminal). Names in the feed (turn, by) are already public in the lobby, as the README says.

Two things I would do next: 1) check the Machine tab on a 360px phone: the log region needs a fixed height so rows arriving do not shift the page, and the Pause/Copy buttons need 44px targets and an aria-live=off log with a labelled region so a screen reader is not flooded; 2) show a plain sentence in the tab when /machine cannot connect or JavaScript is off, instead of an empty panel.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs