Skip to content

Commit 2257094

Browse files
piadeebshihadeh
authored andcommitted
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.
1 parent 1bacd87 commit 2257094

5 files changed

Lines changed: 10 additions & 13 deletions

File tree

opendbc/car/car.capnp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,13 @@ struct CarParams {
484484
autoResumeSng @69 :Bool; # describes whether car can resume from a stop automatically
485485

486486
# things about the car in the manual
487-
mass @17 :Float32; # [kg] curb weight: all fluids no cargo
488487
wheelbase @18 :Float32; # [m] distance from rear axle to front axle
489488
centerToFront @19 :Float32; # [m] distance from center of mass to front axle
490489
steerRatio @20 :Float32; # [] ratio of steering wheel angle to front wheel angle
491490
steerRatioRear @21 :Float32; # [] ratio of steering wheel angle to rear wheel angle (usually 0)
492491

493-
# things we can derive
492+
# vehicle dynamics parameters
493+
unitMass @17 :Float32; # [kg] arbitrary mass; cancels out of the vehicle dynamics
494494
rotationalInertia @22 :Float32; # [kg*m2] body rotational inertia
495495
tireStiffnessFactor @72 :Float32; # scaling factor used in calculating tireStiffness[Front,Rear]
496496
tireStiffnessFront @23 :Float32; # [N/rad] front tire coeff of stiff

opendbc/car/interfaces.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from collections.abc import Callable
99
from functools import cache
1010

11-
from opendbc.car import DT_CTRL, apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness, STD_CARGO_KG
11+
from opendbc.car import DT_CTRL, apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness
1212
from opendbc.car import structs
1313
from opendbc.car.can_definitions import CanData, CanRecvCallable, CanSendCallable
1414
from opendbc.car.common.basedir import BASEDIR
@@ -133,7 +133,8 @@ def get_params(cls, candidate: str, fingerprint: dict[int, dict[int, int]], car_
133133
ret = CarInterfaceBase.get_std_params(candidate)
134134

135135
platform = PLATFORMS[candidate]
136-
ret.mass = platform.config.specs.mass
136+
# Arbitrary mass; it cancels out of the vehicle dynamics but keeps the formulation readable.
137+
ret.unitMass = 1.0
137138
ret.wheelbase = platform.config.specs.wheelbase
138139
ret.steerRatio = platform.config.specs.steerRatio
139140
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_
144145

145146
ret = cls._get_params(ret, candidate, fingerprint, car_fw, alpha_long, is_release, docs)
146147

147-
# Vehicle mass is published curb weight plus assumed payload such as a human driver; notCars have no assumed payload
148-
if not ret.notCar:
149-
ret.mass = ret.mass + STD_CARGO_KG
150-
151148
# Set params dependent on values set by the car interface
152-
ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)
153-
ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, ret.tireStiffnessFactor)
149+
ret.rotationalInertia = scale_rot_inertia(ret.unitMass, ret.wheelbase)
150+
ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.unitMass, ret.wheelbase, ret.centerToFront, ret.tireStiffnessFactor)
154151

155152
return ret
156153

opendbc/car/tests/test_car_interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test(self, fuzzy):
4141
car_interface = get_fuzzy_car_interface(car_name, fuzzy)
4242
car_params = car_interface.CP.as_reader()
4343

44-
assert car_params.mass > 1
44+
assert car_params.unitMass == 1
4545
assert car_params.wheelbase > 0
4646
# centerToFront is center of gravity to front wheels, assert a reasonable range
4747
assert car_params.wheelbase * 0.3 < car_params.centerToFront < car_params.wheelbase * 0.7

opendbc/car/tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_car_params(self):
193193
if self.CP.dashcamOnly:
194194
self.skipTest("no need to check carParams for dashcamOnly")
195195

196-
self.assertGreater(self.CP.mass, 1)
196+
self.assertEqual(self.CP.unitMass, 1)
197197
if self.CP.steerControlType not in (SteerControlType.angle, SteerControlType.curvature):
198198
tuning = self.CP.lateralTuning.which()
199199
if tuning == "pid":

opendbc/car/vehicle_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, CP: CarParams):
2727
CP: Car Parameters
2828
"""
2929
# for math readability, convert long names car params into short names
30-
self.m: float = CP.mass
30+
self.m: float = CP.unitMass
3131
self.j: float = CP.rotationalInertia
3232
self.l: float = CP.wheelbase
3333
self.aF: float = CP.centerToFront

0 commit comments

Comments
 (0)