Repository navigation
nav: dyn_bike_step, a differentiable dynamic single-track vehicle (P8a) - #714
Merged
Merged
Conversation
…er bike_control (P8a) bike_step splits into bike_control (the controller, emitting delta_cmd and a_cmd) and bike_plant (the kinematic integration), its outputs bit for bit unchanged; bike_control_bwd takes the commands' gradients from another plant. diff::dyn_plant: Pacejka tires within a friction ellipse, quasi-static load transfer, actuator lags, drag, rolling resistance and grade, a low-speed blend; (vy, r) by implicit Euler with each tire linearized by its secant through its root in lateral velocity. Its adjoint runs it on forward-mode duals. Parameters are SI from the spec sheet (dyn_bike_si), and nav_plant::dyn_bike_si_of derives them from a vehicle_desc. nav_dyn_bike_test gates the gradients, the kinematic limit against bike_step, the skid modes and the stopping envelope, and pins golden values for the torch twin.
…ers in the golden A double plant is now double throughout (the lags' exp, the slew limit, the determinant floor and the friction ellipse's factor were float), so GRL-SNAM's torch twin reproduces it to 1e-9: next state and VJP on all seven golden cases (tests/test_dyn_bike_parity.py there).
transfix
added a commit
that referenced
this pull request
Oct 19, 2026
…s (fixes macOS) DynBike.KinematicLimitFollowsBikeStep failed on macOS (#717's CI, and master since #714): its 32 routes come from sample_starts_goals, whose uniform_int_distribution differs by standard library, and under the controller (dyn_bike_step) the worst agent parted by 1.3 against 0.017 here. Over 40 sets of routes, 0 to 11 of 32 agents part by more than 0.2 rr in closed loop (the controller amplifies the plant's small differences along some routes), while the median gap is at most 0.0081 and the median end-distance difference at most 0.41%. The closed loop is now gated by those medians (0.1 rr, 2%) and its worst agent reported; the open-loop gate, at most 0.0151 over the 40 sets, moves from 0.1 rr to 0.2 rr.
transfix
added a commit
that referenced
this pull request
Oct 19, 2026
…Jolt reach (P8b) (#717) * nav: rollout_kind::dynamic in coef_train, the policy trained through the dynamic vehicle (P8b) coef_trainer drives bike_control into dyn_plant (dyn_bike_step / dyn_bike_step_bwd) when train_config::rollout is dynamic. loss_and_grad carries the vehicle's further state (vy, r, delta, a) through optional x / x_out, and train() keeps it across windows. train_config::dyn is the vehicle; a dynamic run without one whose wheelbase is veh_L throws. nav_plant::dyn_bike_params_at(desc, wheelbase) builds it from a vehicle_desc: the trainer's city reads as a RoboRacer at about 0.108 normalized units per metre. The CUDA trainer refuses the dynamic rollout for now. Gradcheck dir_rel 2.3e-2; the horizon loss falls; a policy trained at 5e-5 keeps 71.9% reach; an lr sweep is in docs/NAV_TRAINING.md. * nav: material_integrator::dynamic, the material trainer through the dynamic vehicle (P8b) integrate_dynamic_material drives integrate_bicycle_material's controller (force law, pure pursuit, governors, d_cap) into diff::dyn_plant in place of the kinematic update; arc length and cumulative risk follow the dynamic path. Its VJP joins the plant's dual-number VJP to the bicycle's hand-written controller reverse, which gains a controller-only mode (the kinematic default adds 0, so its sums are unchanged). multi_start_penalty_dynamic runs L_multi on it. material_loss_config::dynamic is the vehicle; L_vel compares the rear axle's world velocity. Gradchecks: rollout VJP on 40 coefficients (worst 1.5e-2, directional 3e-6 at eps 1e-3), L_multi worst 4.8e-4, the full loss-to-weights chain dir_rel 7.0e-4 over 64 weights. * nav_plant_test: P8b's gate on the Jolt plant, the dynamic-trained policy against the point-mass one NavPlantConvergence.DynamicTrainedPolicyAgainstPointMassOnJolt trains both alike on the city and drives each on Jolt RoboRacers (the city as a RoboRacer's, its blocks static boxes) over 20 paired seeds, with a paired-bootstrap 95% CI. At lr 2e-4 / 300 steps the dynamic-trained policy reaches 44.0% against 35.0% (+9.0, CI [+6.7, +11.4]), but both fall below the untrained seed's 51.7%; at 5e-5 / 150 they tie (+0.4, CI [-1.8, +2.8]). Recorded in NAV_TRAINING.md and the roadmap. * nav: checkpoint selection on Jolt reach (P8b) coef_trainer::train(scene, verbose, fitness) scores the untrained policy, every train_config::checkpoint_every steps and the last, and ends on the best, so it never ends below where it started by that score (checkpoints(), selected_step()). cvc::physics::reach_on_plant (nav_eval.h) is that score on the physics plant: a coef_train scene's blocks as static boxes, read at a vehicle's scale, `agents` vehicles driven through a nav_plant per seed. The P8b gate test now uses it. It repeats exactly (single-threaded, cross-platform determinism) but is chaotic: passing veh_L's 0.035f instead of 0.035 moves a seed's reach by up to 0.1, so the tests pin the exact scale. NavPlantConvergence.CheckpointSelectionOnJoltReach: at lr 2e-4 / 300 steps, selected every 30 steps on 8 validation seeds, held out over the gate's 20 seeds the dynamic-trained policy reaches 52.7% and the point-mass-trained one 50.1% (+2.6, CI [+0.3, +4.7]); the seed 51.7% (dynamic - seed +1.0, CI [-1.2, +3.4]). With 4 validation seeds: +3.8 [+0.9, +6.7] and +1.3 [-0.6, +3.3]. Recorded in NAV_TRAINING.md and the roadmap. * nav: reach_on_plant scores seeds in parallel; lower-lr, denser-checkpoint sweep (P8b) plant_reach_options::threads (0 = the hardware's threads) runs seeds at once, each in its own world, sim_world and plant with its agents on the worker's thread. NavPlant. ReachOnPlantIsRepeatable checks that parallel scores equal serial ones; 8 validation seeds now score in about the time of one, so a 31-checkpoint selection run takes about 9 minutes. The next P8b lever, lower peak rates with denser checkpoints (8 validation seeds, 31 checkpoints, held out on the gate's 20 seeds; the seed reaches 51.7%): 1e-4 / 300 steps / every 10: dynamic 53.5%, point mass 51.1%; +2.4 [+0.3, +4.4], dynamic - seed +1.9 [-0.8, +4.4] 5e-5 / 600 / every 20: 50.5% vs 48.9%; +1.7 [-1.2, +4.5], -1.1 [-4.0, +1.6] 2e-4 / 150 / every 5: 51.7% vs 50.5%; +1.1 [-0.8, +3.0], +0.0 [-1.9, +2.1] No setting beats the seed outside the CI. At the lower rates validation reach stays flat and denser checkpoints mostly add selection noise, so the next levers act on the signal: more validation seeds, or Jolt reach as the training signal. Recorded in NAV_TRAINING.md and the roadmap. * nav_dyn_bike_test: gate the closed-loop kinematic limit by its medians (fixes macOS) DynBike.KinematicLimitFollowsBikeStep failed on macOS (#717's CI, and master since #714): its 32 routes come from sample_starts_goals, whose uniform_int_distribution differs by standard library, and under the controller (dyn_bike_step) the worst agent parted by 1.3 against 0.017 here. Over 40 sets of routes, 0 to 11 of 32 agents part by more than 0.2 rr in closed loop (the controller amplifies the plant's small differences along some routes), while the median gap is at most 0.0081 and the median end-distance difference at most 0.41%. The closed loop is now gated by those medians (0.1 rr, 2%) and its worst agent reported; the open-loop gate, at most 0.0151 over the 40 sets, moves from 0.1 rr to 0.2 rr. * test(state): poll pump_cycles instead of a fixed 50ms sleep StateSessionStatusTest.StatusReportsPumpCycles joined a session with pump_interval_ms = 5, slept a fixed 50ms and then expected pump_cycles > 0. On 2026-10-19 it failed on recipe / windows-2022 / Release of #717 (job 118144550758), a PR that does not touch state: state_session_status_test.cpp(53): error: Expected: (s.pump_cycles) > (0u), actual: 0 vs 0 [ FAILED ] StateSessionStatusTest.StatusReportsPumpCycles (1002 ms) The assertion fired ~220ms after [ RUN ], and stop() then took another ~560ms to join the pump thread: under ctest -j load the pump thread had not finished its first cycle. Nothing is wrong with the pump; the window is just too short to guarantee one scheduling slice. Poll session->status().pump_cycles until it is > 0, with a 5s steady_clock deadline, the same remedy cc45c55 applied to ConflictAutoPublish. The common case still leaves within a few milliseconds, and a timeout now says the pump completed no cycle in 5s. The file's other tests do not depend on wall-clock timing: StatusReportsRunning and the accessor tests read state set before join() returns, StatusReportsLocalSequence drives pump_all() itself, WaitForDataTimeoutReturns asserts nothing about the result, and ConflictAutoPublish already polls (cc45c55). Verified on Windows (MSVC 19.38, Release, deps from a local cvcpkg prefix), on a box already at 100% CPU from other work, running 16 copies of the test binary at once: * old test: 1 failure in 16 x 50 runs, the same "actual: 0 vs 0"; * new test: 0 failures in 16 x 50 + 16 x 150 runs (3200); median 30ms, p99 114ms, max 419ms per test including stop(); * full suite 8/8, and ctest -R StateSessionStatusTest -j 8 --repeat until-fail:5 passes. (cherry picked from commit 4933281)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
P8a of the vehicle-physics plan: a differentiable dynamic single-track vehicle beside
bike_step(Joe: "start P8a, the dynamic bicycle model").The split
bike_stepis nowbike_control(the trained controller with every governor, emitting(delta_cmd, a_cmd)) thenbike_plant(the kinematic integration). Its outputs are bit for bit what they were.bike_step_bwdis a thin wrapper over the same reverse pass, andbike_control_bwdtakes gradients on the two commands from any other plant. coef_train's 8 tests pass unchanged (bicycle gradcheck dir_rel 8.5e-4).The vehicle (
inc/cvc/nav/detail/dyn_bike.h)dyn_bike_step=bike_controlintodiff::dyn_plant. Everything isCVC_HD.(x, y), the heading, the body velocity(vx, vy)at the centre of gravity, the yaw rate, and the steering angle and drive force behind their actuators.D sin(C atan(B alpha)). The drive and brake force per axle saturates smoothly atmu Fz, and the cornering peak is the friction ellipse's remainder, longitudinal first.Numerics.
(vy, r)advance by implicit Euler, solved by three steps. Each tire is linearized by its secant through its own root in lateral velocity,-F / (w - w0).Adjoint. The plant is written once over a scalar type, and
dyn_plant_vjpruns it on forward-mode duals (doc 19's suggestion).dyn_bike_step_bwdthen hands the command gradients tobike_control_bwd.Parameters from the spec sheet
cvc::nav::dyn_bike_si(SI), converted by length exponent withdyn_bike_params_of(si, frame).cvc::physics::nav_plant::dyn_bike_si_of(vehicle_desc)derives:front_stiffness(0.85) stands in for the front's load sensitivity and steering compliance (understeer).Gates (
nav_dyn_bike_test, 9 tests; the Humvee from its vehicle_desc)bike_step's commands through the plant, 200 ticks, stiff tires, no lag, mu g 40 vs 1.5, mass and drive/brakes at the rear axleThe kinematic limit is exact only for the vehicle
bike_stepassumes. A real body differs physically from itsv' = a:F / cos(delta)on the body.The test reports that case: up to 1.7 apart open loop, and 1.122 vs 1.111 from the goal under the controller.
DynBike.Goldenpins the plant's values for GRL-SNAM's torch twin (tests/data/dyn_bike_golden.json).Not in this PR
rollout_kind::dynamicin the trainers (P8b).