Repository navigation
dyn_bike: an opt-in discrete-gradient step whose energy books close exactly - #978
Merged
Merged
Conversation
…xactly dyn_plant is first order (implicit Euler on (vy, r), a predicted then corrected vx), so dyn_plant_books leaves its error, second order per step, in the residual. diff::dyn_plant_dg (inc/cvc/nav/detail/dyn_bike_dg.h) is the discrete gradient of the plant's port-Hamiltonian form: H is quadratic in the twist, so the step is the implicit midpoint rule on it, M (v1 - v) / hdt = J(M vbar) vbar + Q(vbar), with Q at the midpoint state (the actuators' outputs at the step's midpoint). Then dH = hdt vbar^T Q line for line, and dyn_plant_dg_books closes to the Newton solve's tolerance. Its actuators, clamp and blend are dyn_plant's; the books charge the limiters as dyn_plant_books does. dyn_plant and its callers are untouched, so the defaults are byte-identical. nav_dyn_bike_dg_test (the Humvee): - the rate is dyn_ph_rhs's to 1.1e-15 m g; the actuators are dyn_plant's, bit for bit, in double and float; - books, swerving past the peak at hdt 0.06 to 0.0025 s and braking to a stop: residual at most 1.7e-10 J a step (3.5e-14 to 1.3e-12 of the step's flow), against dyn_plant_books' 25 J to 0.056 J; - second order: 3.92x to 4.03x smaller error per halving of hdt, where dyn_plant is first order (1.98x to 2.13x); - stiff tires (1x, 4x, 16x) at 1 x 0.06 s and 6 x 0.01 s: no coasting step gains energy; a steady turn settles within 0.02% of the kinematic bicycle; - cost: 3.3 to 3.6 us a step against dyn_plant's 0.34 to 0.42 us. The midpoint rule is A-stable but not L-stable: a tire much stiffer than the step swings its slip past zero and back, decaying. At the live plant's 6 x 0.01 s with the Humvee's tires it does not; the test prints the swings.
…/dyn-bike-discrete-gradient # Conflicts: # src/cvc/tests/CMakeLists.txt
…/dyn-bike-discrete-gradient # Conflicts: # src/cvc/tests/CMakeLists.txt
…/dyn-bike-discrete-gradient # Conflicts: # src/cvc/tests/CMakeLists.txt
transfix
added a commit
that referenced
this pull request
Nov 7, 2026
Bumps the project version and every recipe's upstream_version from 3.7.11 to 3.7.12. The v3.7.12 tag on this commit is the first release with the multi-car controller template (pycvc_gl.cars, #1031 #1035 #1040), the hidden-subtree fix in cvcGL (#1037), the discrete-gradient dyn_bike step (#978), semi-implicit Euler by default in the nav rollout (#981), the implicit contact damper (#1004, #1038), and generated_world's roads and water (#1032, #1034).
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.
What
An opt-in step for the dynamic single-track vehicle whose energy books close exactly:
diff::dyn_plant_dganddiff::dyn_plant_dg_books, in a new headerinc/cvc/nav/detail/dyn_bike_dg.h.dyn_bike.h,dyn_plantand everything that calls them are untouched, so the defaults are byte-identical.DynBike.GoldenandDynBikePH.Goldenpass unchanged.Why
dyn_plantis first order: implicit Euler on (vy, r), and a predicted then corrected vx. Sodyn_plant_booksleaves its error, which is second order per step, in the books' residual. The GRL-SNAM whitepaper's future work names a discrete-gradient step as the way to close the books exactly.How
H = 1/2 v^T M vis quadratic in the twistv = (vx, vy, r), so its discrete gradient is the midpoint twist. The step is the implicit midpoint rule on the twist:Qis the tires, the axle forces, drag, rolling resistance and grade, taken from onedyn_ph_parts_atat the midpoint state. That state uses the actuators' outputs at the step's midpoint, which is what makes the step second order while the actuators move.Jis skew, sodH = hdt vbar^T Q(vbar)holds line for line, anddyn_plant_dg_bookscloses to the solve's tolerance.v1 = v. Its Jacobian comes from forward-mode duals, with a backtracking line search.dyn_plant's. The books charge the clamp and the blend to the limiter line, asdyn_plant_booksdoes.Gates (
nav_dyn_bike_dg_test, the Humvee in metres)dyn_plant_dgdyn_plantdyn_ph_rhs, 800 states at every slipdyn_plant's, double and floatStiff tires: what differs from
dyn_plantS hdt / m >> 1) swings its slip past zero and back, decaying.dyn_plant's implicit Euler lands on the root in one step instead.dyn_plant.dyn_plant's at 0.06 s: sliding from 12 m/s, it ends at 9.7 kJ against the reference 10.1 kJ, wheredyn_plantends at 23.4 kJ.1/2 |v1 - v|_M^2line. That is not this step and is not done here.Wheel spin
The
plant-physicssession ownsdyn_bike.h,dyn_4w.handdyn_bike_plant, and is adding wheel-spin states. This header reads only whatdyn_bike.halready exports:dyn_ph_parts_at,dyn_ph_rates_at,dyn_ph_hamiltonian,dyn_clamp,dyn_stateanddyn_step_free.4b640693), as a separatedyn_spin_state(body state plusom_f,om_r). The spin form is its own set,dyn_spin_ph_*, anddyn_state,dyn_ph_parts_at,dyn_ph_booksanddyn_plant's existing signatures are unchanged, so this PR is unaffected.dyn_spin_ph_forces_at(p, s, grade, Q[5]), the generalized force over (vx, vy, r, om_f, om_r). dyn_bike_plant: compliant contact in pH form against sim_world's field and between vehicles; plant logs keep contact windows #983 (2728bca8) added its optional contact wrench.dyn_spin_plant_dg. It is the same midpoint solve on the 5-vector, with M = diag(m, m, Iz, J_f, J_r), and its books come fromdyn_spin_ph_rates_atat the midpoint.Local
MSVC 14.44 Release, deps from the local cvcpkg prefix, on the branch with master (
8f468c18, 2026-11-06) merged in. That merge also brings #1003, the fix forari_chat_component's Debug-runner timeout, which failed this PR'spackage-linux / libcvc-debug:nav_dyn_bike_dg_testnav_dyn_bike_testnav_dyn_spin_testphysics_dyn_bike_plant_testphysics_dyn_contact_testnav_dyn_ph_full_testclang-format 18 is clean on the new files.