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

Migrated from github.com/Trevato/SO-ARM100

src/tuning-run.ts runs one P-coefficient experiment: sweep, write, sweep, then keep or put back - orchestration and test only #489

Merged opened this

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

Merged

I added runPExperiment({ joint, p }, deps) in Software/so101/src/tuning-run.ts, with its tests in tuning-run.test.ts. Only those two files changed. The six new tests pass.

Notes

shipped merged

opened this

I added runPExperiment({ joint, p }, deps) in Software/so101/src/tuning-run.ts, with its tests in tuning-run.test.ts. Only those two files changed. The six new tests pass. I ran only that test file, not the full bun --cwd Software/so101 test, which the forge runs on the push. tsc --noEmit couldn't run here: it failed with "Cannot find type definition file for 'bun'" even after bun install, so the type check is also left to the forge.

  • Refusals: it rejects a P outside TUNABLE.P (1–64) from servo-params.ts, then refuses unless isIdle(). Both refusals happen before anything is written.
  • Run: it reads the current P and sweeps. It then writes the candidate and sweeps again.
  • Keep or restore: it keeps the candidate only if p95 error and overshoot are both no worse and at least one is better. Otherwise it writes the old P back.
  • Throws: a throw from the second sweep, or from the candidate write, also writes the old P back, then rethrows. A throw from the first sweep writes nothing, because nothing has changed yet.
  • Result: it returns { joint, from, to, before, after, kept, at }. to is the old P when the candidate is put back.

I made some choices the issue left open:

  • joint is the servo id, a number, because readParams and writeParams take an id.
  • readParams returns { P }, since the runner needs nothing else.
  • A sweep result is { p95Error, overshoot, timeToArrive }.

The tests use fakes for keep, restore when worse or equal, restore on a mid-run throw, a throw on the first sweep, refusal while someone drives, and out-of-range P.

Closes #485

1 earlier comment · 1 event
commented

I added runPExperiment({ joint, p }, deps) in Software/so101/src/tuning-run.ts, with its tests in tuning-run.test.ts. Only those two files changed. The six new tests pass. I ran only that test file, not the full bun --cwd Software/so101 test, which the forge runs on the push. tsc --noEmit couldn't run here: it failed with "Cannot find type definition file for 'bun'" even after bun install, so the type check is also left to the forge.

  • Refusals: it rejects a P outside TUNABLE.P (1–64) from servo-params.ts, then refuses unless isIdle(). Both refusals happen before anything is written.
  • Run: it reads the current P and sweeps. It then writes the candidate and sweeps again.
  • Keep or restore: it keeps the candidate only if p95 error and overshoot are both no worse and at least one is better. Otherwise it writes the old P back.
  • Throws: a throw from the second sweep, or from the candidate write, also writes the old P back, then rethrows. A throw from the first sweep writes nothing, because nothing has changed yet.
  • Result: it returns { joint, from, to, before, after, kept, at }. to is the old P when the candidate is put back.

I made some choices the issue left open:

  • joint is the servo id, a number, because readParams and writeParams take an id.
  • readParams returns { P }, since the runner needs nothing else.
  • A sweep result is { p95Error, overshoot, timeToArrive }.

The tests use fakes for keep, restore when worse or equal, restore on a mid-run throw, a throw on the first sweep, refusal while someone drives, and out-of-range P.

Changes requested — before the latest push

The orchestration is right and in scope: validation and idle refusal come before any write, the keep rule is correct, and the old P is restored on a throw. One miss against the tests rule. The written = true line carries a deliberate behaviour: a candidate write that throws still gets the old P written back. No test covers it. Moving that line after the write, or deleting it, leaves all six tests green. Fix first: add a test where writeParams throws on the candidate write, with sweep returning one good result. Assert the call rejects and the writes show the restore. The fake records P before it throws, so make it throw after recording. Two smaller points that need no change here: isIdle is checked only once, so someone can start driving during the sweeps. If the restore write itself throws, the original error is lost. The module is not wired to the page or src/tty.ts yet, which is fine for an orchestration-and-test-only pull. There is nothing to try on the preview.

commented

This pull adds runPExperiment in Software/so101/src/tuning-run.ts, with its tests in tuning-run.test.ts. It runs a sweep at the current P, writes the candidate P and sweeps again. It keeps the candidate only if p95 tracking error and overshoot are both no worse and one is better. Otherwise it writes the old P back. The same happens if a sweep or the candidate write throws. A P outside the documented range (1–64 from TUNABLE.P) is refused before anything is written, and so is any run while isIdle() is false.

I added the test @juniper asked for: writeParams records P and then throws on the candidate write, with one good sweep. It asserts the call rejects and that the writes are [24, 16], so the old P is restored. If written = true moved after the write, writes would be [24] and the test would fail. I also reworded the comment on that line to say why it sits before the write.

All 7 tests in tuning-run.test.ts pass. I did not run the full bun --cwd Software/so101 test, and the type check couldn't run in this sandbox (tsc can't find the bun types).

I agree with the other two points and left them out of this pull. isIdle() is checked only once, so someone could start driving during the sweeps. If the restore write itself throws, the original error is lost. Both belong with the wiring that calls the runner.

Approved

Approved. runPExperiment does what the issue asks and nothing more: the P range is checked against TUNABLE.P, then idle, then sweep, write, sweep, then keep or restore. The restore on a throw is covered by tests, including the case where the candidate write throws after it landed, and the comment on written = true says why it sits before the write. It adds no dependency, has no UI and is not wired in, so there is nothing for the preview to show and no tty door to match yet. I did not run the tests.

Two things to do next, both in the wiring pull:

  1. isIdle() is read once, so someone can start driving mid-sweep. Re-check it before the candidate write, or tie the sweep to a driver lock.
  2. If the restore write throws, the original error is lost, and a failed restore inside the try triggers a second restore attempt in the catch. Report both errors, for example with an AggregateError, and make sure the person is told the arm may be left at the candidate P.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs