Skip to content

Commit

Permalink
move getting platform to get_params (commaai#31871)
Browse files Browse the repository at this point in the history
* better

* string

* not here
  • Loading branch information
jnewb1 authored Mar 15, 2024
1 parent 1ecbbef commit ca5a2ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
5 changes: 1 addition & 4 deletions selfdrive/car/car_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from cereal import car
from openpilot.common.params import Params
from openpilot.common.basedir import BASEDIR
from openpilot.selfdrive.car.values import PLATFORMS
from openpilot.system.version import is_comma_remote, is_tested_branch
from openpilot.selfdrive.car.interfaces import get_interface_attr
from openpilot.selfdrive.car.fingerprints import eliminate_incompatible_cars, all_legacy_fingerprint_cars
Expand Down Expand Up @@ -192,9 +191,7 @@ def fingerprint(logcan, sendcan, num_pandas):
fw_count=len(car_fw), ecu_responses=list(ecu_rx_addrs), vin_rx_addr=vin_rx_addr, vin_rx_bus=vin_rx_bus,
fingerprints=repr(finger), fw_query_time=fw_query_time, error=True)

car_platform = PLATFORMS.get(car_fingerprint, MOCK.MOCK)

return car_platform, finger, vin, car_fw, source, exact_match
return car_fingerprint, finger, vin, car_fw, source, exact_match


def get_car_interface(CP):
Expand Down
25 changes: 14 additions & 11 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
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.values import Platform
from openpilot.selfdrive.car.mock.values import CAR as MOCK
from openpilot.selfdrive.car.values import PLATFORMS
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
Expand Down Expand Up @@ -102,24 +103,26 @@ def get_pid_accel_limits(CP, current_speed, cruise_speed):
return ACCEL_MIN, ACCEL_MAX

@classmethod
def get_non_essential_params(cls, candidate: Platform):
def get_non_essential_params(cls, candidate: str):
"""
Parameters essential to controlling the car may be incomplete or wrong without FW versions or fingerprints.
"""
return cls.get_params(candidate, gen_empty_fingerprint(), list(), False, False)

@classmethod
def get_params(cls, candidate: Platform, fingerprint: dict[int, dict[int, int]], car_fw: list[car.CarParams.CarFw], experimental_long: bool, docs: bool):
def get_params(cls, candidate: str, fingerprint: dict[int, dict[int, int]], car_fw: list[car.CarParams.CarFw], experimental_long: bool, docs: bool):
platform = PLATFORMS.get(candidate, MOCK.MOCK)

ret = CarInterfaceBase.get_std_params(candidate)

ret.mass = candidate.config.specs.mass
ret.wheelbase = candidate.config.specs.wheelbase
ret.steerRatio = candidate.config.specs.steerRatio
ret.centerToFront = ret.wheelbase * candidate.config.specs.centerToFrontRatio
ret.minEnableSpeed = candidate.config.specs.minEnableSpeed
ret.minSteerSpeed = candidate.config.specs.minSteerSpeed
ret.tireStiffnessFactor = candidate.config.specs.tireStiffnessFactor
ret.flags |= int(candidate.config.flags)
ret.mass = platform.config.specs.mass
ret.wheelbase = platform.config.specs.wheelbase
ret.steerRatio = platform.config.specs.steerRatio
ret.centerToFront = ret.wheelbase * platform.config.specs.centerToFrontRatio
ret.minEnableSpeed = platform.config.specs.minEnableSpeed
ret.minSteerSpeed = platform.config.specs.minSteerSpeed
ret.tireStiffnessFactor = platform.config.specs.tireStiffnessFactor
ret.flags |= int(platform.config.flags)

ret = cls._get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs)

Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from openpilot.selfdrive.car.car_helpers import FRAME_FINGERPRINT, interfaces
from openpilot.selfdrive.car.honda.values import CAR as HONDA, HondaFlags
from openpilot.selfdrive.car.tests.routes import non_tested_cars, routes, CarTestRoute
from openpilot.selfdrive.car.values import PLATFORMS, Platform
from openpilot.selfdrive.car.values import Platform
from openpilot.selfdrive.controls.controlsd import Controls
from openpilot.selfdrive.test.helpers import read_segment_list
from openpilot.system.hardware.hw import DEFAULT_DOWNLOAD_CACHE_ROOT
Expand Down Expand Up @@ -95,7 +95,7 @@ def get_testing_data_from_logreader(cls, lr):
if msg.carParams.openpilotLongitudinalControl:
experimental_long = True
if cls.platform is None and not cls.ci:
cls.platform = PLATFORMS.get(msg.carParams.carFingerprint)
cls.platform = msg.carParams.carFingerprint

# Log which can frame the panda safety mode left ELM327, for CAN validity checks
elif msg.which() == 'pandaStates':
Expand Down
5 changes: 1 addition & 4 deletions tools/car_porting/test_car_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from openpilot.selfdrive.car.tests.routes import CarTestRoute
from openpilot.selfdrive.car.tests.test_models import TestCarModel
from openpilot.selfdrive.car.values import PLATFORMS
from openpilot.tools.lib.route import SegmentName


Expand Down Expand Up @@ -33,9 +32,7 @@ def create_test_models_suite(routes: list[CarTestRoute], ci=False) -> unittest.T
route_or_segment_name = SegmentName(args.route_or_segment_name.strip(), allow_route_name=True)
segment_num = route_or_segment_name.segment_num if route_or_segment_name.segment_num != -1 else None

platform = PLATFORMS.get(args.car)

test_route = CarTestRoute(route_or_segment_name.route_name.canonical_name, platform, segment=segment_num)
test_route = CarTestRoute(route_or_segment_name.route_name.canonical_name, args.car, segment=segment_num)
test_suite = create_test_models_suite([test_route], ci=args.ci)

unittest.TextTestRunner().run(test_suite)

0 comments on commit ca5a2ed

Please sign in to comment.