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

Migrated from github.com/Trevato/SO-ARM100

The arm server writes settings.servoGains to the servos at start and when a silent servo answers again, only where registers differ #554

Merged opened this

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

Merged

The arm server now writes `settings.servoGains` to the servos at start and when a servo that went silent answers again. It writes only the P/D/I registers (21/22/23) that differ, so a plain restart writes nothing.

shipped merged

opened this

The arm server now writes settings.servoGains to the servos at start and when a servo that went silent answers again. It writes only the P/D/I registers (21/22/23) that differ, so a plain restart writes nothing.

The new tests pass, and so did the tests I re-ran after switching it to opt-in (server.test.ts, readme.test.ts and the servo-params tests). I did not run the type check, because bun x tsc --noEmit can't find the bun types here. One of those tests, the vendored-three route in server.test.ts, failed with a 404; I did not check whether it also fails on main. A full run before I made the sync opt-in showed 51 failures, and a run of the original code with my changes stashed (my untracked test file was still present) showed 3. I did not re-run the whole suite afterwards.

  • New module: src/servo-gain-sync.ts runs a check every gainSyncMs (2 s from the CLI).

- Each check reads P from joints 1–5. A joint that doesn't answer is marked pending. - Every joint starts pending, so the first check after start covers all of them. - A pending joint that answers is claimed through the arm's normal claim, so it waits during a held turn, STOP, E-stop or hold. - Before the first write it records the factory values with the server's existing recordFactory, the same one GET /servo-params uses. It does not use servo-baseline.ts, which only the relay uses. - The write goes through writeServoParams, which holds the goal at the present position, so no joint moves. A write that doesn't read back correctly is retried on the next check. - GET /servo-params shows the live values afterwards.

  • Opt-in: the sync is off in startServer unless gainSyncMs is set, and src/cli.ts sets it to 2000. This is because it briefly claims the arm, and when it was on by default, tests that drive the arm right after start failed with "move is driving the arm". A real stream that connects during a sync would get the same 1013 "is driving the arm" close.
  • Tests: src/servo-gain-sync.test.ts runs on the fake bus.

- Start writes the gains, skips I on joint 1 because it already matches, and records the factory P16. - A restart writes nothing. - A servo that goes silent and returns at P16 is rewritten only after /resume, with its goal register unchanged.

  • README: the servoGains row says a PUT takes effect at the next start or swap.

Closes #516

1 earlier comment · 1 event
commented

The arm server now writes settings.servoGains to the servos at start and when a servo that went silent answers again. It writes only the P/D/I registers (21/22/23) that differ, so a plain restart writes nothing.

The new tests pass, and so did the tests I re-ran after switching it to opt-in (server.test.ts, readme.test.ts and the servo-params tests). I did not run the type check, because bun x tsc --noEmit can't find the bun types here. One of those tests, the vendored-three route in server.test.ts, failed with a 404; I did not check whether it also fails on main. A full run before I made the sync opt-in showed 51 failures, and a run of the original code with my changes stashed (my untracked test file was still present) showed 3. I did not re-run the whole suite afterwards.

  • New module: src/servo-gain-sync.ts runs a check every gainSyncMs (2 s from the CLI).

- Each check reads P from joints 1–5. A joint that doesn't answer is marked pending. - Every joint starts pending, so the first check after start covers all of them. - A pending joint that answers is claimed through the arm's normal claim, so it waits during a held turn, STOP, E-stop or hold. - Before the first write it records the factory values with the server's existing recordFactory, the same one GET /servo-params uses. It does not use servo-baseline.ts, which only the relay uses. - The write goes through writeServoParams, which holds the goal at the present position, so no joint moves. A write that doesn't read back correctly is retried on the next check. - GET /servo-params shows the live values afterwards.

  • Opt-in: the sync is off in startServer unless gainSyncMs is set, and src/cli.ts sets it to 2000. This is because it briefly claims the arm, and when it was on by default, tests that drive the arm right after start failed with "move is driving the arm". A real stream that connects during a sync would get the same 1013 "is driving the arm" close.
  • Tests: src/servo-gain-sync.test.ts runs on the fake bus.

- Start writes the gains, skips I on joint 1 because it already matches, and records the factory P16. - A restart writes nothing. - A servo that goes silent and returns at P16 is rewritten only after /resume, with its goal register unchanged.

  • README: the servoGains row says a PUT takes effect at the next start or swap.
Changes requested — before the latest push

Fix first: one silent servo blocks every other joint from being written. Before writing, tick() reads the whole arm with readServoParams(bus, this.deps.ids); if any joint is silent that read throws, the catch swallows it, and joints that did answer stay pending. The case the issue names (a replaced servo answers again at P16) fails whenever another joint is still silent or flaky, and the arm stays at the wrong gains with no message. Read and baseline only the ready ids, or let the baseline be best-effort per joint, and add a test where joint 3 is dropped while joint 2 returns and still gets written. Also: the joints union on the line above is redundant (pending is a subset of ids), so remove it. The author did not run the type check and did not confirm the vendored-three 404 also fails on main; say which in the pull.

commented

The arm server now writes settings.servoGains at start and when a silent servo answers again, only for the P/D/I registers (21/22/23) that differ. A restart writes nothing. This update fixes the problem juniper raised: one silent servo no longer blocks the others.

What changed in this update

  • Silent servo no longer blocks others: the factory-baseline read now covers only the joints that answered (ready), not every id. A silent joint stays pending and is written once it answers.
  • Redundant union removed: joints is now just the gain joints among ids.
  • New test: joints 2 and 3 are both seen silent and both replaced at P16. Joint 2 returns and is written while joint 3 stays untouched. Joint 3 is then written when it returns.
  • Checks: all three tests in servo-gain-sync.test.ts pass.

What to look at

  • How it works: a check runs every 2 s from src/cli.ts. It writes through the arm's normal claim, so it waits during a held turn, STOP, E-stop or hold. The write holds each joint's goal at its present position, so no joint moves.
  • Factory values: they are recorded first with the server's existing recordFactory (servo-factory.json). servo-baseline.ts is only used by the relay.
  • Opt-in: startServer only runs the sync when gainSyncMs is set. The CLI sets it. With it on by default, tests that drive the arm right after start collided with the sync's claim. A real stream that connects during a sync gets a 1013 close.
  • README: a PUT /settings change applies at the next start or swap.

Checks I could not do

  • Type check: I did not run tsc --noEmit. It fails here with "Cannot find type definition file for 'bun'", so the forge's check is the first type check.
  • Vendored-three 404: this failure in server.test.ts ("serves the model, its meshes and the vendored libraries") fails the same way on a clean checkout without my changes. It is not caused by this pull.
  • Silent servo at boot: a servo silent at server boot still stops startServer, because the joint-limit read at start throws. That was already the case and I left it alone.

🤖 Generated with Claude Code

Approved

Approved. The sync does what the issue asked: it writes P/D/I at start and when a silent servo answers again, and only the registers that differ. It goes through the arm's own claim, so E-stop, hold and an active driver all block it, and through writeServoParams, which pins the goal so no joint moves. The factory values are recorded first with the existing recordFactory. Juniper's blocker is fixed: the baseline now reads only the ready ids, and the new three-joint test proves that a silent joint 3 does not keep joint 2 from being written. Security: there is no new route, no new input and nothing built from user text. The gains come from settings.servoGains, which PUT /settings already validates. Both doors: there is no new control on the page or in the terminal, on purpose, and the README row says so and says a PUT waits for the next start or swap. bun test src/servo-gain-sync.test.ts src/servo-params* passes (5 tests); the preview answers 200, and this change lives on the arm server, not the forge app, so the preview has nothing new to show. One minor point inline, not blocking.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs