Repository navigation
physics: the energy ledger (P3): every vehicle's energy, term by term, with its source - #690
Merged
Merged
Conversation
…, 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).
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.
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:The vehicle is the chassis, its wheels and its drivetrain, engine included (D8):
suppliedis the engine torque's work, andidleis what Jolt's idle-speed clamp adds. So coasting with no input supplies exactly nothing.storedcovers 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::PostCollideand 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.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 source (
vehicle_desc::energy):Where it is published:
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)Also tested:
vehicle_state.The presets against the field
Every value in
vehicle.cppnames its source:vesc.lua;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_stallandconverter_coupling, a torque converter (see below);driveline_efficiency;shift_{up,down}_rpm_light, a throttle-dependent shift schedule, on the gearbox input's speed.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:
The range test pins the present calibration until then.
The two preset findings are resolved:
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_kmakes the clutch a torque converter's. It carries at most (rpm / K)², about 53 N·m at idle for the 4L80-E.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
vehicles.<name>.tuning.*, seeded and applied as the others are:clutch_strength,converter_k,converter_stall,converter_coupling,driveline_efficiency,shift_up_rpm_lightandshift_down_rpm_light.tuning.engine_friction_curve, a string ofrpm:N mpoints ("700:78, 2040:87, 3400:128", or"none").vehicles.<name>.accel_trim.desc).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::stateproperties:access:build,knob,commandortelemetry;uniton a number: SI,1for a ratio;minandmaxon 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_testwalks every key published underphysics.*(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_Jandenergy_per_kmcome 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.ImageTest.ReadsCmykInputAsRgb,CvcCliTest.Vol2Img*/Img2Vol*), unrelated.Docs:
docs/PHYSICS_API.md(the powertrain, the presets and their sources, the energy ledger) andNAV-VEHICLE-PHYSICS-ROADMAP.md(P3 done).