Skip to content

nav: dyn_spin_plant_dg, the discrete-gradient step with the wheels spinning - #1045

Merged
transfix merged 1 commit into
masterfrom
feat/dyn-spin-dg
Nov 8, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/dyn-spin-dg

Conversation

@transfix

@transfix transfix commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

What

diff::dyn_spin_plant_dg in inc/cvc/nav/detail/dyn_bike_dg.h: the discrete-gradient step of #978, now with the wheels spinning. It is opt-in, and nothing that calls dyn_plant, dyn_spin_plant or dyn_plant_dg changes. dyn_bike.h, dyn_4w.h and dyn_bike_plant are untouched.

  • The solve. A 5-vector solve on e = (vx, vy, r, om_f, om_r) with M = diag(m, m, Iz, J_f, J_r):

    M (e1 - e) / h = J(M e_th) e_th + Q(e_th),   e_th = e + Theta (e1 - e),   Theta = diag(1/2, 1/2, 1/2, th, th)
    

    Q comes from the agreed hook dyn_spin_ph_forces_at (dyn_bike, dyn_4w: opt-in wheel spin in pH form; plant logs carry the wheels; cvc::ph potential and input options #982), with its optional wrench (dyn_bike_plant: compliant contact in pH form against sim_world's field and between vehicles; plant logs keep contact windows #983). J comes from dyn_spin_ph_J. The actuators sit at the step's midpoint.

  • Books. dyn_spin_ph_rates_at at e_th, times h, plus the wrench's work. J is skew, so H(e1) - H(e) = h e_th^T Q(e_th) - (th - 1/2) sum J dom^2 exactly. The second term is a new books line, scheme. It is at least 0, and exactly 0 at th = 1/2.

  • Actuators, clamp, blend, pose. These are dyn_plant_dg's. They are factored into dyn_dg_actuators and dyn_dg_finish, and dyn_plant_dg calls the same helpers. All of dyn_bike: an opt-in discrete-gradient step whose energy books close exactly #978's tests pass unchanged.

  • Newton. The Jacobian uses forward-mode duals through one tire evaluation per direction (dyn_spin_dg_rate_one). There is a backtracking line search on |M^-1 F|.

    • Past a tire's peak, at a crawl at 0.06 s, the Jacobian can turn indefinite. A Newton direction that two halvings cannot make descend then gives way to a secant step, M - h (J - R) Theta, with R >= 0 from dyn_spin_ph_R. That step always descends.
    • A step at round-off is taken whole.
  • Options. dyn_spin_dg_options: theta_wheels (default 1), substeps (default 1), max_iters 40.

  • Out of scope. The ground form (dyn_plant_ground).

The decision: the wheels' rows at the step's end (th = 1)

The wheels' slip is stiff: h lambda is 60 to 600 at 0.06 s on the Humvee. The midpoint rule is A-stable but not L-stable, so at th = 1/2 the slip swings every step once disturbed. Substeps help only near h lambda of 2 (25 substeps of 0.06 s).

At th = 1 on the wheels alone, the slip's amplification is about (1 - b/2) / (1 + a + b/2), where a ≈ 120 b on the Humvee. So the slip settles in a step or two, about as dyn_spin_plant's does. Three things come with that:

  • the wheels' speeds are first order;
  • the books stay exact through scheme;
  • the step is still ten times nearer the converged solution than dyn_spin_plant at every hdt.

Substeps stay at 1.

Gates (nav_dyn_bike_dg_test, DynSpinDG.*, the Humvee)

Gate th = 1 (default) th = 1/2 dyn_spin_plant
Rate against dyn_spin_ph_rhs, 500 states (rolling, spinning, locked, reversed; grades 0 to 0.08), mu 0.9 and 0.3 ≤ 8.2e-15 of m g; wrench rows 3.3e-16; one-tire Jacobian rate 1.1e-14 (gate 1e-12) the same
Actuators against dyn_spin_plant, lags and slew on, 100 states bit for bit, double and float the same
Books' residual: swerve past the peak (mu 0.6), launch and lock (mu 0.3, κ to 8.8), swerve against a wrench; hdt 0.06, 0.02, 0.01, 0.005, 0.0025 s worst 3.3e-10 J a step, 2.4e-15 to 1.4e-12 of the step's flow (gate 1e-10); 0 unconverged the same, scheme exactly 0 mean 27 J (swerve), 240 J (launch), 20 J (wrench) a step at 0.06 s; 0.04 to 0.06 J at 0.0025 s
Order: error at 2 s of a turn-in, per halving, 0.04 to 0.005 s 2.17x to 2.30x (2.4e-2 at 0.04 s) 4.09x to 4.15x (5.5e-3 at 0.04 s) 2.01x to 2.14x (0.24 at 0.04 s)
Order, 2 to 0.25 ms 2.03x to 2.14x 4.01x to 4.05x 2.03x to 2.14x
Coasting, rims 1.5x the ground, from 0.5, 3 and 12 m/s at 0.06 and 0.01 s no step gains energy (gate 1e-12 of H) the same
Newton steps a solve 3 to 4 on average (at most 9, launching); 6.3 at a crawl at 0.06 s (at most 9) 3 to 4 on average (at most 9, launching)
Cost per step, double (float) 12 to 13 µs at 0.06 s (8 to 10 µs); 5 to 7 µs at 0.01 s (3 to 4 µs) 6 to 9 µs; 4.3 to 4.7 µs 0.4 to 0.5 µs

The order gates are: th = 1/2 between 3.4x and 4.6x per halving on both ranges; th = 1 between 1.7x and 2.6x, and under 0.2 of dyn_spin_plant's error at every hdt.

Stiff wheel slip (DynSpinDG.StiffWheelSlip)

The low-speed blend is off so the runs compare. The reference is th = 1 at 0.1 ms. A swing is a sign change in the slip's step-to-step change, each over 1 mm/s, counted on either wheel.

Scenario, at one 0.06 s step dyn_spin_plant th = 1/2, 1 5 substeps 25 substeps th = 1
Lock: brake 8 m/s² from 20 m/s, mu 0.6 (42 steps) 2 swings; vx −0.378 m/s off 6; −0.104 2; −0.100 2; −0.100 2; −0.113
Spin: drive 4 m/s² from 5 m/s, mu 0.3 (33 steps) 0; rear rim −4.98 m/s off 0; −0.54 0; −0.50 0; −0.50 0; −0.56
Coast from 0.5 m/s, rims 1.5x (50 steps) 0 98 98 4 2
Coast from 3 m/s 1 98 36 0 3
Coast from 12 m/s 4 98 8 0 6

At the live plant's 0.01 s, th = 1 swings 2, 0, 2, 0 and 0 times, against dyn_spin_plant's 2, 0, 0, 0 and 0. th = 1/2 still swings 590, 149 and 34 times coasting. Every DG configuration solves (0 unconverged), and no coasting step gains energy.

Cost

The cost run is CostPerStep's 600 s swerve at 0.06 s, which spends most of its time at a crawl (0.2 to 15.5 m/s). There th = 1 averages 6.3 Newton steps, against 3.9 for th = 1/2. Capping Newton's own line search at two halvings before the secant step cut it from 20 µs to 12 µs a step. At 0.01 s, th = 1 is 3.6 steps and 5 to 7 µs.

The timings come from a shared build host, so expect ±30%. dyn_plant_dg's timing on the same runs is 2.8 to 4.5 µs.

Tests run locally (Windows, MSVC, cvcpkg prefix)

  • nav_dyn_bike_dg_test: 13/13, all 7 DynBikeDG and all 6 DynSpinDG.
  • nav_dyn_bike_test 23/23, nav_dyn_ph_full_test 8/8, nav_dyn_spin_test 13/13.
  • nav_plant_test 28/28 run (5 experiments skipped: they run only with their env flags set), physics_dyn_bike_plant_test 10/10, physics_dyn_contact_test 9/9. None of these includes dyn_bike_dg.h.
  • clang-format 18 on the changed lines: clean.

docs/NAV_TRAINING.md gets a short section and the gates table after dyn_plant_dg's.

…inning

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.
@transfix
transfix merged commit fcfc4ee into master Nov 8, 2026
29 checks passed
@transfix
transfix deleted the feat/dyn-spin-dg branch November 8, 2026 04:02
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