From 037d1db5fb62251698b8334943c59c6961a04ba5 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Sat, 10 Aug 2024 19:09:31 -0700 Subject: [PATCH] replace CarControl i hope there's no circular imports in hyundai's CC --- selfdrive/car/chrysler/chryslercan.py | 6 +++--- selfdrive/car/chrysler/interface.py | 2 +- selfdrive/car/ford/carcontroller.py | 7 +++---- selfdrive/car/ford/fordcan.py | 5 ++--- selfdrive/car/ford/interface.py | 2 +- selfdrive/car/gm/carcontroller.py | 10 ++++------ selfdrive/car/gm/interface.py | 2 +- selfdrive/car/honda/carcontroller.py | 7 +++---- selfdrive/car/honda/interface.py | 2 +- selfdrive/car/honda/values.py | 10 ++++------ selfdrive/car/hyundai/carcontroller.py | 10 +++++----- selfdrive/car/hyundai/interface.py | 2 +- selfdrive/car/interfaces.py | 8 ++++---- selfdrive/car/mazda/carcontroller.py | 5 ++--- selfdrive/car/mazda/interface.py | 2 +- selfdrive/car/nissan/carcontroller.py | 5 ++--- selfdrive/car/nissan/interface.py | 2 +- selfdrive/car/subaru/interface.py | 2 +- selfdrive/car/subaru/subarucan.py | 4 ++-- selfdrive/car/tesla/interface.py | 2 +- selfdrive/car/toyota/carcontroller.py | 8 +++----- selfdrive/car/toyota/interface.py | 2 +- selfdrive/car/volkswagen/carcontroller.py | 10 ++++------ selfdrive/car/volkswagen/interface.py | 2 +- 24 files changed, 52 insertions(+), 65 deletions(-) diff --git a/selfdrive/car/chrysler/chryslercan.py b/selfdrive/car/chrysler/chryslercan.py index 96439f35d8..9fefeef8fb 100644 --- a/selfdrive/car/chrysler/chryslercan.py +++ b/selfdrive/car/chrysler/chryslercan.py @@ -1,8 +1,8 @@ -from cereal import car +from openpilot.selfdrive.car import structs from openpilot.selfdrive.car.chrysler.values import RAM_CARS -GearShifter = car.CarState.GearShifter -VisualAlert = car.CarControl.HUDControl.VisualAlert +GearShifter = structs.CarState.GearShifter +VisualAlert = structs.CarControl.HUDControl.VisualAlert def create_lkas_hud(packer, CP, lkas_active, hud_alert, hud_count, car_model, auto_high_beam): # LKAS_HUD - Controls what lane-keeping icon is displayed diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index 34b91ce3e8..dbb8f2c24c 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -95,6 +95,6 @@ class CarInterface(CarInterfaceBase): if self.low_speed_alert: events.add(car.CarEvent.EventName.belowSteerSpeed) - ret.events = events.to_msg() + # ret.events = events.to_msg() return ret diff --git a/selfdrive/car/ford/carcontroller.py b/selfdrive/car/ford/carcontroller.py index 961d7086c4..12e301c722 100644 --- a/selfdrive/car/ford/carcontroller.py +++ b/selfdrive/car/ford/carcontroller.py @@ -1,13 +1,12 @@ -from cereal import car from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import apply_std_steer_angle_limits +from openpilot.selfdrive.car import apply_std_steer_angle_limits, structs from openpilot.selfdrive.car.ford import fordcan from openpilot.selfdrive.car.ford.values import CarControllerParams, FordFlags from openpilot.selfdrive.car.helpers import clip from openpilot.selfdrive.car.interfaces import CarControllerBase, V_CRUISE_MAX -LongCtrlState = car.CarControl.Actuators.LongControlState -VisualAlert = car.CarControl.HUDControl.VisualAlert +LongCtrlState = structs.CarControl.Actuators.LongControlState +VisualAlert = structs.CarControl.HUDControl.VisualAlert def apply_ford_curvature_limits(apply_curvature, apply_curvature_last, current_curvature, v_ego_raw): diff --git a/selfdrive/car/ford/fordcan.py b/selfdrive/car/ford/fordcan.py index 5bb3d0570f..b2cbe945c3 100644 --- a/selfdrive/car/ford/fordcan.py +++ b/selfdrive/car/ford/fordcan.py @@ -1,7 +1,6 @@ -from cereal import car -from openpilot.selfdrive.car import CanBusBase +from openpilot.selfdrive.car import CanBusBase, structs -HUDControl = car.CarControl.HUDControl +HUDControl = structs.CarControl.HUDControl class CanBus(CanBusBase): diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 192a12b9ec..bd1a5e7aca 100644 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -79,6 +79,6 @@ class CarInterface(CarInterfaceBase): if not self.CS.vehicle_sensors_valid: events.add(car.CarEvent.EventName.vehicleSensorsInvalid) - ret.events = events.to_msg() + # ret.events = events.to_msg() return ret diff --git a/selfdrive/car/gm/carcontroller.py b/selfdrive/car/gm/carcontroller.py index 8f048229e4..a33cf2a2a6 100644 --- a/selfdrive/car/gm/carcontroller.py +++ b/selfdrive/car/gm/carcontroller.py @@ -1,16 +1,14 @@ -from cereal import car from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import DT_CTRL, apply_driver_steer_torque_limits +from openpilot.selfdrive.car import DT_CTRL, apply_driver_steer_torque_limits, structs from openpilot.selfdrive.car.gm import gmcan from openpilot.selfdrive.car.conversions import Conversions as CV -from openpilot.selfdrive.car.structs import CarParams from openpilot.selfdrive.car.gm.values import DBC, CanBus, CarControllerParams, CruiseButtons from openpilot.selfdrive.car.helpers import interp from openpilot.selfdrive.car.interfaces import CarControllerBase -VisualAlert = car.CarControl.HUDControl.VisualAlert -NetworkLocation = CarParams.NetworkLocation -LongCtrlState = car.CarControl.Actuators.LongControlState +VisualAlert = structs.CarControl.HUDControl.VisualAlert +NetworkLocation = structs.CarParams.NetworkLocation +LongCtrlState = structs.CarControl.Actuators.LongControlState # Camera cancels up to 0.1s after brake is pressed, ECM allows 0.5s CAMERA_CANCEL_DELAY_FRAMES = 10 diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 68650dd874..58d50ecace 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -236,6 +236,6 @@ class CarInterface(CarInterfaceBase): if ret.vEgo < self.CP.minSteerSpeed: events.add(EventName.belowSteerSpeed) - ret.events = events.to_msg() + # ret.events = events.to_msg() return ret diff --git a/selfdrive/car/honda/carcontroller.py b/selfdrive/car/honda/carcontroller.py index 0f08ee21a8..e86a0aeb82 100644 --- a/selfdrive/car/honda/carcontroller.py +++ b/selfdrive/car/honda/carcontroller.py @@ -1,15 +1,14 @@ from collections import namedtuple -from cereal import car from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import DT_CTRL, rate_limit, make_tester_present_msg +from openpilot.selfdrive.car import DT_CTRL, rate_limit, make_tester_present_msg, structs from openpilot.selfdrive.car.helpers import clip, interp from openpilot.selfdrive.car.honda import hondacan from openpilot.selfdrive.car.honda.values import CruiseButtons, VISUAL_HUD, HONDA_BOSCH, HONDA_BOSCH_RADARLESS, HONDA_NIDEC_ALT_PCM_ACCEL, CarControllerParams from openpilot.selfdrive.car.interfaces import CarControllerBase -VisualAlert = car.CarControl.HUDControl.VisualAlert -LongCtrlState = car.CarControl.Actuators.LongControlState +VisualAlert = structs.CarControl.HUDControl.VisualAlert +LongCtrlState = structs.CarControl.Actuators.LongControlState def compute_gb_honda_bosch(accel, speed): diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 78e71be133..02398afd18 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -253,6 +253,6 @@ class CarInterface(CarInterfaceBase): if self.CS.CP.minEnableSpeed > 0 and ret.vEgo < 0.001: events.add(EventName.manualRestart) - ret.events = events.to_msg() + # ret.events = events.to_msg() return ret diff --git a/selfdrive/car/honda/values.py b/selfdrive/car/honda/values.py index 977bb4b7c4..499cbbc0e0 100644 --- a/selfdrive/car/honda/values.py +++ b/selfdrive/car/honda/values.py @@ -1,16 +1,14 @@ from dataclasses import dataclass from enum import Enum, IntFlag -from cereal import car from panda.python import uds -from openpilot.selfdrive.car import CarSpecs, PlatformConfig, Platforms, dbc_dict +from openpilot.selfdrive.car import CarSpecs, PlatformConfig, Platforms, dbc_dict, structs from openpilot.selfdrive.car.conversions import Conversions as CV -from openpilot.selfdrive.car.structs import CarParams from openpilot.selfdrive.car.docs_definitions import CarFootnote, CarHarness, CarDocs, CarParts, Column from openpilot.selfdrive.car.fw_query_definitions import FwQueryConfig, Request, StdQueries, p16 -Ecu = CarParams.Ecu -VisualAlert = car.CarControl.HUDControl.VisualAlert +Ecu = structs.CarParams.Ecu +VisualAlert = structs.CarControl.HUDControl.VisualAlert class CarControllerParams: @@ -91,7 +89,7 @@ VISUAL_HUD = { class HondaCarDocs(CarDocs): package: str = "Honda Sensing" - def init_make(self, CP: CarParams): + def init_make(self, CP: structs.CarParams): if CP.flags & HondaFlags.BOSCH: self.car_parts = CarParts.common([CarHarness.bosch_b]) if CP.flags & HondaFlags.BOSCH_RADARLESS else CarParts.common([CarHarness.bosch_a]) else: diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index 0e3a3f0afd..5169247ca2 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -1,15 +1,15 @@ -from cereal import car from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import DT_CTRL, apply_driver_steer_torque_limits, common_fault_avoidance, make_tester_present_msg +from openpilot.selfdrive.car import DT_CTRL, apply_driver_steer_torque_limits, common_fault_avoidance, make_tester_present_msg, structs from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.helpers import clip from openpilot.selfdrive.car.hyundai import hyundaicanfd, hyundaican +from openpilot.selfdrive.car.hyundai.carstate import CarState from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, Buttons, CarControllerParams, CANFD_CAR, CAR from openpilot.selfdrive.car.interfaces import CarControllerBase -VisualAlert = car.CarControl.HUDControl.VisualAlert -LongCtrlState = car.CarControl.Actuators.LongControlState +VisualAlert = structs.CarControl.HUDControl.VisualAlert +LongCtrlState = structs.CarControl.Actuators.LongControlState # EPS faults if you apply torque while the steering angle is above 90 degrees for more than 1 second # All slightly below EPS thresholds to avoid fault @@ -169,7 +169,7 @@ class CarController(CarControllerBase): self.frame += 1 return new_actuators, can_sends - def create_button_messages(self, CC: car.CarControl, CS: car.CarState, use_clu11: bool): + def create_button_messages(self, CC: structs.CarControl, CS: CarState, use_clu11: bool): can_sends = [] if use_clu11: if CC.cruiseControl.cancel: diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 65a82b1aac..341013ac09 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -173,6 +173,6 @@ class CarInterface(CarInterfaceBase): if self.low_speed_alert: events.add(car.CarEvent.EventName.belowSteerSpeed) - ret.events = events.to_msg() + # ret.events = events.to_msg() return ret diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 00333aac14..045d8d2a95 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -112,7 +112,7 @@ class CarInterfaceBase(ABC): dbc_name = "" if self.cp is None else self.cp.dbc_name self.CC: CarControllerBase = CarController(dbc_name, CP) - def apply(self, c: car.CarControl, now_nanos: int) -> tuple[car.CarControl.Actuators, list[CanData]]: + def apply(self, c: structs.CarControl, now_nanos: int) -> tuple[structs.CarControl.Actuators, list[CanData]]: return self.CC.update(c, self.CS, now_nanos) @staticmethod @@ -230,10 +230,10 @@ class CarInterfaceBase(ABC): tune.torque.steeringAngleDeadzoneDeg = steering_angle_deadzone_deg @abstractmethod - def _update(self, c: car.CarControl) -> structs.CarState: + def _update(self, c: structs.CarControl) -> structs.CarState: pass - def update(self, c: car.CarControl, can_packets: list[tuple[int, list[CanData]]]) -> structs.CarState: + def update(self, c: structs.CarControl, can_packets: list[tuple[int, list[CanData]]]) -> structs.CarState: # parse can for cp in self.can_parsers: if cp is not None: @@ -476,7 +476,7 @@ class CarControllerBase(ABC): self.frame = 0 @abstractmethod - def update(self, CC: car.CarControl.Actuators, CS: CarStateBase, now_nanos: int) -> tuple[car.CarControl.Actuators, list[CanData]]: + def update(self, CC: structs.CarControl.Actuators, CS: CarStateBase, now_nanos: int) -> tuple[structs.CarControl.Actuators, list[CanData]]: pass diff --git a/selfdrive/car/mazda/carcontroller.py b/selfdrive/car/mazda/carcontroller.py index 910e2303d8..13e7f8aa3d 100644 --- a/selfdrive/car/mazda/carcontroller.py +++ b/selfdrive/car/mazda/carcontroller.py @@ -1,11 +1,10 @@ -from cereal import car from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import apply_driver_steer_torque_limits +from openpilot.selfdrive.car import apply_driver_steer_torque_limits, structs from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.mazda import mazdacan from openpilot.selfdrive.car.mazda.values import CarControllerParams, Buttons -VisualAlert = car.CarControl.HUDControl.VisualAlert +VisualAlert = structs.CarControl.HUDControl.VisualAlert class CarController(CarControllerBase): diff --git a/selfdrive/car/mazda/interface.py b/selfdrive/car/mazda/interface.py index 8dcad2a2db..f761bcaeab 100755 --- a/selfdrive/car/mazda/interface.py +++ b/selfdrive/car/mazda/interface.py @@ -47,6 +47,6 @@ class CarInterface(CarInterfaceBase): elif self.CS.low_speed_alert: events.add(EventName.belowSteerSpeed) - ret.events = events.to_msg() + # ret.events = events.to_msg() return ret diff --git a/selfdrive/car/nissan/carcontroller.py b/selfdrive/car/nissan/carcontroller.py index 35a70ff106..ec9dc6e5c8 100644 --- a/selfdrive/car/nissan/carcontroller.py +++ b/selfdrive/car/nissan/carcontroller.py @@ -1,11 +1,10 @@ -from cereal import car from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import apply_std_steer_angle_limits +from openpilot.selfdrive.car import apply_std_steer_angle_limits, structs from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.nissan import nissancan from openpilot.selfdrive.car.nissan.values import CAR, CarControllerParams -VisualAlert = car.CarControl.HUDControl.VisualAlert +VisualAlert = structs.CarControl.HUDControl.VisualAlert class CarController(CarControllerBase): diff --git a/selfdrive/car/nissan/interface.py b/selfdrive/car/nissan/interface.py index 3ba76fdd4f..6808add0f0 100644 --- a/selfdrive/car/nissan/interface.py +++ b/selfdrive/car/nissan/interface.py @@ -41,6 +41,6 @@ class CarInterface(CarInterfaceBase): if self.CS.lkas_enabled: events.add(car.CarEvent.EventName.invalidLkasSetting) - ret.events = events.to_msg() + # ret.events = events.to_msg() return ret diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index 72410d2c80..35c317c34b 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -102,7 +102,7 @@ class CarInterface(CarInterfaceBase): ret = self.CS.update(self.cp, self.cp_cam, self.cp_body) - ret.events = self.create_common_events(ret).to_msg() + # ret.events = self.create_common_events(ret).to_msg() return ret diff --git a/selfdrive/car/subaru/subarucan.py b/selfdrive/car/subaru/subarucan.py index 41bd177ff2..fd6644c22c 100644 --- a/selfdrive/car/subaru/subarucan.py +++ b/selfdrive/car/subaru/subarucan.py @@ -1,7 +1,7 @@ -from cereal import car +from openpilot.selfdrive.car import structs from openpilot.selfdrive.car.subaru.values import CanBus -VisualAlert = car.CarControl.HUDControl.VisualAlert +VisualAlert = structs.CarControl.HUDControl.VisualAlert def create_steering_control(packer, apply_steer, steer_req): diff --git a/selfdrive/car/tesla/interface.py b/selfdrive/car/tesla/interface.py index b8a2b4960b..c8ecddae45 100755 --- a/selfdrive/car/tesla/interface.py +++ b/selfdrive/car/tesla/interface.py @@ -44,6 +44,6 @@ class CarInterface(CarInterfaceBase): def _update(self, c) -> structs.CarState: ret = self.CS.update(self.cp, self.cp_cam) - ret.events = self.create_common_events(ret).to_msg() + # ret.events = self.create_common_events(ret).to_msg() return ret diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index b4465adab9..51fa3e748c 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -1,7 +1,5 @@ -from cereal import car -from openpilot.selfdrive.car import apply_meas_steer_torque_limits, apply_std_steer_angle_limits, common_fault_avoidance, make_tester_present_msg +from openpilot.selfdrive.car import apply_meas_steer_torque_limits, apply_std_steer_angle_limits, common_fault_avoidance, make_tester_present_msg, structs from openpilot.selfdrive.car.can_definitions import CanData -from openpilot.selfdrive.car.structs import CarParams from openpilot.selfdrive.car.helpers import clip from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.toyota import toyotacan @@ -10,8 +8,8 @@ from openpilot.selfdrive.car.toyota.values import CAR, STATIC_DSU_MSGS, NO_STOP_ UNSUPPORTED_DSU_CAR from opendbc.can.packer import CANPacker -SteerControlType = CarParams.SteerControlType -VisualAlert = car.CarControl.HUDControl.VisualAlert +SteerControlType = structs.CarParams.SteerControlType +VisualAlert = structs.CarControl.HUDControl.VisualAlert # LKA limits # EPS faults if you apply torque while the steering rate is above 100 deg/s for too long diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 58778c7b97..e8fcb70309 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -175,6 +175,6 @@ class CarInterface(CarInterfaceBase): # while in standstill, send a user alert events.add(EventName.manualRestart) - ret.events = events.to_msg() + # ret.events = events.to_msg() return ret diff --git a/selfdrive/car/volkswagen/carcontroller.py b/selfdrive/car/volkswagen/carcontroller.py index 60f69fc88f..e782f14985 100644 --- a/selfdrive/car/volkswagen/carcontroller.py +++ b/selfdrive/car/volkswagen/carcontroller.py @@ -1,15 +1,13 @@ -from cereal import car from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import DT_CTRL, apply_driver_steer_torque_limits +from openpilot.selfdrive.car import DT_CTRL, apply_driver_steer_torque_limits, structs from openpilot.selfdrive.car.conversions import Conversions as CV -from openpilot.selfdrive.car.structs import CarParams from openpilot.selfdrive.car.helpers import clip from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.volkswagen import mqbcan, pqcan from openpilot.selfdrive.car.volkswagen.values import CANBUS, CarControllerParams, VolkswagenFlags -VisualAlert = car.CarControl.HUDControl.VisualAlert -LongCtrlState = car.CarControl.Actuators.LongControlState +VisualAlert = structs.CarControl.HUDControl.VisualAlert +LongCtrlState = structs.CarControl.Actuators.LongControlState class CarController(CarControllerBase): @@ -18,7 +16,7 @@ class CarController(CarControllerBase): self.CCP = CarControllerParams(CP) self.CCS = pqcan if CP.flags & VolkswagenFlags.PQ else mqbcan self.packer_pt = CANPacker(dbc_name) - self.ext_bus = CANBUS.pt if CP.networkLocation == CarParams.NetworkLocation.fwdCamera else CANBUS.cam + self.ext_bus = CANBUS.pt if CP.networkLocation == structs.CarParams.NetworkLocation.fwdCamera else CANBUS.cam self.apply_steer_last = 0 self.gra_acc_counter_last = None diff --git a/selfdrive/car/volkswagen/interface.py b/selfdrive/car/volkswagen/interface.py index ff1ed641a9..e4db6969ec 100644 --- a/selfdrive/car/volkswagen/interface.py +++ b/selfdrive/car/volkswagen/interface.py @@ -130,7 +130,7 @@ class CarInterface(CarInterfaceBase): if self.CC.eps_timer_soft_disable_alert: events.add(EventName.steerTimeLimit) - ret.events = events.to_msg() + # ret.events = events.to_msg() return ret