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

Migrated from github.com/Trevato/SO-ARM100

src/limits-search.ts steps one joint's speed and acceleration up until p95 error or overshoot worsens, then backs off one step - orchestration and test only #496

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 searchLimits({ joint, steps }, deps) in src/limits-search.ts, with src/limits-search.test.ts beside it. The six new tests pass with bun test. The type check didn't run: tsc couldn't find the bun type definitions in this sandbox, even after bun install.

Notes

shipped merged

opened this

I added searchLimits({ joint, steps }, deps) in src/limits-search.ts, with src/limits-search.test.ts beside it. The six new tests pass with bun test. The type check didn't run: tsc couldn't find the bun type definitions in this sandbox, even after bun install. I did not run the full bun --cwd Software/so101 test. forge.json is untouched.

  • Refusals: it throws if isIdle() is false. Every step is checked against the ranges in src/safety.ts with validateSafety before anything is read or written, so an out-of-range step is refused with no writes. I used validateSafety because RANGES isn't exported and you asked for only the two new files.
  • Search: it reads the starting limits and sweeps at them. It then writes each step and sweeps again. It stops at the first step where p95 error or overshoot is worse than the best so far. It writes back the last good step, or the starting limits if no step was good.
  • On a throw: it writes the starting limits back and rethrows. This happens even if the first sweep is the one that throws, before anything was written, which is a harmless extra write.
  • Return value: { joint, from, to, runs: [{ step, result }], at }. The worse step that ended the search is included in runs.
  • Reuse: SweepResult comes from src/tuning-run.ts.

Closes #494

commented

I added searchLimits({ joint, steps }, deps) in src/limits-search.ts, with src/limits-search.test.ts beside it. The six new tests pass with bun test. The type check didn't run: tsc couldn't find the bun type definitions in this sandbox, even after bun install. I did not run the full bun --cwd Software/so101 test. forge.json is untouched.

  • Refusals: it throws if isIdle() is false. Every step is checked against the ranges in src/safety.ts with validateSafety before anything is read or written, so an out-of-range step is refused with no writes. I used validateSafety because RANGES isn't exported and you asked for only the two new files.
  • Search: it reads the starting limits and sweeps at them. It then writes each step and sweeps again. It stops at the first step where p95 error or overshoot is worse than the best so far. It writes back the last good step, or the starting limits if no step was good.
  • On a throw: it writes the starting limits back and rethrows. This happens even if the first sweep is the one that throws, before anything was written, which is a harmless extra write.
  • Return value: { joint, from, to, runs: [{ step, result }], at }. The worse step that ended the search is included in runs.
  • Reuse: SweepResult comes from src/tuning-run.ts.
commented

This PR adds searchLimits in src/limits-search.ts, with six tests in src/limits-search.test.ts. It also now carries one small fix to a file outside the issue's scope, bench/precision.ts.

The preview failure. The only failing test was "a short script on the fake bus gives a scorecard…". It broke because bench() in bench/precision.ts used server.port, a variable that isn't in scope there. That came in with #493 and is not caused by the limits search. bench() now builds the /watch URL from the fake arm's own URL. bench/precision.test.ts passes (2 of 2). I did not re-run the full suite.

Why bench/precision.ts is touched. The issue said "only the two new files", but the preview can't go green without this one-line change.

The limits search.

  • It refuses to start while someone is driving.
  • It refuses any step outside the safety ranges, before anything is written.
  • It sweeps at today's limits, then at each step, and stops at the first step where p95 error or overshoot is worse than the best so far.
  • It writes back the last good step, or today's limits if no step was good.
  • On any throw it writes back the starting limits and rethrows.
  • It returns { joint, from, to, runs, at }.
Approved

Approved. searchLimits does what the issue asks and no more: it validates every step before any write, refuses while someone is driving, stops at the first worse p95 or overshoot, writes back the last good step (or the starting limits), and restores the starting limits on any throw. The six tests cover each of those and would fail without the code. It adds no dependency and has no user-facing surface yet, so the page, terminal and README checks do not apply. The one-line bench/precision.ts fix is outside the issue but needed to get the check green, and the pull says so.

Two things I would do next:

  1. When this is wired to a caller (page, tty, MCP), put the same-origin and identity check on that door. Also validate that steps ascend, and validate the limits read back as the starting values.
  2. If the restore write in the catch fails, it hides the original error. Keep the original error as the one that is thrown.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs