Skip to content

physics: the energy ledger (P3): every vehicle's energy, term by term, with its source - #690

Merged
transfix merged 6 commits into
masterfrom
feat/energy-ledger
Oct 18, 2026
Merged

transfix merged 6 commits into
masterfrom
feat/energy-ledger

Conversation

@transfix

Copy link
Copy Markdown
Owner

P3 of the vehicle physics roadmap: the energy ledger (doc 31's D8). Every vehicle's energy since it was added, term by term, measured each engine sub-step. The ledger includes a battery or fuel source, and the snapshot, its JSON and the state tree carry it.

It also recalibrates both presets from engineering documentation: the M1097A2 against AM General's sheet, the TM and the Army's dynamometer tests of its engine, and the RoboRacer against the UT-AV lab's configuration. That fixes the two preset problems the ledger found.

The ledger

vehicle_state::energy (vehicle_energy) balances like this, in joules:

supplied + idle + fields + drivetrain_split
  = brake + tire + aero + rolling + medium + drivetrain + suspension + chassis_damping
    + stored + residual

The vehicle is the chassis, its wheels and its drivetrain, engine included (D8):

  • supplied is the engine torque's work, and idle is what Jolt's idle-speed clamp adds. So coasting with no input supplies exactly nothing.
  • stored covers the kinetic energy of the chassis, wheels and engine, plus potential and spring energy.

How each term is measured. With a ledger, the Jolt controller runs copies of Jolt 5.6.0's WheeledVehicleController::PostCollide and friction solve (MIT, attributed in the file), with measurements between their steps. The copies change no arithmetic: a measured run equals an unmeasured one bit for bit, and every P2 measurement is unchanged to the last printed digit.

  • Exact:
    • the engine torque's work and the idle clamp;
    • engine and wheel damping, clutch slip and engine braking, from Jolt's implicit drivetrain step, every flow at its end speed, so slip is never negative;
    • the brakes, including a locked wheel's sliding;
    • tire slip, impulse by impulse in the friction solve.
  • Estimated: the lateral warm start, from its impulse and the velocities it left.
  • Modelled: the dampers (c v² with Jolt's c), and the work of the facade's drag, rolling, compaction and field loads, each charged to its cause.

drivetrain_split. Jolt solves engine, clutch and wheels with an estimate of the brake and ground torques, then undoes the estimate before the friction solve. That leaves each driven wheel dL·τ/I more energy, where dL is the clutch's angular impulse and τ the estimate's. This term is that energy, computed exactly from Jolt's numbers: a known numerical error, itemized so the residual is the rest.

  • The split is proportional to the collision step: it halves when the step halves.
  • So the closed-cycle gate is on residual + split, at the step a twin runs at (8 for the Humvee).
  • The residual alone is gated at every step.

The source (vehicle_desc::energy):

  • A battery draws (supplied + idle) / motor_efficiency. Braking returns regen_efficiency of the braking energy, up to max_regen_power, never counting what the split made in a braked wheel.
  • Fuel burns on a Willans line, (supplied + friction + accessories) / (indicated efficiency × heating value), while fuelled (under throttle or at idle); a diesel burns none on the overrun.
  • The ledger reports state of charge, fuel used and left, source energy and Wh/km. An empty battery or tank gives no more throttle.
  • Presets: the Humvee burns diesel on its engine's dynamometer Willans line from a 95 L tank. The RoboRacer has a 55.5 Wh battery (85% pack to shaft, 70% regen up to 150 W, estimates until measured).

Where it is published:

  • the snapshot and its JSON (state.energy, desc.energy_source);
  • vehicles.<name>.energy.{P_W, supplied_J, idle_J, brake_J, tire_J, aero_J, roll_J, medium_J, drivetrain_J, drivetrain_split_J, suspension_J, chassis_damping_J, fields_J, stored_J, residual_J, regen_J, source_J, soc, fuel_kg, fuel_left_kg, distance_m, Wh_per_km}, in D11's names;
  • save(), so a replay reproduces the ledger.

Gates (physics_energy_test, Windows MSVC)

Gate Measured
A closed cycle over five 1 m hills: accelerate to 10 m/s, hold the speed (throttle up the hills, brake down them), stop and stand. |residual| ≤ 2% of supplied at any step; |residual + split| ≤ 2% at 8 collision steps At 8: 640 kJ supplied; residual −64 J (0.01%); split +4.5 kJ (0.70%). The split is 3.9% at 2 steps and 1.4% at 4
Coasting with no input from 15 m/s: supplied = 0, and ΔKE + ΔPE = −dissipated within 2% supplied 0; 211 kJ of stored energy lost against 211 kJ dissipated; residual +52 J
Coasting down a 6° ramp in neutral: KE gained = −ΔPE − dissipated within 2% +62.4 kJ kinetic, −73.9 kJ potential; residual +46 J
Regeneration never credits more than the braking energy RoboRacer, three 5 m/s stops: 79.4 J returned of 117.9 J of braking (67%); 2.9 J at a 2 W cap
The RoboRacer's split shrinks with the step: |residual + split| ≤ 2% at 32 Split 20.8 / 11.5 / 5.2 / 2.2 / 1.1% at 2 / 4 / 8 / 16 / 32 steps; residual ≤ 0.06%
Fuel on the Willans line Idle 1.653 kg/h, the line's 1.653 kg/h; none on the overrun

Also tested:

  • the empty tank;
  • that measuring changes nothing (identical state with and without the ledger);
  • the ledger after save, restore and replay;
  • the published keys and the JSON against vehicle_state.

The presets against the field

Every value in vehicle.cpp names its source:

  • [AMG], AM General's M1097A2 sheet;
  • [TM], TM 9-2320-280-10, table 1-15;
  • [DTIC], the Army's ISO 8178 dynamometer modes for the 6.5 L (TARDEC TFLRF, DTIC ADA449196);
  • [lab], ut-av.pages.dev and ut_automata's vesc.lua;
  • [trx], Traxxas's listing;
  • [derived] and [est].

New powertrain terms in vehicle_desc:

  • torque_curve, the net curve;
  • engine_friction_curve, motoring friction, acting only with the throttle shut;
  • clutch_strength, the converter's coupling;
  • converter_k, converter_stall and converter_coupling, a torque converter (see below);
  • driveline_efficiency;
  • shift_{up,down}_rpm_light, a throttle-dependent shift schedule, on the gearbox input's speed.
Check Published The twin
M1097A2 at GVW, 0–30 mph 9.4 s, the Army's requirement [AMG] 8.9 s
M1097A2 at GVW, 0–50 mph 26.1 s [AMG] 23.6 s
Idle fuel 2.6 lb/h on the dynamometer, without vehicle accessories [DTIC] 1.95 L/h with 2.5 kW of them
Range at GVW, 30–40 mph, hilly, hard surface 442 km bias-ply, ~490 km radial [TM] 596 km level, 600 km over 3 m hills, at 35 mph on radials

The range gap is open. The twin goes about 22% further than the TM says, with only the documented losses modelled. Closing it needs measurements:

  • a coast-down, which gives C_rr and C_d·A;
  • a logged fuel flow;
  • or DTIC ADA259919's M998 steady-speed consumption.

The range test pins the present calibration until then.

The two preset findings are resolved:

  • The Humvee's drivetrain lost about half the engine's work to Jolt's defaults (engine damping 0.2/s at every throttle, a clutch of strength 10). It now takes 20% at a steady 35 mph, with the dynamometer's friction acting only with the throttle shut, a converter's coupling of 40 and 82% through the gears.
  • The RoboRacer's split exceeded its supplied energy while braking. With the lab's 15.15:1 gearing and a 2e-6 kg·m² rotor, the split is 21% at 2 steps and halves with each halving. An energy-accurate RoboRacer run wants 32 collision steps. Modelling the VESC's braking as motor torque, as the real car brakes, would remove most of the split.

A torque converter, and a driver that trims its error

P4's plant (the next PR) found the Humvee speeding up at 3.4 m/s² with the throttle shut and the brakes at half. Jolt holds an idling engine at its idle speed, and with a stiff clutch that clamp drove the wheels with about 2.9 kN·m of creep. This PR fixes it in the plant:

  • converter_k makes the clutch a torque converter's. It carries at most (rpm / K)², about 53 N·m at idle for the 4L80-E.
  • It multiplies the engine's torque, 2:1 at stall falling to 1 at the coupling point. The gear ratios are scaled by that torque ratio, so Jolt's clutch books the converter's loss and no energy is made.
  • The automatic shifts on its input's speed, not the engine speed a slipping converter lifts.
  • The driver model gains an integral trim on its acceleration error, saved with its other memory.

With these, a hill start on 15% reaches 5.6 m/s in 6 s, and the GVW acceleration meets the Army's figures.

The new knobs in the state tree

  • The powertrain's scalar knobs are vehicles.<name>.tuning.*, seeded and applied as the others are: clutch_strength, converter_k, converter_stall, converter_coupling, driveline_efficiency, shift_up_rpm_light and shift_down_rpm_light.
  • The friction curve is tuning.engine_friction_curve, a string of rpm:N m points ("700:78, 2040:87, 3400:128", or "none").
  • The driver's trim is read back as vehicles.<name>.accel_trim.
  • The fixed settings (the torque curve, the energy source's fields) are in the snapshot's JSON (desc).
  • An invalid tuning value is now ignored on its own. Before, one bad knob kept every later change to that vehicle from applying.

Every key says what it is

Every key the binding owns describes itself, for other applications such as a UI, a validator or a remote peer. Each key has a comment and cvc::state properties:

  • access: build, knob, command or telemetry;
  • unit on a number: SI, 1 for a ratio;
  • a recommended min and max on a knob or a command.

The ranges are recommendations; the world still validates on its own. The table is src/cvc/physics/binding_meta.cpp. physics_vehicle_test walks every key published under physics.* (more than 150) and requires a comment and an access on each.

Node properties are new to cvc::state (STATE_API.md documented them, but they did not exist). They came in #685, merged first; this branch builds on them.

nav_stats.energy_J and energy_per_km come with P4's plant seam, where the navigator first reads a physics plant.

Tests

  • physics_energy_test: 11 tests.
  • physics_vehicle_test: 24 tests. The ledger changes none of their measurements; the recalibrated presets do, and the docs carry the new figures.
  • physics_world_test: 40 tests.
  • Full ctest on Windows: all pass except three ImageMagick coder-module lookups in this local environment (ImageTest.ReadsCmykInputAsRgb, CvcCliTest.Vol2Img* / Img2Vol*), unrelated.

Docs: docs/PHYSICS_API.md (the powertrain, the presets and their sources, the energy ledger) and NAV-VEHICLE-PHYSICS-ROADMAP.md (P3 done).

…, with its source

vehicle_state::energy balances each engine sub-step:
supplied + idle + fields + drivetrain_split = brake + tire + aero +
rolling + medium + drivetrain + suspension + chassis_damping + stored +
residual. The vehicle includes its engine (doc 31 D8): supplied is the
engine torque's work and idle what Jolt's idle-speed clamp adds, so
coasting with no input supplies exactly nothing.

The Jolt controller measures it in copies of Jolt 5.6.0's PostCollide
and friction solve (MIT, attributed), with measurements between their
steps and no arithmetic changed: a measured run equals an unmeasured
one bit for bit (vehicle_desc::energy_ledger), and every P2 number is
unchanged. Engine, idle, drivetrain, brake and tire terms are exact;
the drivetrain flows are taken at the implicit step's end speeds, and
drivetrain_split is the energy Jolt's estimate-undo leaves in each
driven wheel (dL tau / I), itemized. Dampers, chassis damping and the
facade's loads are charged to their causes.

energy_source: a battery (motor efficiency; regen of the vehicle's own
braking, capped) or fuel (thermal efficiency x LHV, idle flow), with
state of charge, fuel used and left, and Wh/km; an empty source cuts
the throttle. The Humvee runs on diesel and the RoboRacer on a 55 Wh
battery (estimates). The ledger is saved, snapshotted, in the JSON and
published as vehicles.<name>.energy.* in D11's names.

Gates (physics_energy_test): a closed cycle over hills, residual -308 J
of 593 kJ supplied (0.05%), split +16.3 kJ; coasting supplies 0 and
loses what it dissipates (residual +35 J of 132 kJ); coasting downhill
gains -dPE - dissipated (residual +38 J of 54 kJ); regeneration returns
60% of the brakes' own energy, within its cap.
The M1097A2 preset now names a source for every value: AM General's
M1097A2 sheet, TM 9-2320-280-10, and the Army's ISO 8178 dynamometer
modes for the 6.5 L (TARDEC TFLRF, DTIC ADA449196). The RoboRacer's
come from the UT-AV lab's configuration (ut-av.pages.dev, vesc.lua) and
Traxxas's listing. Estimates are marked as estimates.

New powertrain terms in vehicle_desc: a net torque curve, a motoring
friction curve (it acts only with the throttle shut), the converter's
coupling (clutch_strength), the driveline's efficiency, and a
throttle-dependent shift schedule. Fuel burns on a Willans line,
(shaft work + friction + accessories) / indicated efficiency, while
fuelled, and none on the overrun.

Field checks (physics_energy_test):
- M1097A2 at GVW reaches 30 mph in 10.1 s and 50 mph in 25.1 s,
  against the Army's 9.4 / 26.1 s.
- Idle fuel follows the Willans line.
- The cruising range is 602-613 km against the TM's 442 km
  (bias-ply; about 490 km on radials). This gap is open, and the test
  pins the calibration.

Gates: the closed cycle checks |residual + drivetrain_split| <= 2% at
8 collision steps (0.97%; the split halves with each halving of the
step). The RoboRacer, with the lab's 15.15:1 gearing, needs 32 steps
(1.1%). The Humvee's drivetrain takes 19% of the engine's work at
cruise, down from about half with Jolt's defaults.
P4's plant found the Humvee speeding up at 3.4 m/s^2 with the throttle
shut and the brakes at half. Jolt holds an idling engine at its idle
speed, and with a stiff clutch that clamp drove the wheels with about
2.9 kN m of creep.

vehicle_desc::converter_k (with converter_stall and converter_coupling)
makes the clutch a torque converter's:
- it carries at most (rpm / K)^2, about 53 N m at idle for the
  M1097A2's 4L80-E;
- it multiplies the engine's torque, 2:1 at stall falling to 1 at the
  coupling point. The gear ratios are scaled by that torque ratio, so
  Jolt's clutch books the converter's loss and no energy is made;
- the automatic shifts on its input's speed, not the engine speed a
  slipping converter lifts.

The driver model gains an integral trim on its acceleration error. The
trim restarts when the command turns from speeding up to slowing down,
and holds while its pedal is saturated. It is saved with the driver's
other memory.

The M1097A2 at GVW now reaches 30 mph in 8.9 s and 50 mph in 23.6 s,
inside the Army's 9.4 / 26.1 s. A hill start on 15% reaches 5.6 m/s
in 6 s. The closed cycle's residual + drivetrain split is 0.69% at 8
collision steps, and the cruise drivetrain share is 20%. The vehicle,
energy and world suites all pass.
…tree

- vehicles.<name>.tuning.engine_friction_curve: the friction curve as
  "rpm:N m" points ("700:78, 2040:87, 3400:128", or "none"). It is
  seeded with the vehicle's curve, and applied when it changes. The
  scalar powertrain knobs (clutch_strength, converter_k,
  converter_stall, converter_coupling, driveline_efficiency, the
  light-throttle shift points) were already knobs, and are now tested.
- vehicles.<name>.accel_trim, from vehicle_state::accel_trim (the driver
  model's integral trim), and in the snapshot's JSON.
- An invalid tuning value in the tree is ignored on its own. Before
  this, one bad knob kept every later change to that vehicle from
  applying, because all of them went to set_vehicle together.
…nge)

Every key world_binding owns now describes itself, for other
applications (a UI, a validator, a remote peer). Each has a comment and
cvc::state properties:
- access: build, knob, command or telemetry;
- unit on a number: SI, "1" for a ratio;
- a recommended min and max on a knob or a command.

The keys covered:
- the world's build settings, solver knobs and publication rates, and
  its telemetry;
- the materials;
- bodies;
- vehicles: telemetry, wheels, the energy ledger, commands, pedals, and
  the tuning of the vehicle and its axles;
- fields.

The ranges are recommendations, not limits: the world still validates
on its own. Some examples:
- collision_steps 1-32, with 8 noted as the Humvee's energy-accurate
  step;
- converter_k 0-300 rpm/sqrt(N m);
- friction 0-2;
- max_steer_rate 0.05-10 rad/s.

The table is src/cvc/physics/binding_meta.cpp. A test walks every key
published under physics.* and requires each to have a comment and an
access.
On macOS, P3 failed 1082 of 4208 tests: boost::bad_any_cast escaping
the first cvc::state::instance(), whose catch (std::exception &) no
longer matched. Linux and Windows passed, and master passes macOS on the
same image and dependencies. A recipe run of the energy ledger's commit
alone already failed the same way.

It is the failure jolt_material.h records: a -fno-rtti file that
instantiates anything that can throw a std exception emits weak copies
of its typeinfo, and on macOS those bind every reference in
libcvc.dylib. The energy ledger put about 700 lines into
jolt_vehicle_controller.cpp, the controller's -fno-rtti file: Jolt's
PostCollide and friction solve with its measurements, over
PhysicsSystem.h and Body.h.

jolt_vehicle_controller.cpp now holds only what must own a vtable over
a Jolt base: the constructors, the destructors (the key functions) and
ConstructController, as on master. Every other member is in the new
jolt_vehicle_energy.cpp, built with RTTI and the same floating-point
flags. Nothing there needs a Jolt type's typeinfo, and the vtable stays
in the no-RTTI file.

The move changes no arithmetic. On Windows, physics_energy_test (11),
physics_vehicle_test (24), physics_world_test (40), nav_plant_test (13)
and the parity reference (3) pass, with the parity state hashes
unchanged (ad4f3e75970506ac, fab1bf415fa513f7).
@transfix
transfix merged commit 54a3a41 into master Oct 18, 2026
15 checks passed
@transfix
transfix deleted the feat/energy-ledger branch October 18, 2026 16:02
transfix added a commit that referenced this pull request Oct 18, 2026
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