Skip to content

dyn_bike, dyn_4w: opt-in wheel spin in pH form; plant logs carry the wheels; cvc::ph potential and input options - #982

Merged
transfix merged 6 commits into
masterfrom
feat/dyn-wheel-spin
Nov 3, 2026
Merged

transfix merged 6 commits into
masterfrom
feat/dyn-wheel-spin

Conversation

@transfix

@transfix transfix commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Answers the reviewers' actuation point on the vehicle pH plant (GRL-SNAM docs/vehicle-ph-plant.tex): neither dyn_bike nor dyn_4w had wheel spin, so there was no longitudinal slip, wheelspin or lockup, and the learned plant's G(v)u absorbed the whole drivetrain with a potential V(x, y) tied to world position. Every new path is opt-in; the defaults are unchanged.

Wheel spin, in port-Hamiltonian form (dyn_bike.h, dyn_4w.h)

  • State. dyn_spin_state = dyn_state + om_f, om_r (each axle's wheels); dyn4_spin_state = dyn4_state + four wheel speeds.
  • Torques follow the existing split: a >= 0 drives, each axle's T_d = r_w * share(front_drive) * m a; a < 0 brakes, T_b = r_w * share(front_brake) * m |a| against the wheel's rolling, -T_b sg(om) with sg smoothed over the slip floor at the rim. A brake stops and holds a wheel, so a negative a never drives backward (as Jolt's driver).
  • Longitudinal force: Pacejka of the slip ratio, F_x = D sin(C_x atan(B_x sigma / u)), sigma = r_w om - t^T v (the patch's slip velocity; t the wheel's direction on the twist), D = mu F_z, under the existing friction ellipse. The step solves (vx, om) by implicit Euler with the tires and brakes linearized by their secants through their roots: (M + h R_x) d = M(...), SPD, so it never fails and stiff tires stay stable at nav's step.
  • From the spec sheet (dyn_bike_si_of): wheel radius, each axle's wheel inertia (Humvee: 0.47 m, 12 kg m^2 an axle), C_x = C (Jolt's sliding fraction), B_x puts the peak at Jolt's tire_peak_slip (B_x 46.2, peak at slip 0.080).
  • pH form (dyn_spin_ph_*, dyn4_spin_ph_*): x = (p, J om).
    • H gains 1/2 sum J om^2.
    • R gains K d d^T with K = F_x / sigma >= 0 (the exact secant) along d = (-t, r_w e_wheel): d^T dH/dx = sigma, the direction of wheel surface speed less ground speed. PSD at every slip, rolling, spinning or locked. On four wheels t is the patch's speed along the wheel with roll and pitch, so the coupling is reciprocal: no lever term.
    • Port (wheel torque, wheel speed): G = [e_om], y^T u = om^T T, shaft power; the brakes' part -T_b om sg(om) <= 0 at every state.
  • Books (dyn_spin_plant_books, dyn4_spin_plant_books): dH = supplied - braked - dissipated - slip + floor + grade (+ lever + ground on four wheels) + limiter + residual.
  • Live plant: dyn_bike_plant_options::wheel_spin (books gain slip; wheel_speed(i, axle); tire_use reads the slip ratio too).

Plant logs and the learned plant

  • plant_log records each Jolt vehicle's wheels (the single track's two axles' mean angular speeds and rim speeds), the pedals, and the ledger's shaft work and brake energy per tick. Jolt's vehicle API does not expose a per-wheel drive torque; the ledger's shaft power over the wheels' speed is the mean drive torque.
  • cut_flights(..., flight_layout::wide) and cvc plant-log --wide: an 18-column row (attitude, wheels, pedals, shaft and brake power); meta.json names the columns. The 8-column .npy stays the default.
  • cvc::ph::se2: se2_setup::potential = world (V(x, y), default) | none | terrain (the logged grade and roll times two learned coefficients: the gradient of m g z, read where the vehicle is). Non-world models are cvc-ph-se2/3. select_inputs picks inputs by column name, so the wheels' rim speeds can be ports. cvc ph-train --inputs --potential --eval-runs.
  • Fixed on the way: write_plant_log wrote the bundle path into meta.json unescaped, so a Windows bundle run could not be read back.

The learned plant's fit comparison

Plant logs (cvc plant-log --wide) of the Jolt Humvee:

  • swerve: flat open ground, seeds 100-103, mean 12.9 m/s;
  • Austin: the scene-austin-south-small bundle from cvcpkg, terrain and buildings, seeds 200-203, mean 6.0 m/s, ground slope rms 0.052 (max 0.17).

Each environment has 192 flights of 5 s. cvc ph-train was run with steering as a modulation, 5000 steps, 0.05 observation noise, seeds 0 and 1. The loss is the mean model's rollout loss on clean 2 s windows (101 points), the same measure for every column: train seeds, the environment's held-out seed (203 / 103), and the other environment.

Trained on Austin (held out: seed 203; other environment: the swerve)

inputs potential train held-out seed swerve
drive, steer V(x, y) (default) 0.230 / 0.218 0.499 / 0.467 6.79 / 8.33
drive, steer none 0.232 / 0.227 0.503 / 0.465 8.47 / 6.43
drive, steer terrain (ground slope) 0.230 / 0.218 0.472 / 0.441 6.55 / 7.92
drive, steer terrain (body attitude) 0.234 / 0.220 0.486 / 0.448 7.05 / 8.15
rim speeds, steer none 0.152 / 0.173 0.669 / 0.590 10.2 / 7.10
rim speeds, steer terrain (ground slope) 0.142 / 0.179 0.612 / 0.584 9.31 / 6.85

Trained on the swerve (held out: seed 103; other environment: Austin)

inputs potential train held-out seed Austin
drive, steer V(x, y) (default) 0.486 / 0.434 0.511 / 0.685 2.03 / 1.61
drive, steer none diverged / 0.452 diverged / 0.706 diverged / 1.66
drive, steer terrain (body attitude) 0.203 / 0.188 0.445 / 0.397 207 / 206
drive, steer terrain (ground slope) non-finite at step 1378 / 0.427 – / 0.610 – / 1.69
rim speeds, steer none non-finite at step 410 / 0.335 – / 0.498 – / 2.04
rim speeds, steer terrain (body attitude) 0.150 / 0.146 0.187 / 0.177 1e265 / 329
rim speeds, steer terrain (ground slope) non-finite at step 1296 / 0.289 – / 0.560 – / 1.88

What this says

  • V(x, y) buys nothing. Dropping it or replacing it by the terrain term matches or beats it in every column. Trained on Austin, the ground-slope terrain term has the best held-out loss (0.441-0.472 against V's 0.467-0.499).
  • The body's attitude is the wrong terrain signal. It carries the suspension's pitch under acceleration, so on flat ground the term fits the acceleration: held-out 0.40-0.45, better than any other, then 207 on real slopes. That is why the ground's slope from the wheels' contacts was added. On flat ground the ground slope is about 0, its coefficient is not identified, and the term reduces to none.
  • Wheel speeds as ports. Trained on the flat swerve with the attitude term they fit best of all (held-out 0.18), but on Austin they overfit (train 0.14-0.18, held-out 0.58-0.67). Seed 0 diverged without a potential.
  • Across environments, the speed distribution dominates. Austin averages 6 m/s and the swerve 13 m/s, so every model trained on one does 4-15x worse on the other, whatever its potential. A cleaner held-out-environment test needs two environments with overlapping speeds.
  • The trainer is unstable on the swerve with seed 0 whenever V(x, y) is absent. It diverges or goes non-finite with no potential and with the terrain term (whose ground-slope input is about 0 there). Seed 1 is fine, and with it the ground-slope term transfers to Austin as well as V does (1.69 against 1.61-2.03).
  • An input that never moved in training (the ground's slope on flat ground) now keeps a unit scale in ph-train, and every final loss says how many windows stayed finite. Before this, the scale was round-off (rms 7.5e-9), so all of Austin's windows diverged and the loss averaged none of them.

Tests (Windows, MSVC 14.44 Release, local)

Suites run: nav_dyn_spin_test 12/12, nav_dyn_bike_test 23/23, nav_dyn_4w_test 23/23, physics_dyn_bike_plant_test 9/9, ph_se2_test 18/18, ph_se2_train_test 13/13, physics_plant_log_test 14/14, cvc_cli_test 182/182.

Gate (test) Measured
Structure at every slip, 500 states x mu 0.9/0.3 (DynSpinPH, Dyn4SpinPH.TheStructureIsPortHamiltonianAtEverySlip) J skew; R symmetric, K >= 0, w^T R w >= 0 in every sample; y^T u = supplied - braked. 420 of 500 states (single) and 1193 of 2000 wheels (4w) past the longitudinal peak
Vector field vs a 1e-7 s plant step (...TheVectorFieldIsThePlantsAtEverySlip) worst 2.5e-4 of m g (single), 5.6e-4 of its scale (4w)
Books (...StepBooksCloseToSecondOrder), launch at full drive on mu 0.3 (wheels spin to kappa 8.7), then full brakes (they lock) mean residual per step 2.05 → 0.37 → 0.049 → 0.0074 J at hdt 0.01 → 0.00125 (faster than 4x while the slip mode is stiff against hdt, then 4x); abs(sum)/flow 4.9e-4 at 0.01. Swerve past the lateral peak: 3.97x per halving
Gradient, duals vs central differences (DynSpin, Dyn4Spin.PlantGradientMatchesFiniteDifference) 1.8e-8, 1.3e-8
Behaviour (DynSpin.SpinsOnLowGripLocksUnderHardBrakingRollsLikeDynPlant) full drive on mu 0.3: slip ratios 3.57 front / 1.76 rear after 1 s; 8 m/s^2 braking on mu 0.6 locks the front (kappa -0.97) and stops in 34.8 m vs dyn_plant's 33.9 m; wheels at 1% of their inertia: within 2 mm of dyn_plant over 5 s; with the Humvee's, a steady drive accelerates as m + sum J / r^2 = 2785 kg (4% over m) predicts, to 7e-4 m/s
Live plant (DynBikePlant.WheelSpinSpinsLocksAndTheBooksClose), driver on, mu 0.2 rear slip ratio up to 7.0, front lock -0.99; residual 6.8e-5 of the flow
Goldens for GRL-SNAM (DynSpinPH.Golden, Dyn4SpinPH.Golden) the torch twins (GRL-SNAM PR to follow) match to 4.5e-15 (parts) and 7.2e-13 (gradients)
Jolt's wheels in the log (PlantLog.LogsAHumveeSwervingOnJolt) rear rims within 3.1% of the speed on average above 5 m/s; 83 of 1368 ticks past 0.1 slip (the swerve's hard braking locks Jolt's wheels: it has no ABS); flat ground: the body tilts up to 0.027, the ground slope stays 0
Potential options' reverse pass (PhSe2Train.PotentialOptionsGradientsMatchFiniteDifferences), /3 round trip 2.1e-7 (none), within central differences' rounding (terrain)

Defaults unchanged

dyn_bike_golden.json, dyn_bike_ph_golden.json, ext_rollout_golden.json and dyn4_ext_rollout_golden.json regenerate byte-identical. dyn4_golden.json regenerates identical to what master's own dyn_4w.h and test give when rebuilt on this box; both differ from the committed file in 11 last-bit lines (the test passes at 1e-9), so that drift predates this PR and the file is left alone.

For the discrete-gradient step (added after review opened, 1005ab6). dyn_spin_ph_forces_at(p, s, grade, Q[5]) returns every force but the structure's: Q = -R dH/dx + G u + f_eps - m g grade e_x on the five momenta. So dyn_spin_ph_rhs is J dH/dx + Q (to 2.1e-15 of m g), and dH/dx^T Q is dyn_spin_ph_rates_at's balance (to 1.3e-14 of its terms). DynSpinPH.TheForcesAreTheFieldLessTheStructure checks both. It is the hook #978's follow-up (dyn_spin_plant_dg) evaluates at its midpoint. Nothing existing changes.

dyn_spin_plant and dyn4_spin_plant give each wheel (each axle's, on the
single track) its own angular speed, driven and braked by torques with
the existing drive/brake split, and a Pacejka longitudinal tire force of
its slip ratio under the friction ellipse. The longitudinal step solves
(vx, om) implicitly with the tires and brakes linearized by their secants.

In pH form H gains 1/2 sum J om^2, R gains K d d^T with K = F_x / sigma
>= 0 along d = (-t, r_w e_wheel) (the patch's slip velocity), and the port
is (wheel torque, wheel speed). dyn_spin_plant_books and
dyn4_spin_plant_books add slip and braked lines.

dyn_bike_plant gets options.wheel_spin. dyn_plant, dyn4_plant and their
forms are unchanged by default: DynBike.Golden, DynBikePH.*, Dyn4.Golden,
Dyn4PH.* and Dyn4ExtRollout.Golden pass unchanged.
…tial and input options

plant_log records each Jolt vehicle's wheel speeds (the single track's
two axles' means and their rims' surface speeds), the pedals, and the
ledger's shaft work and brake energy per tick. cut_flights takes an
opt-in flight_layout::wide row (18 columns: attitude, wheels, pedals,
shaft and brake power); the planar 8-column layout stays the default.
cvc plant-log --wide writes it, with meta.json naming the columns.

cvc::ph::se2: se2_setup::potential world (V(x, y), the default), none,
or terrain (the logged grade and roll times two learned coefficients:
the gradient of m g z read where the vehicle is). Non-world models are
cvc-ph-se2/3. se2_flights carries the column names; select_inputs picks
the inputs by name (e.g. the wheels' rim speeds as ports). cvc ph-train
gains --inputs, --potential and --eval-runs, and reports the mean model's
clean rollout loss on train, held-out seeds and the eval runs.
… slip pointer

write_plant_log wrote the bundle path into meta.json unescaped, so a run on
a Windows bundle path could not be read back (by load_plant_log_runs or any
JSON reader). dyn4_ph_parts_at fills the slips only when given somewhere to
put them.
…rm reads it

The body's grade and roll carry the suspension's pitch and roll under
acceleration, so a terrain term fitted to them on flat ground learns the
acceleration, not the ground, and blows up on real slopes. planar_sample
gains ground_grade and ground_roll from the wheels' contact points (the
two axles' and the two sides' mean contact heights); the wide row gains
them (20 columns), and cvc ph-train --potential terrain reads them where
the runs have them. On flat ground the body tilts up to 0.027 while the
ground slope stays 0.
…te windows

An input with no variation in training (the ground's slope on flat
ground) had a scale of zero, so every window of a run where it moves
diverged and the reported loss averaged none of them. It now keeps a
unit scale, and each final loss says how many windows stayed finite.
Q = -R dH/dx + G u + f_eps - m g grade e_x on the five momenta, so
dyn_spin_ph_rhs is J dH/dx + Q and dH/dx^T Q is dyn_spin_ph_rates_at's
balance: the hook a discrete-gradient step evaluates at its midpoint.
DynSpinPH.TheForcesAreTheFieldLessTheStructure checks both at 500 states
(2.1e-15 of m g, 1.3e-14 of the terms).
@transfix
transfix merged commit 4b64069 into master Nov 3, 2026
23 of 28 checks passed
@transfix
transfix deleted the feat/dyn-wheel-spin branch November 3, 2026 02:52
transfix added a commit that referenced this pull request Nov 3, 2026
transfix added a commit that referenced this pull request Nov 3, 2026
transfix added a commit that referenced this pull request Nov 3, 2026
… ground (#1002)

pycvc.dyn_bike_plant takes the plant's opt-in options from #982, #983 and #987:
wheel_spin; side_slope; and contact, with contact_field (a sim_world handle,
whose signed distance on contact_plane is copied as it is now), contact_vehicles
and contact_params (a dict of dyn_contact_params' fields). ground, a
pycvc.height_field in world metres (copied), gives the plant a ground height,
which the vehicle climbs and the side slope reads; before, Python had only a flat
ground_z. contact with a world raises, as do contact_field without contact and a
contact setting that does not exist.

The books gain slip, contact_energy, contact_stored, contact_dissipated and
contact_exchange. options() reports the new settings. wheel_speed(i, axle) and
contact_now(i) (the barrier's energy, the damper's power, the points touching and
the body wrench) read an agent.

test_pycvc_physics.py's test_the_dynamic_plant_options:
- wheel spin on grip 0.3 books 1.75 kJ of slip, and the axles' wheels part;
- a 5% ramp costs 51.5 kJ;
- a 10% side slope pulls the vehicle 0.23 m downhill, where the plain ground
  leaves it on its line;
- driven at a wall in another sim_world's map, it stops with its rear axle
  4.55 m short, pressed with 4 points at 23.5 kN, and the damping books 81.6 kJ.
Every run's books close to 1e-9 of the flow.

The contact run uses a 0.005 s substep. At the default 0.01 s the damper, held
over the substep, overshoots this 7.8 m/s impact: the books show
contact_dissipated at -1.5e5 J (the contact supplying energy), the limiter takes
2.4e5 J, and the residual is 3.1e-2 of the flow. At 0.005, 0.0025 and 0.00125 s
the residual is 2.4e-3, 1.3e-3 and 2.6e-4 of the flow. physics_dyn_contact_test
impacts at 5 m/s only.
transfix added a commit that referenced this pull request Nov 8, 2026
…inning (#1045)

dyn_spin_plant_dg (detail/dyn_bike_dg.h, opt-in) solves the momenta
e = (vx, vy, r, om_f, om_r), M = diag(m, m, Iz, J_f, J_r), with Q from
the plant's hook dyn_spin_ph_forces_at (#982) and its optional wrench
(#983). The body's rows take the midpoint. The wheels' rows take
theta_wheels, 1 by default, because the wheels' slip is far stiffer than
the step. The books (dyn_spin_ph_rates_at at e_th) close to the solver's
tolerance, with one more line, `scheme`, for the wheels' damping.

Actuators, clamp, blend and pose are dyn_plant_dg's. dyn_plant_dg now
calls them through dyn_dg_actuators and dyn_dg_finish, and its step is
unchanged. Nothing that calls dyn_plant or dyn_spin_plant changes.

nav_dyn_bike_dg_test gains DynSpinDG.*: rate against dyn_spin_ph_rhs,
actuators to the bit, books, order, stiff wheel slip at nav's 0.06 s
and the live plant's 0.01 s with and without substeps, and cost. docs/NAV_TRAINING.md gets the gates.
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