From d8d3d3c3e0d35e73eacf534a4f35a0bd299dcb07 Mon Sep 17 00:00:00 2001 From: pi Date: Sat, 8 Aug 2026 16:28:26 -0700 Subject: [PATCH] remove carParams.mass from the bicycle model mass cancels out of the bicycle model since tire stiffness and rotational inertia both scale with it. store stiffness/inertia per unit mass (divided by the reference Civic mass) so mass disappears from the vehicle model entirely instead of substituting a fake mass constant. carParams.mass is still set, just no longer consumed. --- opendbc/car/car.capnp | 4 ++-- opendbc/car/interfaces.py | 13 +++++-------- opendbc/car/tests/test_car_interfaces.py | 2 +- opendbc/car/tests/test_models.py | 2 +- opendbc/car/vehicle_model.py | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/opendbc/car/car.capnp b/opendbc/car/car.capnp index 2dc1304fff8..1b527f7c17e 100644 --- a/opendbc/car/car.capnp +++ b/opendbc/car/car.capnp @@ -484,13 +484,13 @@ struct CarParams { autoResumeSng @69 :Bool; # describes whether car can resume from a stop automatically # things about the car in the manual - mass @17 :Float32; # [kg] curb weight: all fluids no cargo wheelbase @18 :Float32; # [m] distance from rear axle to front axle centerToFront @19 :Float32; # [m] distance from center of mass to front axle steerRatio @20 :Float32; # [] ratio of steering wheel angle to front wheel angle steerRatioRear @21 :Float32; # [] ratio of steering wheel angle to rear wheel angle (usually 0) - # things we can derive + # vehicle dynamics parameters + unitMass @17 :Float32; # [kg] arbitrary mass; cancels out of the vehicle dynamics rotationalInertia @22 :Float32; # [kg*m2] body rotational inertia tireStiffnessFactor @72 :Float32; # scaling factor used in calculating tireStiffness[Front,Rear] tireStiffnessFront @23 :Float32; # [N/rad] front tire coeff of stiff diff --git a/opendbc/car/interfaces.py b/opendbc/car/interfaces.py index 5da6e9ecc32..8d978facd0a 100644 --- a/opendbc/car/interfaces.py +++ b/opendbc/car/interfaces.py @@ -8,7 +8,7 @@ from collections.abc import Callable from functools import cache -from opendbc.car import DT_CTRL, apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness, STD_CARGO_KG +from opendbc.car import DT_CTRL, apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness from opendbc.car import structs from opendbc.car.can_definitions import CanData, CanRecvCallable, CanSendCallable from opendbc.car.common.basedir import BASEDIR @@ -133,7 +133,8 @@ def get_params(cls, candidate: str, fingerprint: dict[int, dict[int, int]], car_ ret = CarInterfaceBase.get_std_params(candidate) platform = PLATFORMS[candidate] - ret.mass = platform.config.specs.mass + # Arbitrary mass; it cancels out of the vehicle dynamics but keeps the formulation readable. + ret.unitMass = 1.0 ret.wheelbase = platform.config.specs.wheelbase ret.steerRatio = platform.config.specs.steerRatio ret.centerToFront = ret.wheelbase * platform.config.specs.centerToFrontRatio @@ -144,13 +145,9 @@ def get_params(cls, candidate: str, fingerprint: dict[int, dict[int, int]], car_ ret = cls._get_params(ret, candidate, fingerprint, car_fw, alpha_long, is_release, docs) - # Vehicle mass is published curb weight plus assumed payload such as a human driver; notCars have no assumed payload - if not ret.notCar: - ret.mass = ret.mass + STD_CARGO_KG - # Set params dependent on values set by the car interface - ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase) - ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, ret.tireStiffnessFactor) + ret.rotationalInertia = scale_rot_inertia(ret.unitMass, ret.wheelbase) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.unitMass, ret.wheelbase, ret.centerToFront, ret.tireStiffnessFactor) return ret diff --git a/opendbc/car/tests/test_car_interfaces.py b/opendbc/car/tests/test_car_interfaces.py index 1c2c778f9de..f7191a82b22 100644 --- a/opendbc/car/tests/test_car_interfaces.py +++ b/opendbc/car/tests/test_car_interfaces.py @@ -41,7 +41,7 @@ def test(self, fuzzy): car_interface = get_fuzzy_car_interface(car_name, fuzzy) car_params = car_interface.CP.as_reader() - assert car_params.mass > 1 + assert car_params.unitMass == 1 assert car_params.wheelbase > 0 # centerToFront is center of gravity to front wheels, assert a reasonable range assert car_params.wheelbase * 0.3 < car_params.centerToFront < car_params.wheelbase * 0.7 diff --git a/opendbc/car/tests/test_models.py b/opendbc/car/tests/test_models.py index 5a911e96746..e32a1445c93 100755 --- a/opendbc/car/tests/test_models.py +++ b/opendbc/car/tests/test_models.py @@ -193,7 +193,7 @@ def test_car_params(self): if self.CP.dashcamOnly: self.skipTest("no need to check carParams for dashcamOnly") - self.assertGreater(self.CP.mass, 1) + self.assertEqual(self.CP.unitMass, 1) if self.CP.steerControlType not in (SteerControlType.angle, SteerControlType.curvature): tuning = self.CP.lateralTuning.which() if tuning == "pid": diff --git a/opendbc/car/vehicle_model.py b/opendbc/car/vehicle_model.py index fa20a6e7d52..0ddbee287ef 100755 --- a/opendbc/car/vehicle_model.py +++ b/opendbc/car/vehicle_model.py @@ -27,7 +27,7 @@ def __init__(self, CP: CarParams): CP: Car Parameters """ # for math readability, convert long names car params into short names - self.m: float = CP.mass + self.m: float = CP.unitMass self.j: float = CP.rotationalInertia self.l: float = CP.wheelbase self.aF: float = CP.centerToFront