From f96d08f11c4b07a78da217ba86c694cfcf89a3d2 Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Fri, 23 Feb 2024 09:32:17 -0800 Subject: [PATCH] all brands can be done like this --- selfdrive/car/interfaces.py | 12 ++++++++++-- selfdrive/car/subaru/interface.py | 6 ------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 9767752edb..22d42549e9 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -4,7 +4,7 @@ import numpy as np import tomllib from abc import abstractmethod, ABC from enum import StrEnum -from typing import Any, Dict, Optional, Tuple, List, Callable, NamedTuple +from typing import Any, Dict, Optional, Tuple, List, Callable, NamedTuple, cast from cereal import car from openpilot.common.basedir import BASEDIR @@ -12,7 +12,7 @@ from openpilot.common.conversions import Conversions as CV from openpilot.common.simple_kalman import KF1D, get_kalman_gain from openpilot.common.numpy_fast import clip from openpilot.common.realtime import DT_CTRL -from openpilot.selfdrive.car import apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness, STD_CARGO_KG +from openpilot.selfdrive.car import PlatformConfig, apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness, STD_CARGO_KG from openpilot.selfdrive.controls.lib.drive_helpers import V_CRUISE_MAX, get_friction from openpilot.selfdrive.controls.lib.events import Events from openpilot.selfdrive.controls.lib.vehicle_model import VehicleModel @@ -111,6 +111,14 @@ class CarInterfaceBase(ABC): ret = CarInterfaceBase.get_std_params(candidate) ret = cls._get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs) + if hasattr(candidate, "config"): + platform_config = cast(PlatformConfig, candidate.config) + if platform_config.specs is not None: + ret.mass = platform_config.specs.mass + ret.wheelbase = platform_config.specs.wheelbase + ret.steerRatio = platform_config.specs.steerRatio + ret.centerToFront = ret.wheelbase * 0.5 + # 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 diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index 581613acb6..d13c90e7e6 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -40,12 +40,6 @@ class CarInterface(CarInterfaceBase): else: CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning) - platform_config = CAR(candidate).config - ret.mass = platform_config.specs.mass - ret.wheelbase = platform_config.specs.wheelbase - ret.steerRatio = platform_config.specs.steerRatio - ret.centerToFront = ret.wheelbase * 0.5 - if candidate in (CAR.ASCENT, CAR.ASCENT_2023): ret.steerActuatorDelay = 0.3 # end-to-end angle controller ret.lateralTuning.init('pid')