Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions opendbc/car/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions opendbc/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/tests/test_car_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/vehicle_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading