Repository navigation
dyn_bike, dyn_4w: the full (q, p) port-Hamiltonian form; the single track's side slope with gravity in H - #987
Merged
Merged
Conversation
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.
…ope, gravity in H The form had only its momentum part. dyn_ph_T and dyn_ph_rhs_full give q' = T(q) v and p' = -T(q)^T dV/dq + (J(p) - R) v + G u + f_eps + f_g, the structure [[0, T], [-T^T, J(p)]] skew and Poisson. On a ground (any at(x, y, mu, height) sampler) the potential m g h(centre of gravity) is in H, and dyn_ph_hamiltonian, dyn_ph_rates_at and the books take it. dyn_plant takes an optional slope across the heading (gravity's body-y component on the lateral solve). dyn_plant_ground and dyn_plant_books_ground (and their wheel-spin twins) apply gravity along and across the heading from the ground's gradient (the tangents: the planar model's potential) and book the grade line as -dV. dyn_bike_plant_options::side_slope turns it on in the live plant. dyn_4w had no side-slope gap (grade_force is -T^T dH/dg to round-off); its full form adds the pose: dyn4_ph_T, dyn4_ph_grad_full, dyn4_ph_J_full, dyn4_ph_rhs_full, the plant's field with grade_force. nav_dyn_ph_full_test: the structure (skew, Jacobi), the pose update q1 = q0 + hdt T(q1) v1, the full vector field, closed-loop side-slope books (second order with gravity in H; the momentum-only books drift), and DynPHFull.Golden for GRL-SNAM's twin. Every path is opt-in: the existing goldens regenerate byte-identical.
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.
transfix
enabled auto-merge (squash)
November 3, 2026 04:32
This was referenced 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.
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.
The vehicle plants' port-Hamiltonian form had only its momentum part:
dyn_ph_rhsgavep'with the pose left out, and the single track took gravity as the power of a grade along its heading, given as data. With no slope across the heading, H carried no potential. This adds the full (q, p) form beside the momentum-only one for both plants, and the single track's slope across its heading with gravity as a potential in H. Everything is opt-in or additive; every existing output and golden is unchanged.Follows #982 (wheel spin, merged as 4b64069) and #983 (contact, merged as 2728bca); it touches the same parts of
dyn_bike.h. The diff againstmasteris this PR's alone.The full form (
dyn_bike.h):dyn_ph_T;dyn_ph_J_full=[[0, T], [-T^T, J(p)]]. It is skew and Poisson: T*SE(2)'s canonical structure in body momenta, withJ(p)as its coadjoint block.dyn_ph_rhs_fullhas two overloads:f_g = -m g (grade, side, 0); itsp'isdyn_ph_rhs's, to the bit, whenside = 0;-T^T dV/dq = -m g (along, across, 0). There is no moment, since V is the centre of gravity's.at(x, y, mu, height)sampler (dyn_4w.h's):dyn_ph_slope,dyn_ph_potential,dyn_ph_grad_q;dyn_ph_hamiltonian(T + V);dyn_ph_rates_at, whose grade line is-dV/dt = -m g (along vx + across vy).The side slope.
dyn_plantgains an optionalside(the slope across the heading). Gravity's body-y component,-m g side, joins the lateral solve's force.dyn_plant_groundsamples the ground under the centre of gravity at the step's start and applies gravity along and across the heading.dyn_plant_books_groundbooks it with the grade line equal to-dV, the potential's change.dHstays the kinetic energy's, sodH - gradeis the change ofdyn_ph_hamiltonian(p, ground, .).dyn_spin_plant_groundanddyn_spin_plant_books_grounddo the same for the wheel-spin plant.Sine or tangent. The slopes are the ground's gradient at the centre of gravity, along and across the heading: the tangents of the slope angles. The model's pose and twist are planar (projected), so the force whose work is
-dV, with V = m g h(x, y), is-m g grad hat any angle. The sine is gravity's component along the surface for a speed measured along it. Over the projected pose it leavesm g (tan - sin), aboutm g θ³/2, unbooked, and a smaller step does not remove that (measured below). The existing path keeps nav'sgrade_atsine. The gradient is taken by central differences over1e-3 (lf + lr), asdyn4_gradedoes.dyn_4w had no side-slope gap:
grade_forcealready appliesdyn4_gradealong and across the heading, and its terrain energy is in H. Its gap was the pose missing from the state.dyn4_ph_T,dyn4_ph_coords_full(12 coordinates),dyn4_ph_grad_full,dyn4_ph_J_full,dyn4_ph_rhs_full.-T^T dH/dgisdyn4_grade's force and moment, to round-off, sof_grademoves into the structure.grade_forceisdyn4_ph_rhs_full. Withoutgrade_forceit lacks-T^T dH/dg, so the vehicle gets the hill for free.The live plant.
dyn_bike_plant_options::side_slope(off by default) usesdyn_plant_books_groundand its wheel-spin twin onoptions.plant.ground_height. Its books' grade line becomes-dV. The driver still reads #869's sine along the heading.Measured (MSVC 14.44 Release, Windows). New suite
nav_dyn_ph_full_test, 8 tests:DynPHFull.TheStructureIsSkewAndPoisson, 300 states on a hillsideJ_fullexactly skew;e^T J e≤ 1.1e-16 of its terms; Jacobi defect ≤ 3.1e-9 (central differences);dV/dqwithin 1.6e-9 m g of the exact gradient;-T^T dV/dqwithin 3.5e-17 of-m g (along, across, 0)DynPHFull.ThePoseUpdateIsTvq1 - q0 = hdt T(q1) v1to 1.8e-16 over 400 states (flat and hillside); a first-order step ofq' = T(q) v: the error againstT(q0) v0is 0.176 → 0.087 → 0.043 → 0.021 for hdt 0.04 → 0.005DynPHFull.TheVectorFieldIsTheFullFormsAtEverySlip, 400 states × mu 0.9/0.6, a 1e-5 s stepq'6.1e-5 of the speed,p'1.65e-4 m g (ground and data overloads)DynPHFull.SideSlopeBooksCloseWithGravityInH, closed loop across a 15% hillside with swells, the body slipping (up to 0.052 rad)DynPHFull.TheWheelSpinPlantTakesTheSlopeAcrossItsHeadingDyn4PHFull.TheStructureIsSkewAndPoissonAndTheGradeForceIsIts, 200 statese^T J e≤ 1.7e-16; Jacobi ≤ 9.1e-11;dH/dgwithin 1.6e-8 m g L of H's differences;-T^T dH/dgwithin 6.9e-17 ofdyn4_gradeDyn4PHFull.TheVectorFieldIsTheFullFormsWithTheGradeForce, 300 statesgrade_forcethe momenta miss up to 0.20 of theirs; pose step vshdt T(q1) v11.6e-16DynPHFull.Goldentests/data/dyn_ph_full_golden.json(CVC_DYN_PH_FULL_GOLDEN_WRITE=1), for GRL-SNAM's torch twinDynBikePlant.SideSlopePullsDownhillAndBooksThePotential, 6 s across a 10% side slope, wheel straightUnchanged. DynBike.Golden, DynBikePH.Golden, the ext_rollout and dyn4_ext goldens, dyn_spin_ph, dyn4_spin_ph and dyn_contact all regenerate byte-identical. dyn4_golden.json passes its check at 1e-9; it is not rewritten here because of the 11 last-bit lines master's own build already drifts by (noted on #982).
GRL-SNAM's twin of the full form, with its parity test from this golden, is in CVC-Lab/GRL-SNAM#146 (with the wheel-spin and contact twins): values within 2.1e-14 relative, gradients within 3.2e-11.