Skip to content

dyn_bike_plant: compliant contact in pH form against sim_world's field and between vehicles; plant logs keep contact windows - #983

Merged
transfix merged 12 commits into
masterfrom
feat/dyn-contact
Nov 3, 2026
Merged

transfix merged 12 commits into
masterfrom
feat/dyn-contact

Conversation

@transfix

@transfix transfix commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Follows #982 (wheel spin, merged as 4b64069). Retargeted to master; the diff is this PR's alone. Answers the reviewers' collision point on the vehicle pH plant: the dynamic plant "has no world to collide with", cut_flights dropped every contact window, and contacts were resolved only inside Jolt. Opt-in; the defaults are unchanged.

Compliant contact in pH form (cvc/nav/detail/dyn_contact.h)

  • Footprint. The vehicle's outline about its centre of gravity (chassis box and wheels, as limits() reads them), sampled at points l_k (7 per side, 4 per end by default).
  • Against a field (phi, the signed distance, and its gradient):
    • barrier psi_k = 1/2 k (s - d_k)^2 inside the skin s;
    • Hunt-Crossley damper c_k = c (s - d_k) / s on the normal velocity (nothing pulls at separation);
    • Coulomb friction along the obstacle on the barrier's push, its sliding direction smoothed.
  • External port. Each point's world force reaches the body through the paper's external-port map, G_e,k^T F = (R^T F, l_k x R^T F). The plant takes the summed wrench as a port held over the step: dyn_plant(..., wrench), dyn_spin_plant(..., wrench), and dyn_plant_books(..., wrench, &port) books y_e^T u_e.
  • pH form. With the pose in the state (T*SE(2)), H gains Phi = sum_k psi_k and the barrier's force -B^T dPhi/dg is the canonical structure's. R gains R_c = sum_k (c_k b_k b_k^T + f_k a_k a_k^T): the damper along each point's normal and the friction (its secant through zero sliding) along the tangent. PSD.
  • Between vehicles (dyn_contact_pair): each vehicle's points against the other's outline as a rounded rectangle's signed distance (C1 for overlaps under the corner radius), both ways, equal and opposite at the point. The pair keeps its momentum; the barrier's energy and the dissipation go half to each.

The live plant (dyn_bike_plant_options::contact)

  • contact_field: a callback (x, y) -> (phi, grad phi); dyn_bike_plant::sdf_field(field_stack, plane, metres_per_world_unit) builds one from nav's SDF grid (bilinear phi and its own gradient, so the force is the energy's). sim_world::field() (new, one line: the private field_view() made public) hands over sim_world's own field. contact_vehicles (default on): the agents meet each other.
  • Books gain contact_energy (level), contact_stored (its change), contact_dissipated (the dampers' and friction's work) and contact_exchange (what the vehicles passed each other; over a pair, the integrator's error):
    kinetic now - kinetic at attach = drive - brake - dissipated - slip + floor + grade + limiter + contact - contact_stored - contact_dissipated + contact_exchange + residual.
  • No world needed (the Jolt chassis world options.physics remains the other way; use one or the other).

Plant logs: keeping contact windows

cut_flights(..., keep_contact) and cvc plant-log --keep-contact keep the windows with a contact or an impact (a wheel off the ground still drops one) and add a last column, contact: the static contacts the interval began, plus one for another vehicle or an impact.

What a learned plant can learn from it: the mean response of the intervals in contact, read as a port or a modulation of D and G (extra deceleration and damping). What it cannot: where or when a contact happens, or its direction. The rows carry no obstacle, only that the interval touched one, and what it fits is Jolt's rigid contact averaged over the logs' approach speeds and angles.

Measured on the Austin bundle (--wide --keep-contact, seeds 200-203). --keep-contact keeps 202 flights against 192 without it: 10 with a contact, peak 9.6 g. The other 182 windows still drop, for a wheel off the ground or for standing still against the buildings. cvc ph-train --potential terrain, steering a modulation, 5000 steps, held out seed 203, seeds 0 / 1:

inputs train held-out seed
drive, steer 0.322 / 0.340 0.735 / 0.709
drive, contact, steer (contact as a port) 0.255 / 0.236 0.734 / 0.707

The contact port fits the training contacts (train loss -25%) and gives nothing held out, as expected: the rows say that a contact happened, not where.

Against the Jolt plant (DynContactPlant.ComparesWithJoltOnImpacts)

A Humvee at 5 m/s on flat ground, coasting (the dynamic plant raw, Jolt in neutral) into a wall head on, into a wall at 30 degrees, and into a parked Humvee. "Before" is the speed 1 m before contact; "after", "rebound" (normal velocity after over before) and "heading" are 1 s later.

impact plant v before v after rebound heading struck after
wall, head on dyn 4.80 0.89 0.19 0.0 deg
wall, head on Jolt 4.56 0.01 0.00 0.0 deg
wall, 30 deg dyn 4.70 0.91 0.19 +0.4 deg
wall, 30 deg dyn, friction 0.6 4.70 0.68 0.14 -0.1 deg
wall, 30 deg Jolt 4.46 0.04 0.01 -2.8 deg
parked Humvee dyn 5.06 1.90 0.0 deg 2.88 m/s
parked Humvee Jolt 4.82 2.27 0.0 deg 2.28 m/s
  • Restitution. Jolt's rigid chassis box is perfectly plastic (restitution 0). The compliant barrier keeps about 0.19 of the approach even with the Hunt-Crossley damper, so the bump is more elastic (2.88 against 2.28 m/s for the struck vehicle).
  • The 30-degree yaw. Jolt's friction yaws the vehicle into the wall. In the compliant plant the yaw is a balance of the barrier's push (along the wall) and the friction (into it), and with the default friction 0.2 the push wins. At friction 0.6 the yaw turns toward Jolt's sign.
  • Defaults. Barrier k 3e5 N/m and damper c 1.5e4 N s/m per point, friction 0.2, skin 0.05 m. They were chosen to resolve at the live plant's 0.01 s substep, not fitted to Jolt; fitting them is a follow-up.

Tests (Windows, MSVC 14.44 Release, local)

physics_dyn_contact_test 7/7, physics_dyn_bike_plant_test 9/9, nav_dyn_bike_test 23/23, nav_dyn_spin_test 12/12, nav_dyn_4w_test 23/23, physics_plant_log_test (PlantLog.*) 9/9.

Gate (test) Measured
The barrier is its energy's gradient (DynContact.TheBarrierIsItsEnergysGradientAndTheDamperDissipates), wall and pillar, 165 poses in the skin within 5.2e-10 of -dPhi/dpose (central differences); the damper's power is minus its dissipation
A pair (DynContact.APairKeepsItsMomentum), 168 touching poses world forces and moments cancel to 1e-9; each side's barrier within 3.3e-10 of -dPhi/dpose
Books (DynContactPlant.TheBooksCloseToSecondOrder), 5 m/s, substep 0.01 / 0.005 / 0.0025 s wall head on: residual per step 3.23 → 0.70 → 0.16 J (4.6x, 4.4x), abs(sum)/flow 4.0e-3 at 0.01; 30 deg: 1.10 → 0.27 → 0.064 J; parked Humvee: exchange over the pair 237 → 85 → 20 J (second order), residual 2.5e-5 of the flow; the identity closes to 1e-8 of the flow
sim_world's own field (DynContactPlant.StopsAtAWallInSimWorldsField) phi 5.000 m 5 m from an occupancy wall, gradient (-1, 0); a Humvee at 5 m/s stops with its front at 24.50 m (wall at 25 m)
nav's SDF grid as a field (DynContactPlant.ReadsNavsSignedDistanceGrid) 9.5e-7 of the analytic wall
Golden for GRL-SNAM's twin (DynContact.Golden) written; see the GRL-SNAM PR
Contact windows (PlantLog.KeepsContactWindowsWithAFeature) kept with the feature; airborne windows still dropped

Defaults: with contact off, dyn_plant without a wrench and the books without a port are unchanged. DynBike.Golden, DynBikePH.Golden, the spin goldens and dyn_4w's pass as on #982.

Outside the files this work owns: sim_world::field() is one new public line, the existing private field_view() made reachable.

The discrete-gradient hook takes the contact (ee342a8). dyn_spin_ph_forces_at (from #982) gains an optional trailing wrench, the external port's (F_x, F_y, M_z), as dyn_plant_core's. It adds exactly W on the body's momenta and nothing on the wheels (checked in DynSpinPH.TheForcesAreTheFieldLessTheStructure).

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.
… keeps contact windows

The dynamic plant had no world to collide with. dyn_contact.h samples the
vehicle's footprint (chassis box and wheels about the centre of gravity)
and, against a field's signed distance and between vehicles, gives each
point a barrier energy psi = 1/2 k (s - d)^2, a Hunt-Crossley damper on
the normal velocity and smoothed Coulomb friction along the obstacle. The
barrier is minus its energy's gradient in the pose (H, through T*SE(2)'s
canonical structure); the damper and friction are R_c, PSD. Each point's
force reaches the body through the external-port map; dyn_plant and
dyn_spin_plant take the wrench as a port held over the step, and their
books book its energy.

dyn_bike_plant_options::contact (off by default): a contact field
callback (sdf_field builds one from nav's SDF grid; sim_world::field()
exposes sim_world's own), vehicle-vehicle contact, and books lines
contact_energy, contact_stored, contact_dissipated, contact_exchange.

cut_flights(..., keep_contact) and cvc plant-log --keep-contact keep the
contact windows with a contact feature column.

Measured (physics_dyn_contact_test): the barrier within 5e-10 of
-dPhi/dpose; books second order (residual per step 3.23 -> 0.70 -> 0.16
J at 0.01/0.005/0.0025 s, a wall impact); against Jolt at 5 m/s: rebound
0.19 vs 0.00, a parked Humvee pushed to 2.88 vs 2.28 m/s.
… the corner radius held

The contact golden's wall cases sat 0.3-0.65 m off the wall against a
0.05 m skin, so they pinned nothing; every case now has points in the
skin (checked). The step's vehicle parameters are written into the
golden so a twin needs no other file. dyn_rounded_box_sdf holds its
corner radius to the half width and half length; dyn_ph_books' comment
says where the port's energy goes.
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).
An optional trailing wrench (F_x, F_y, M_z), as dyn_plant_core's, joins Q on
the body's momenta, so a discrete-gradient step takes the contact as the
plant does. DynSpinPH.TheForcesAreTheFieldLessTheStructure checks it adds
exactly W on the body and nothing on the wheels.
Base automatically changed from feat/dyn-wheel-spin to master November 3, 2026 02:52
@transfix
transfix enabled auto-merge (squash) November 3, 2026 02:56
@transfix
transfix merged commit 2728bca into master Nov 3, 2026
18 of 28 checks passed
@transfix
transfix deleted the feat/dyn-contact branch November 3, 2026 04:14
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 6, 2026
…ubsteps for fast impacts (#1004)

* dyn_bike_plant: the contact's damper and friction implicit; contact substeps for fast impacts

The compliant contact (#983) held its Hunt-Crossley damper and friction from the
substep's start. Their coefficients grow with the penetration, so in a fast impact
hdt R_c / m passes 2 at the default 0.01 s substep: pycvc's navigator driving the
full-size preset into a wall in sim_world's field at 7.8 m/s reversed the vehicle
within a tick to -3.24 m/s (the reverse clamp), the damper supplied 1.5e5 J
(contact_dissipated < 0), the speed clamp took 2.4e5 J and the residual was 3.1e-2
of the flow. nav's grid SDF makes it worse: phi runs from +1 cell to -1 cell across
the cell at a face, so there the barrier is 4x and the damper 8x as stiff per metre
of approach as against an exact distance.

The damper and the friction are now read implicitly (dyn_contact_implicit), at the
twist the step reaches under the bodies' inertia, the barrier's push and themselves:
(M + hdt R_c) v_d = M v0 + hdt W_c, W_d = -R_c v_d, with the friction's secants
taken again at the slide v_d reaches. The bodies touching each other are solved
together, so W_d stays equal and opposite between vehicles. The contact functions
report each touching point's damped directions (dyn_contact_row) on request; their
outputs are unchanged.

The barrier stays explicit, so a step that carries a point far into it leaves that
energy in the residual. dyn_bike_plant_options::contact_step_depth (0.1 m) cuts a
substep in which a point would close further into equal pieces, held until nothing
touches or closes, so a bounce runs at one step (finer steps for the approach alone
leave the rebound's errors uncancelled). At the default it splits none of the
existing 5 m/s cases. The contact lines' port work uses the step's own hdt, as
dyn_plant_books' port does, so the books' identity holds in every piece.

Measured (physics_dyn_contact_test, MSVC 19.44 Release): the navigator case at
0.01 s now dissipates 8.16e4 J, limiter 0, slowest -0.47 m/s, residual 1.3e-3 of
the flow (at 0.00125 s: 8.19e4 J, -0.47 m/s). New tests
DynContact.TheImplicitDamperOnlyDissipates and
DynContactPlant.AFastImpactAtTheDefaultSubstep (fails on master); the existing
gates pass and DynContact.Golden regenerates byte-identical.

* physics_dyn_contact_test: the implicit solve held to its backward error

DynContact.TheImplicitDamperOnlyDissipates checked M (v_d - v) = hdt (W_c + W_d)
against M |v| + hdt (|W_c| + |W_d|). Stiff dampers (hdt to 1 s) leave v_d nearly
across their directions, so W_d = -R_c v_d is far smaller than the terms the solve
summed, and the check read the solve's rounding as 4.9e-10 on Windows and 1.26e-9
on Linux (CI failed it at 1e-9). It now divides by |A| |v_d| + |b|, R_c's entries
bounded by each row's largest coefficient (a friction secant is at most coulomb /
slide): 3.4e-16, gated at 1e-12.
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