Skip to content

Add preemptible control-rate execution with PCHIP and timed blending - #13

Open
stevenaya wants to merge 5 commits into
enactic:mainfrom
stevenaya:executor-control-rate
Open

stevenaya wants to merge 5 commits into
enactic:mainfrom
stevenaya:executor-control-rate

Conversation

@stevenaya

@stevenaya stevenaya commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add preemptible, latest-only action execution with control-rate trajectory handoff, shape-preserving PCHIP interpolation, duration-based blending, and chunk provenance metadata.

The PR keeps concise usage, configuration, metadata, migration notes, and limitations in README.

Execution changes

Latest-only scheduling and lifecycle

  • Separate action and command queues each retain one pending input. A newer item replaces an older pending item; command processing takes priority.
  • Blocking Dora input reception runs through asyncio.to_thread(node.next) instead of the previous 100 ms idle polling loop.
  • The executor starts disabled. start enables output; stop, intervene, and quit disable output and clear pending actions, trajectory, filter, and provenance state.
  • These lifecycle commands stop executor output, not the physical motors. Arm/driver lifecycle wiring remains separate.

Upsample first, then blend unsent control points

The trajectory path is:

new policy chunk -> optional PCHIP on the execution grid
                 -> blend with old unsent execution points
                 -> optional low-pass per emitted point
                 -> split right/left qpos and publish

On interruption, the executor retains the old trajectory's unsent, not-yet-filtered points. It does not prepend the last published command or reconstruct a policy-rate remainder. Each new chunk is interpolated independently using its own length and interval before mixing the two buffers. Filtering runs once per emitted point, retaining state across ordinary handoffs; reset discards the old remainder and resets filter state.

PCHIP and endpoint coverage

SciPy PCHIP replaces the handwritten Hermite slope calculation, which could reverse or overshoot even on monotone input near the first/last segment. PCHIP preserves per-joint shape without forcing every chunk's endpoint velocities to zero.

Integer-nanosecond timing constructs a fixed-period output grid that reaches or passes the horizon. Evaluation times are clamped to the horizon and the final pose is copied exactly; no extrapolation or shortened final control period is used. A single-point chunk passes through the interpolation stage unchanged. SciPy is added as a package dependency.

These are interpolation properties, not guarantees about the later blend/filter result or physical robot motion.

Time-based blending and filter damping

  • --blend-duration-ms / ACTION_BLEND_DURATION_MS specifies a target transition duration. For example, 100 ms at 250 Hz uses 26 points including both endpoints when enough overlap is available.
  • Unset means full overlap; 0 disables explicit blending, not filtering. Durations round up to an execution period and are clipped by available overlap.
  • Without upsampling, the execution period is the policy interval.
  • The biquad default changes from Q=0.707 to Q=0.5, reducing ringing at the cost of a slower response at the same frequency parameter. The default cutoff_hz remains 15 Hz; filter placement and state management are unchanged.

Interface and migration

Canonical per-arm struct<qpos: list<float32>> outputs remain unchanged. Actions remain a [T, D] Arrow list array, with required interval metadata in nanoseconds and optional cutoff_hz, reset, and chunk_id.

Upstream users must wire the new behavioral command requirement and send Start before actions can execute. --upsample and --filter remain opt-in; --control-hz defaults to 250 Hz when upsampling.

For users of the earlier feature branch, the point-count options --blend-max-steps / ACTION_BLEND_MAX_STEPS are removed. Their approximate time-span replacement is (N - 1) * policy_interval; four policy points at 30 Hz correspond to about 100 ms. Numerical behavior still changes because blending now follows interpolation.

Provenance

Outputs always carry a publication timestamp. When an input has chunk_id, output metadata also includes its ID, executor receive time, and nominal blend_duration_ns. blended_chunk_id identifies the immediately preceding chunk during the explicit transition window, including the endpoint whose old weight is zero.

The legacy blend_policy_points field remains a rounded policy-span equivalent for existing recorders. It is not the count of mixed control samples. Recorders need a separate schema update to persist blend_duration_ns; this PR does not change recorder code. Arbitrary policy metadata is not forwarded automatically, and provenance is not a complete blend lineage or proof that the driver accepted the command.

Known limitations retained intentionally

  • Single-point actions emit once and update the filter once; they do not establish a continuously updated 250 Hz target. A one-point overlap assigns weight 1 to the old point and can replace a new singleton target. This behavior is explicitly left for follow-up rather than silently redefining single-target tracking here.
  • After a chunk finishes, there is no remaining trajectory to blend with a later chunk.
  • Latest-only command/reset delivery can replace an unconsumed command or reset-bearing chunk. Unknown commands can interrupt playback without changing lifecycle state.
  • Input validation and reader/executor failure supervision remain limited. Scheduling is wall-clock based, not hard real-time. There is no sensor-time latency compensation or new velocity/acceleration safety layer.

Validation

  • 10 compact repository tests passed for policy-knot/endpoint handling, blend duration, filter reset, latest-only queues, command priority, and canonical qpos output.
  • 35 additional scratch tests passed outside the repository for numeric monotonicity/overshoot, fixed-cadence terminal coverage, changing chunk parameters, mocked playback handoffs, reset/filter behavior, and provenance windows. These intentionally are not added as a large permanent test harness.
  • At 250 Hz with a 15 Hz frequency parameter, offline rising/falling step checks showed approximately zero overshoot for Q=0.5, versus about 4.57% for the former default. This is a synthetic filter test, not a hardware benchmark or equal-bandwidth comparison.
  • Ruff lint/format and whitespace checks passed. Runtime code, dependencies, and tests are identical to the backup commit; only documentation was consolidated before this PR.

No robot hardware or full Dora/model inference pipeline was run for these changes.

Integrate latest-only scheduling, lifecycle commands, PCHIP endpoint holding, duration-based blending of unsent control points, and Q=0.5 filtering on mainline 5306d47. Preserve the current single-point behavior and compact helper tests.

Consolidate usage, metadata, migration notes and known limitations in README. The version with the full document is preserved on backup/executor-control-rate-099158a.
@stevenaya

stevenaya commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Feature summary relative to main

This summary compares base commit 5306d47e84e91ebb4c7d059eb1be0f34129362ee with this PR's commit 0d43c9978b186cfa9681e2213fe0953436d06eca.

  • Latest-only action scheduling: Replace the unbounded FIFO with a queue that retains only the newest pending action chunk, avoiding a backlog of outdated actions. Commands have a separate queue and take priority over actions.
  • More responsive input reception: Replace the 100 ms idle polling sleep with asyncio.to_thread(node.next), allowing input reception to proceed alongside trajectory execution without that polling delay.
  • Explicit execution lifecycle: Start with action output disabled and enable it only after start. stop, intervene, and quit disable output and clear pending actions, trajectory, filter, and provenance state; they do not directly disable the physical motors.
  • Control-rate trajectory handoff: Upsample each incoming chunk first, then blend it with the old trajectory's unsent control points. This replaces the baseline's integer policy-index truncation followed by policy-rate blending and then upsampling.
  • Configurable blend duration: Add --blend-duration-ms / ACTION_BLEND_DURATION_MS to limit the transition by time, clipped to the available overlap. Unset uses the full overlap; 0 disables explicit blending, not filtering.
  • Shape-preserving PCHIP interpolation: Replace handwritten Hermite interpolation with PCHIP to avoid interpolation-induced reversals and overshoot on monotone per-joint inputs. The fixed-period output grid also covers the final target, holding the exact final pose instead of extrapolating beyond the horizon.
  • Per-chunk sampling configuration: Build the interpolation grid from each chunk's own length and interval, rather than retaining the first chunk's interpolation configuration when later chunk parameters change.
  • Low-pass damping and update timing: Change the default biquad Q from 0.707 to 0.5 to reduce ringing, at the cost of a slower response at the same frequency parameter. Advance the filter only after interruption checks, immediately before publishing a point, so a point discarded during handoff does not advance filter state.
  • Chunk provenance metadata: When an input supplies chunk_id, attach it to outgoing commands together with executor receive time and blend-span metadata. During the explicit transition window, blended_chunk_id identifies the immediately preceding chunk; this traces command provenance, not physical execution or complete recursive blend ancestry.

Report matching adoption, completion, and rejection feedback through execution_plan. Complete only after both arms receive the final command, while preserving cancellation and legacy asynchronous/RTC behavior.

Validation: 167 CPU regression tests passed across the executor, policy bridge, and shared runtime.
Scale action intervals while preserving the first target and takeover time. Report effective timing in execution plans and account for scaled completion.

Validation: executor CPU tests passed as part of the 221-test node/runtime suite.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant