diff --git a/opendbc_repo b/opendbc_repo index 79c69ec9f2f86bf..d7862bc2f650c2c 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit 79c69ec9f2f86bf3a0b5f2245f6682bfd4a152c8 +Subproject commit d7862bc2f650c2cb7e8cdd001bad81af0ef551a0 diff --git a/selfdrive/car/car_specific.py b/selfdrive/car/car_specific.py index 3984b66c63df46c..2305e1104be6060 100644 --- a/selfdrive/car/car_specific.py +++ b/selfdrive/car/car_specific.py @@ -1,16 +1,16 @@ from cereal import car import cereal.messaging as messaging -from opendbc.car import DT_CTRL, structs +from opendbc.car import DT_CTRL from opendbc.car.interfaces import MAX_CTRL_SPEED, CarStateBase, CarControllerBase from opendbc.car.volkswagen.values import CarControllerParams as VWCarControllerParams from opendbc.car.hyundai.interface import ENABLE_BUTTONS as HYUNDAI_ENABLE_BUTTONS from openpilot.selfdrive.selfdrived.events import Events -ButtonType = structs.CarState.ButtonEvent.Type -GearShifter = structs.CarState.GearShifter +ButtonType = car.CarState.ButtonEvent.Type +GearShifter = car.CarState.GearShifter EventName = car.OnroadEvent.EventName -NetworkLocation = structs.CarParams.NetworkLocation +NetworkLocation = car.CarParams.NetworkLocation # TODO: the goal is to abstract this file into the CarState struct and make events generic @@ -29,7 +29,7 @@ def update(self, CS: car.CarState): class CarSpecificEvents: - def __init__(self, CP: structs.CarParams): + def __init__(self, CP: car.CarParams): self.CP = CP self.steering_unpressed = 0 @@ -172,7 +172,7 @@ def update(self, CS: CarStateBase, CS_prev: car.CarState, CC: CarControllerBase, return events - def create_common_events(self, CS: structs.CarState, CS_prev: car.CarState, extra_gears=None, pcm_enable=True, + def create_common_events(self, CS: car.CarState, CS_prev: car.CarState, extra_gears=None, pcm_enable=True, allow_enable=True, enable_buttons=(ButtonType.accelCruise, ButtonType.decelCruise)): events = Events() diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 62569f64f5318dd..dc9f3c6d7119871 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -13,7 +13,7 @@ from openpilot.common.realtime import config_realtime_process, Priority, Ratekeeper from openpilot.common.swaglog import cloudlog, ForwardingHandler -from opendbc.car import DT_CTRL, carlog, structs +from opendbc.car import DT_CTRL, carlog from opendbc.car.can_definitions import CanData, CanRecvCallable, CanSendCallable from opendbc.car.fw_versions import ObdCallback from opendbc.car.car_helpers import get_car, get_radar_interface @@ -21,7 +21,6 @@ from openpilot.selfdrive.pandad import can_capnp_to_list, can_list_to_can_capnp from openpilot.selfdrive.car.cruise import VCruiseHelper from openpilot.selfdrive.car.car_specific import CarSpecificEvents, MockCarState -from openpilot.selfdrive.car.helpers import convert_carControl, convert_to_capnp from openpilot.selfdrive.selfdrived.events import Events, ET REPLAY = "REPLAY" in os.environ @@ -64,7 +63,7 @@ def can_send(msgs: list[CanData]) -> None: class Car: CI: CarInterfaceBase RI: RadarInterfaceBase - CP: structs.CarParams + CP: car.CarParams CP_capnp: car.CarParams def __init__(self, CI=None, RI=None) -> None: @@ -78,7 +77,7 @@ def __init__(self, CI=None, RI=None) -> None: self.CS_prev = car.CarState.new_message() self.initialized_prev = False - self.last_actuators_output = structs.CarControl.Actuators() + self.last_actuators_output = car.CarControl.Actuators.new_message() self.params = Params() @@ -99,7 +98,7 @@ def __init__(self, CI=None, RI=None) -> None: cached_params_raw = self.params.get("CarParamsCache") if cached_params_raw is not None: with car.CarParams.from_bytes(cached_params_raw) as _cached_params: - cached_params = structs.CarParams(carName=_cached_params.carName, carFw=_cached_params.carFw, carVin=_cached_params.carVin) + cached_params = car.CarParams(carName=_cached_params.carName, carFw=_cached_params.carFw, carVin=_cached_params.carVin) self.CI = get_car(*self.can_callbacks, obd_callback(self.params), experimental_long_allowed, num_pandas, cached_params) self.RI = get_radar_interface(self.CI.CP) @@ -123,8 +122,8 @@ def __init__(self, CI=None, RI=None) -> None: self.CP.passive = not controller_available or self.CP.dashcamOnly if self.CP.passive: - safety_config = structs.CarParams.SafetyConfig() - safety_config.safetyModel = structs.CarParams.SafetyModel.noOutput + safety_config = car.CarParams.SafetyConfig.new_message() + safety_config.safetyModel = car.CarParams.SafetyModel.noOutput self.CP.safetyConfigs = [safety_config] # Write previous route's CarParams @@ -134,7 +133,7 @@ def __init__(self, CI=None, RI=None) -> None: # Write CarParams for controls and radard # convert to pycapnp representation for caching and logging - self.CP_capnp = convert_to_capnp(self.CP) + self.CP_capnp = self.CP cp_bytes = self.CP_capnp.to_bytes() self.params.put("CarParams", cp_bytes) self.params.put_nonblocking("CarParamsCache", cp_bytes) @@ -152,19 +151,19 @@ def __init__(self, CI=None, RI=None) -> None: # card is driven by can recv, expected at 100Hz self.rk = Ratekeeper(100, print_delay_threshold=None) - def state_update(self) -> tuple[car.CarState, structs.RadarData | None]: + def state_update(self) -> tuple[car.CarState, car.RadarData]: """carState update loop, driven by can""" can_strs = messaging.drain_sock_raw(self.can_sock, wait_for_one=True) can_list = can_capnp_to_list(can_strs) # Update carState from CAN - CS = convert_to_capnp(self.CI.update(can_list)) + CS = self.CI.update(can_list) if self.CP.carName == 'mock': CS = self.mock_carstate.update(CS) # Update radar tracks from CAN - RD: structs.RadarData | None = self.RI.update(can_list) + RD: car.RadarData = self.RI.update(can_list) self.sm.update(0) @@ -184,7 +183,7 @@ def state_update(self) -> tuple[car.CarState, structs.RadarData | None]: return CS, RD - def update_events(self, CS: car.CarState, RD: structs.RadarData | None): + def update_events(self, CS: car.CarState, RD: car.RadarData): self.events.clear() CS.events = self.car_events.update(self.CI.CS, self.CS_prev, self.CI.CC, self.CC_prev).to_msg() @@ -208,7 +207,7 @@ def update_events(self, CS: car.CarState, RD: structs.RadarData | None): CS.events = self.events.to_msg() - def state_publish(self, CS: car.CarState, RD: structs.RadarData | None): + def state_publish(self, CS: car.CarState, RD: car.RadarData): """carState and carParams publish loop""" # carParams - logged every 50 seconds (> 1 per segment) @@ -221,7 +220,7 @@ def state_publish(self, CS: car.CarState, RD: structs.RadarData | None): # publish new carOutput co_send = messaging.new_message('carOutput') co_send.valid = self.sm.all_checks(['carControl']) - co_send.carOutput.actuatorsOutput = convert_to_capnp(self.last_actuators_output) + co_send.carOutput.actuatorsOutput = self.last_actuators_output self.pm.send('carOutput', co_send) # kick off controlsd step while we actuate the latest carControl packet @@ -235,7 +234,7 @@ def state_publish(self, CS: car.CarState, RD: structs.RadarData | None): if RD is not None: tracks_msg = messaging.new_message('liveTracks') tracks_msg.valid = len(RD.errors) == 0 - tracks_msg.liveTracks = convert_to_capnp(RD) + tracks_msg.liveTracks = RD self.pm.send('liveTracks', tracks_msg) def controls_update(self, CS: car.CarState, CC: car.CarControl): @@ -251,7 +250,7 @@ def controls_update(self, CS: car.CarState, CC: car.CarControl): if self.sm.all_alive(['carControl']): # send car controls over can now_nanos = self.can_log_mono_time if REPLAY else int(time.monotonic() * 1e9) - self.last_actuators_output, can_sends = self.CI.apply(convert_carControl(CC), now_nanos) + self.last_actuators_output, can_sends = self.CI.apply(CC, now_nanos) self.pm.send('sendcan', can_list_to_can_capnp(can_sends, msgtype='sendcan', valid=CS.canValid)) self.CC_prev = CC diff --git a/selfdrive/car/helpers.py b/selfdrive/car/helpers.py deleted file mode 100644 index 75e1c66d24254a4..000000000000000 --- a/selfdrive/car/helpers.py +++ /dev/null @@ -1,74 +0,0 @@ -import capnp -from typing import Any - -from cereal import car -from opendbc.car import structs - -_FIELDS = '__dataclass_fields__' # copy of dataclasses._FIELDS - - -def is_dataclass(obj): - """Similar to dataclasses.is_dataclass without instance type check checking""" - return hasattr(obj, _FIELDS) - - -def _asdictref_inner(obj) -> dict[str, Any] | Any: - if is_dataclass(obj): - ret = {} - for field in getattr(obj, _FIELDS): # similar to dataclasses.fields() - ret[field] = _asdictref_inner(getattr(obj, field)) - return ret - elif isinstance(obj, (tuple, list)): - return type(obj)(_asdictref_inner(v) for v in obj) - else: - return obj - - -def asdictref(obj) -> dict[str, Any]: - """ - Similar to dataclasses.asdict without recursive type checking and copy.deepcopy - Note that the resulting dict will contain references to the original struct as a result - """ - if not is_dataclass(obj): - raise TypeError("asdictref() should be called on dataclass instances") - - return _asdictref_inner(obj) - - -def convert_to_capnp(struct: structs.CarParams | structs.CarState | structs.CarControl.Actuators | structs.RadarData) -> capnp.lib.capnp._DynamicStructBuilder: - struct_dict = asdictref(struct) - - if isinstance(struct, structs.CarParams): - del struct_dict['lateralTuning'] - struct_capnp = car.CarParams.new_message(**struct_dict) - - # this is the only union, special handling - which = struct.lateralTuning.which() - struct_capnp.lateralTuning.init(which) - lateralTuning_dict = asdictref(getattr(struct.lateralTuning, which)) - setattr(struct_capnp.lateralTuning, which, lateralTuning_dict) - elif isinstance(struct, structs.CarState): - struct_capnp = car.CarState.new_message(**struct_dict) - elif isinstance(struct, structs.CarControl.Actuators): - struct_capnp = car.CarControl.Actuators.new_message(**struct_dict) - elif isinstance(struct, structs.RadarData): - struct_capnp = car.RadarData.new_message(**struct_dict) - else: - raise ValueError(f"Unsupported struct type: {type(struct)}") - - return struct_capnp - - -def convert_carControl(struct: capnp.lib.capnp._DynamicStructReader) -> structs.CarControl: - # TODO: recursively handle any car struct as needed - def remove_deprecated(s: dict) -> dict: - return {k: v for k, v in s.items() if not k.endswith('DEPRECATED')} - - struct_dict = struct.to_dict() - struct_dataclass = structs.CarControl(**remove_deprecated({k: v for k, v in struct_dict.items() if not isinstance(k, dict)})) - - struct_dataclass.actuators = structs.CarControl.Actuators(**remove_deprecated(struct_dict.get('actuators', {}))) - struct_dataclass.cruiseControl = structs.CarControl.CruiseControl(**remove_deprecated(struct_dict.get('cruiseControl', {}))) - struct_dataclass.hudControl = structs.CarControl.HUDControl(**remove_deprecated(struct_dict.get('hudControl', {}))) - - return struct_dataclass diff --git a/selfdrive/car/tests/test_car_interfaces.py b/selfdrive/car/tests/test_car_interfaces.py index 66cf0dc69685310..11a802ea4661f66 100644 --- a/selfdrive/car/tests/test_car_interfaces.py +++ b/selfdrive/car/tests/test_car_interfaces.py @@ -5,14 +5,12 @@ from parameterized import parameterized from cereal import car -from opendbc.car import DT_CTRL +from opendbc.car import DT_CTRL, CarParams from opendbc.car.car_helpers import interfaces -from opendbc.car.structs import CarParams from opendbc.car.tests.test_car_interfaces import get_fuzzy_car_interface_args from opendbc.car.fingerprints import all_known_cars from opendbc.car.fw_versions import FW_VERSIONS, FW_QUERY_CONFIGS from opendbc.car.mock.values import CAR as MOCK -from openpilot.selfdrive.car.card import convert_carControl, convert_to_capnp from openpilot.selfdrive.controls.lib.latcontrol_angle import LatControlAngle from openpilot.selfdrive.controls.lib.latcontrol_pid import LatControlPID from openpilot.selfdrive.controls.lib.latcontrol_torque import LatControlTorque @@ -72,7 +70,6 @@ def test_car_interfaces(self, car_name, data): # Run car interface now_nanos = 0 CC = car.CarControl.new_message(**cc_msg) - CC = convert_carControl(CC.as_reader()) for _ in range(10): car_interface.update([]) car_interface.apply(CC, now_nanos) @@ -80,7 +77,6 @@ def test_car_interfaces(self, car_name, data): CC = car.CarControl.new_message(**cc_msg) CC.enabled = True - CC = convert_carControl(CC.as_reader()) for _ in range(10): car_interface.update([]) car_interface.apply(CC, now_nanos) @@ -89,7 +85,7 @@ def test_car_interfaces(self, car_name, data): # Test controller initialization # TODO: wait until card refactor is merged to run controller a few times, # hypothesis also slows down significantly with just one more message draw - car_params_capnp = convert_to_capnp(car_params).as_reader() + car_params_capnp = car_params.as_reader() LongControl(car_params_capnp) if car_params.steerControlType == CarParams.SteerControlType.angle: LatControlAngle(car_params_capnp, car_interface) diff --git a/selfdrive/car/tests/test_models.py b/selfdrive/car/tests/test_models.py index 460b9f196d0c3f3..2ef8e6462a42713 100644 --- a/selfdrive/car/tests/test_models.py +++ b/selfdrive/car/tests/test_models.py @@ -14,13 +14,13 @@ from cereal import messaging, log, car from openpilot.common.basedir import BASEDIR from openpilot.common.params import Params -from opendbc.car import DT_CTRL, gen_empty_fingerprint, structs +from opendbc.car import DT_CTRL, gen_empty_fingerprint from opendbc.car.fingerprints import all_known_cars, MIGRATION from opendbc.car.car_helpers import FRAME_FINGERPRINT, interfaces from opendbc.car.honda.values import CAR as HONDA, HondaFlags from opendbc.car.values import Platform from opendbc.car.tests.routes import non_tested_cars, routes, CarTestRoute -from openpilot.selfdrive.car.card import Car, convert_to_capnp +from openpilot.selfdrive.car.card import Car from openpilot.selfdrive.pandad import can_capnp_to_list from openpilot.selfdrive.test.helpers import read_segment_list from openpilot.system.hardware.hw import DEFAULT_DOWNLOAD_CACHE_ROOT @@ -185,7 +185,7 @@ def tearDownClass(cls): del cls.can_msgs def setUp(self): - self.CI = self.CarInterface(copy.deepcopy(self.CP), self.CarController, self.CarState) + self.CI = self.CarInterface(self.CP.copy(), self.CarController, self.CarState) assert self.CI Params().put_bool("OpenpilotEnabledToggle", self.openpilot_enabled) @@ -193,7 +193,7 @@ def setUp(self): # TODO: check safetyModel is in release panda build self.safety = libpanda_py.libpanda - cfg = car.CarParams.SafetyConfig(**dataclasses.asdict(self.CP.safetyConfigs[-1])) + cfg = self.CP.safetyConfigs[-1] set_status = self.safety.set_safety_hooks(cfg.safetyModel.raw, cfg.safetyParam) self.assertEqual(0, set_status, f"failed to set safetyModel {cfg}") self.safety.init_tests() @@ -205,7 +205,7 @@ def test_car_params(self): # make sure car params are within a valid range self.assertGreater(self.CP.mass, 1) - if self.CP.steerControlType != structs.CarParams.SteerControlType.angle: + if self.CP.steerControlType != car.CarParams.SteerControlType.angle: tuning = self.CP.lateralTuning.which() if tuning == 'pid': self.assertTrue(len(self.CP.lateralTuning.pid.kpV)) @@ -218,7 +218,7 @@ def test_car_interface(self): # TODO: also check for checksum violations from can parser can_invalid_cnt = 0 can_valid = False - CC = structs.CarControl() + CC = car.CarControl.new_message() for i, msg in enumerate(self.can_msgs): CS = self.CI.update(can_capnp_to_list((msg.as_builder().to_bytes(),))) @@ -241,9 +241,9 @@ def test_radar_interface(self): # start parsing CAN messages after we've left ELM mode and can expect CAN traffic error_cnt = 0 for i, msg in enumerate(self.can_msgs[self.elm_frame:]): - rr: structs.RadarData | None = RI.update(can_capnp_to_list((msg.as_builder().to_bytes(),))) + rr: car.RadarData | None = RI.update(can_capnp_to_list((msg.as_builder().to_bytes(),))) if rr is not None and i > 50: - error_cnt += structs.RadarData.Error.canError in rr.errors + error_cnt += car.RadarData.Error.canError in rr.errors self.assertEqual(error_cnt, 0) def test_panda_safety_rx_checks(self): @@ -309,17 +309,17 @@ def test_car_controller(car_control): self.assertGreater(msgs_sent, 50) # Make sure we can send all messages while inactive - CC = structs.CarControl() + CC = car.CarControl.new_message() test_car_controller(CC) # Test cancel + general messages (controls_allowed=False & cruise_engaged=True) self.safety.set_cruise_engaged_prev(True) - CC = structs.CarControl(cruiseControl=structs.CarControl.CruiseControl(cancel=True)) + CC = car.CarControl.new_message(cruiseControl={'cancel': True}) test_car_controller(CC) # Test resume + general messages (controls_allowed=True & cruise_engaged=True) self.safety.set_controls_allowed(True) - CC = structs.CarControl(cruiseControl=structs.CarControl.CruiseControl(resume=True)) + CC = car.CarControl.new_message(cruiseControl={'resume': True}) test_car_controller(CC) # Skip stdout/stderr capture with pytest, causes elevated memory usage @@ -406,7 +406,7 @@ def test_panda_safety_carstate(self): checks = defaultdict(int) card = Car(CI=self.CI) for idx, can in enumerate(self.can_msgs): - CS = convert_to_capnp(self.CI.update(can_capnp_to_list((can.as_builder().to_bytes(), )))) + CS = self.CI.update(can_capnp_to_list((can.as_builder().to_bytes(), ))) for msg in filter(lambda m: m.src in range(64), can.can): to_send = libpanda_py.make_CANPacket(msg.address, msg.src % 4, msg.dat) ret = self.safety.safety_rx_hook(to_send) diff --git a/selfdrive/controls/lib/tests/test_latcontrol.py b/selfdrive/controls/lib/tests/test_latcontrol.py index c8c8d027515bb16..ba4bd0faeceb4a5 100644 --- a/selfdrive/controls/lib/tests/test_latcontrol.py +++ b/selfdrive/controls/lib/tests/test_latcontrol.py @@ -5,7 +5,6 @@ from opendbc.car.honda.values import CAR as HONDA from opendbc.car.toyota.values import CAR as TOYOTA from opendbc.car.nissan.values import CAR as NISSAN -from openpilot.selfdrive.car.card import convert_to_capnp from openpilot.selfdrive.controls.lib.latcontrol_pid import LatControlPID from openpilot.selfdrive.controls.lib.latcontrol_torque import LatControlTorque from openpilot.selfdrive.controls.lib.latcontrol_angle import LatControlAngle @@ -21,7 +20,6 @@ def test_saturation(self, car_name, controller): CarInterface, CarController, CarState, RadarInterface = interfaces[car_name] CP = CarInterface.get_non_essential_params(car_name) CI = CarInterface(CP, CarController, CarState) - CP = convert_to_capnp(CP) VM = VehicleModel(CP) controller = controller(CP.as_reader(), CI) diff --git a/selfdrive/controls/lib/tests/test_vehicle_model.py b/selfdrive/controls/lib/tests/test_vehicle_model.py index b58bdbe522a4416..d15519a8667d4ef 100644 --- a/selfdrive/controls/lib/tests/test_vehicle_model.py +++ b/selfdrive/controls/lib/tests/test_vehicle_model.py @@ -5,14 +5,13 @@ from opendbc.car.honda.interface import CarInterface from opendbc.car.honda.values import CAR -from openpilot.selfdrive.car.card import convert_to_capnp from openpilot.selfdrive.controls.lib.vehicle_model import VehicleModel, dyn_ss_sol, create_dyn_state_matrices class TestVehicleModel: def setup_method(self): CP = CarInterface.get_non_essential_params(CAR.HONDA_CIVIC) - self.VM = VehicleModel(convert_to_capnp(CP)) + self.VM = VehicleModel(CP) def test_round_trip_yaw_rate(self): # TODO: fix VM to work at zero speed diff --git a/selfdrive/debug/format_fingerprints.py b/selfdrive/debug/format_fingerprints.py index ae1ed06b75ae18c..ea252942aeec15d 100755 --- a/selfdrive/debug/format_fingerprints.py +++ b/selfdrive/debug/format_fingerprints.py @@ -14,7 +14,7 @@ # ruff: noqa: E501 {% endif %} {% if FW_VERSIONS[brand] %} -from opendbc.car.structs import CarParams +from opendbc.car import CarParams {% endif %} from opendbc.car.{{brand}}.values import CAR {% if FW_VERSIONS[brand] %} diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index 86813fcb8ecd664..9091d50b90c1653 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -17,7 +17,6 @@ from openpilot.common.transformations.camera import DEVICE_CAMERAS from openpilot.common.transformations.model import get_warp_matrix from openpilot.system import sentry -from openpilot.selfdrive.car.card import convert_to_capnp from openpilot.selfdrive.controls.lib.desire_helper import DesireHelper from openpilot.selfdrive.modeld.runners import ModelRunner, Runtime from openpilot.selfdrive.modeld.parse_model_outputs import Parser @@ -171,7 +170,7 @@ def main(demo=False): if demo: - CP = convert_to_capnp(get_demo_car_params()) + CP = get_demo_car_params() else: CP = messaging.log_from_bytes(params.get("CarParams", block=True), car.CarParams) diff --git a/selfdrive/modeld/tests/test_modeld.py b/selfdrive/modeld/tests/test_modeld.py index 1bf2977a9197035..a3c571d7194f54a 100644 --- a/selfdrive/modeld/tests/test_modeld.py +++ b/selfdrive/modeld/tests/test_modeld.py @@ -7,7 +7,6 @@ from openpilot.common.params import Params from openpilot.common.transformations.camera import DEVICE_CAMERAS from openpilot.common.realtime import DT_MDL -from openpilot.selfdrive.car.card import convert_to_capnp from openpilot.system.manager.process_config import managed_processes from openpilot.selfdrive.test.process_replay.vision_meta import meta_from_camera_state @@ -24,7 +23,7 @@ def setup_method(self): self.vipc_server.create_buffers(VisionStreamType.VISION_STREAM_DRIVER, 40, False, CAM.width, CAM.height) self.vipc_server.create_buffers(VisionStreamType.VISION_STREAM_WIDE_ROAD, 40, False, CAM.width, CAM.height) self.vipc_server.start_listener() - Params().put("CarParams", convert_to_capnp(get_demo_car_params()).to_bytes()) + Params().put("CarParams", get_demo_car_params()).to_bytes() self.sm = messaging.SubMaster(['modelV2', 'cameraOdometry']) self.pm = messaging.PubMaster(['roadCameraState', 'wideRoadCameraState', 'liveCalibration']) diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 59f6c6cc537f0c3..6ac165e36d49427 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -17,14 +17,13 @@ from cereal import car from cereal.services import SERVICE_LIST from msgq.visionipc import VisionIpcServer, get_endpoint_name as vipc_get_endpoint_name -from opendbc.car import structs from opendbc.car.car_helpers import get_car, interfaces from openpilot.common.params import Params from openpilot.common.prefix import OpenpilotPrefix from openpilot.common.timeout import Timeout from openpilot.common.realtime import DT_CTRL from panda.python import ALTERNATIVE_EXPERIENCE -from openpilot.selfdrive.car.card import can_comm_callbacks, convert_to_capnp +from openpilot.selfdrive.car.card import can_comm_callbacks from openpilot.system.manager.process_config import managed_processes from openpilot.selfdrive.test.process_replay.vision_meta import meta_from_camera_state, available_streams from openpilot.selfdrive.test.process_replay.migration import migrate_all @@ -363,14 +362,14 @@ def get_car_params_callback(rc, pm, msgs, fingerprint): cached_params = None if has_cached_cp: with car.CarParams.from_bytes(cached_params_raw) as _cached_params: - cached_params = structs.CarParams(carName=_cached_params.carName, carFw=_cached_params.carFw, carVin=_cached_params.carVin) + cached_params = car.CarParams(carName=_cached_params.carName, carFw=_cached_params.carFw, carVin=_cached_params.carVin) CP = get_car(*can_callbacks, lambda obd: None, Params().get_bool("ExperimentalLongitudinalEnabled"), cached_params=cached_params).CP if not params.get_bool("DisengageOnAccelerator"): CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS - params.put("CarParams", convert_to_capnp(CP).to_bytes()) + params.put("CarParams", CP).to_bytes() def selfdrived_rcv_callback(msg, cfg, frame): diff --git a/system/hardware/tici/tests/test_power_draw.py b/system/hardware/tici/tests/test_power_draw.py index eb3a515b76eeaa2..53ad69f7db03fa7 100644 --- a/system/hardware/tici/tests/test_power_draw.py +++ b/system/hardware/tici/tests/test_power_draw.py @@ -10,7 +10,6 @@ from opendbc.car.car_helpers import get_demo_car_params from openpilot.common.mock import mock_messages from openpilot.common.params import Params -from openpilot.selfdrive.car.card import convert_to_capnp from openpilot.system.hardware.tici.power_monitor import get_power from openpilot.system.manager.process_config import managed_processes from openpilot.system.manager.manager import manager_cleanup @@ -43,7 +42,7 @@ def name(self): class TestPowerDraw: def setup_method(self): - Params().put("CarParams", convert_to_capnp(get_demo_car_params()).to_bytes()) + Params().put("CarParams", get_demo_car_params()).to_bytes() # wait a bit for power save to disable time.sleep(5) diff --git a/tools/car_porting/examples/hkg_canfd_gear_message.ipynb b/tools/car_porting/examples/hkg_canfd_gear_message.ipynb index 5fdbdda6842ca52..4a81f86e9766ddb 100644 --- a/tools/car_porting/examples/hkg_canfd_gear_message.ipynb +++ b/tools/car_porting/examples/hkg_canfd_gear_message.ipynb @@ -21,7 +21,7 @@ } ], "source": [ - "from opendbc.car import structs\n", + "from opendbc.car import car\n", "from opendbc.car.hyundai.values import CAR, HyundaiFlags\n", "from opendbc.car.hyundai.fingerprints import FW_VERSIONS\n", "\n", @@ -72,7 +72,7 @@ " #if platform not in database:\n", " # print(f\"Skipping platform: {platform}, no data available\")\n", " # continue\n", - " \n", + "\n", " all_segments = database[platform]\n", "\n", " NUM_SEGMENTS = min(len(all_segments), MAX_SEGS_PER_PLATFORM)\n", diff --git a/tools/car_porting/examples/subaru_fuzzy_fingerprint.ipynb b/tools/car_porting/examples/subaru_fuzzy_fingerprint.ipynb index 708e55865bc1bf7..c4ffb0c02986335 100644 --- a/tools/car_porting/examples/subaru_fuzzy_fingerprint.ipynb +++ b/tools/car_porting/examples/subaru_fuzzy_fingerprint.ipynb @@ -6,13 +6,13 @@ "metadata": {}, "outputs": [], "source": [ - "from opendbc.car import structs\n", + "from opendbc.car import car\n", "from opendbc.car.subaru.values import CAR, SubaruFlags\n", "from opendbc.car.subaru.fingerprints import FW_VERSIONS\n", "\n", "TEST_PLATFORMS = set(CAR) - CAR.with_flags(SubaruFlags.PREGLOBAL)\n", "\n", - "Ecu = structs.CarParams.Ecu\n", + "Ecu = car.CarParams.Ecu\n", "\n", "FW_BY_ECU = {platform: {ecu: versions for (ecu, addr, sub_addr), versions in fw_versions.items()} for platform, fw_versions in FW_VERSIONS.items()}" ]