replace CarControl

i hope there's no circular imports in hyundai's CC
pull/33208/head
Shane Smiskol 11 months ago
parent 7bc96d1c82
commit 037d1db5fb
  1. 6
      selfdrive/car/chrysler/chryslercan.py
  2. 2
      selfdrive/car/chrysler/interface.py
  3. 7
      selfdrive/car/ford/carcontroller.py
  4. 5
      selfdrive/car/ford/fordcan.py
  5. 2
      selfdrive/car/ford/interface.py
  6. 10
      selfdrive/car/gm/carcontroller.py
  7. 2
      selfdrive/car/gm/interface.py
  8. 7
      selfdrive/car/honda/carcontroller.py
  9. 2
      selfdrive/car/honda/interface.py
  10. 10
      selfdrive/car/honda/values.py
  11. 10
      selfdrive/car/hyundai/carcontroller.py
  12. 2
      selfdrive/car/hyundai/interface.py
  13. 8
      selfdrive/car/interfaces.py
  14. 5
      selfdrive/car/mazda/carcontroller.py
  15. 2
      selfdrive/car/mazda/interface.py
  16. 5
      selfdrive/car/nissan/carcontroller.py
  17. 2
      selfdrive/car/nissan/interface.py
  18. 2
      selfdrive/car/subaru/interface.py
  19. 4
      selfdrive/car/subaru/subarucan.py
  20. 2
      selfdrive/car/tesla/interface.py
  21. 8
      selfdrive/car/toyota/carcontroller.py
  22. 2
      selfdrive/car/toyota/interface.py
  23. 10
      selfdrive/car/volkswagen/carcontroller.py
  24. 2
      selfdrive/car/volkswagen/interface.py

@ -1,8 +1,8 @@
from cereal import car from openpilot.selfdrive.car import structs
from openpilot.selfdrive.car.chrysler.values import RAM_CARS from openpilot.selfdrive.car.chrysler.values import RAM_CARS
GearShifter = car.CarState.GearShifter GearShifter = structs.CarState.GearShifter
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
def create_lkas_hud(packer, CP, lkas_active, hud_alert, hud_count, car_model, auto_high_beam): 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 # LKAS_HUD - Controls what lane-keeping icon is displayed

@ -95,6 +95,6 @@ class CarInterface(CarInterfaceBase):
if self.low_speed_alert: if self.low_speed_alert:
events.add(car.CarEvent.EventName.belowSteerSpeed) events.add(car.CarEvent.EventName.belowSteerSpeed)
ret.events = events.to_msg() # ret.events = events.to_msg()
return ret return ret

@ -1,13 +1,12 @@
from cereal import car
from opendbc.can.packer import CANPacker 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 import fordcan
from openpilot.selfdrive.car.ford.values import CarControllerParams, FordFlags from openpilot.selfdrive.car.ford.values import CarControllerParams, FordFlags
from openpilot.selfdrive.car.helpers import clip from openpilot.selfdrive.car.helpers import clip
from openpilot.selfdrive.car.interfaces import CarControllerBase, V_CRUISE_MAX from openpilot.selfdrive.car.interfaces import CarControllerBase, V_CRUISE_MAX
LongCtrlState = car.CarControl.Actuators.LongControlState LongCtrlState = structs.CarControl.Actuators.LongControlState
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
def apply_ford_curvature_limits(apply_curvature, apply_curvature_last, current_curvature, v_ego_raw): def apply_ford_curvature_limits(apply_curvature, apply_curvature_last, current_curvature, v_ego_raw):

@ -1,7 +1,6 @@
from cereal import car from openpilot.selfdrive.car import CanBusBase, structs
from openpilot.selfdrive.car import CanBusBase
HUDControl = car.CarControl.HUDControl HUDControl = structs.CarControl.HUDControl
class CanBus(CanBusBase): class CanBus(CanBusBase):

@ -79,6 +79,6 @@ class CarInterface(CarInterfaceBase):
if not self.CS.vehicle_sensors_valid: if not self.CS.vehicle_sensors_valid:
events.add(car.CarEvent.EventName.vehicleSensorsInvalid) events.add(car.CarEvent.EventName.vehicleSensorsInvalid)
ret.events = events.to_msg() # ret.events = events.to_msg()
return ret return ret

@ -1,16 +1,14 @@
from cereal import car
from opendbc.can.packer import CANPacker 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.gm import gmcan
from openpilot.selfdrive.car.conversions import Conversions as CV 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.gm.values import DBC, CanBus, CarControllerParams, CruiseButtons
from openpilot.selfdrive.car.helpers import interp from openpilot.selfdrive.car.helpers import interp
from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.interfaces import CarControllerBase
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
NetworkLocation = CarParams.NetworkLocation NetworkLocation = structs.CarParams.NetworkLocation
LongCtrlState = car.CarControl.Actuators.LongControlState LongCtrlState = structs.CarControl.Actuators.LongControlState
# Camera cancels up to 0.1s after brake is pressed, ECM allows 0.5s # Camera cancels up to 0.1s after brake is pressed, ECM allows 0.5s
CAMERA_CANCEL_DELAY_FRAMES = 10 CAMERA_CANCEL_DELAY_FRAMES = 10

@ -236,6 +236,6 @@ class CarInterface(CarInterfaceBase):
if ret.vEgo < self.CP.minSteerSpeed: if ret.vEgo < self.CP.minSteerSpeed:
events.add(EventName.belowSteerSpeed) events.add(EventName.belowSteerSpeed)
ret.events = events.to_msg() # ret.events = events.to_msg()
return ret return ret

@ -1,15 +1,14 @@
from collections import namedtuple from collections import namedtuple
from cereal import car
from opendbc.can.packer import CANPacker 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.helpers import clip, interp
from openpilot.selfdrive.car.honda import hondacan 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.honda.values import CruiseButtons, VISUAL_HUD, HONDA_BOSCH, HONDA_BOSCH_RADARLESS, HONDA_NIDEC_ALT_PCM_ACCEL, CarControllerParams
from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.interfaces import CarControllerBase
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
LongCtrlState = car.CarControl.Actuators.LongControlState LongCtrlState = structs.CarControl.Actuators.LongControlState
def compute_gb_honda_bosch(accel, speed): def compute_gb_honda_bosch(accel, speed):

@ -253,6 +253,6 @@ class CarInterface(CarInterfaceBase):
if self.CS.CP.minEnableSpeed > 0 and ret.vEgo < 0.001: if self.CS.CP.minEnableSpeed > 0 and ret.vEgo < 0.001:
events.add(EventName.manualRestart) events.add(EventName.manualRestart)
ret.events = events.to_msg() # ret.events = events.to_msg()
return ret return ret

@ -1,16 +1,14 @@
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum, IntFlag from enum import Enum, IntFlag
from cereal import car
from panda.python import uds 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.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.docs_definitions import CarFootnote, CarHarness, CarDocs, CarParts, Column
from openpilot.selfdrive.car.fw_query_definitions import FwQueryConfig, Request, StdQueries, p16 from openpilot.selfdrive.car.fw_query_definitions import FwQueryConfig, Request, StdQueries, p16
Ecu = CarParams.Ecu Ecu = structs.CarParams.Ecu
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
class CarControllerParams: class CarControllerParams:
@ -91,7 +89,7 @@ VISUAL_HUD = {
class HondaCarDocs(CarDocs): class HondaCarDocs(CarDocs):
package: str = "Honda Sensing" package: str = "Honda Sensing"
def init_make(self, CP: CarParams): def init_make(self, CP: structs.CarParams):
if CP.flags & HondaFlags.BOSCH: 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]) self.car_parts = CarParts.common([CarHarness.bosch_b]) if CP.flags & HondaFlags.BOSCH_RADARLESS else CarParts.common([CarHarness.bosch_a])
else: else:

@ -1,15 +1,15 @@
from cereal import car
from opendbc.can.packer import CANPacker 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.conversions import Conversions as CV
from openpilot.selfdrive.car.helpers import clip from openpilot.selfdrive.car.helpers import clip
from openpilot.selfdrive.car.hyundai import hyundaicanfd, hyundaican 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.hyundaicanfd import CanBus
from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, Buttons, CarControllerParams, CANFD_CAR, CAR from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, Buttons, CarControllerParams, CANFD_CAR, CAR
from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.interfaces import CarControllerBase
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
LongCtrlState = car.CarControl.Actuators.LongControlState LongCtrlState = structs.CarControl.Actuators.LongControlState
# EPS faults if you apply torque while the steering angle is above 90 degrees for more than 1 second # 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 # All slightly below EPS thresholds to avoid fault
@ -169,7 +169,7 @@ class CarController(CarControllerBase):
self.frame += 1 self.frame += 1
return new_actuators, can_sends 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 = [] can_sends = []
if use_clu11: if use_clu11:
if CC.cruiseControl.cancel: if CC.cruiseControl.cancel:

@ -173,6 +173,6 @@ class CarInterface(CarInterfaceBase):
if self.low_speed_alert: if self.low_speed_alert:
events.add(car.CarEvent.EventName.belowSteerSpeed) events.add(car.CarEvent.EventName.belowSteerSpeed)
ret.events = events.to_msg() # ret.events = events.to_msg()
return ret return ret

@ -112,7 +112,7 @@ class CarInterfaceBase(ABC):
dbc_name = "" if self.cp is None else self.cp.dbc_name dbc_name = "" if self.cp is None else self.cp.dbc_name
self.CC: CarControllerBase = CarController(dbc_name, CP) 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) return self.CC.update(c, self.CS, now_nanos)
@staticmethod @staticmethod
@ -230,10 +230,10 @@ class CarInterfaceBase(ABC):
tune.torque.steeringAngleDeadzoneDeg = steering_angle_deadzone_deg tune.torque.steeringAngleDeadzoneDeg = steering_angle_deadzone_deg
@abstractmethod @abstractmethod
def _update(self, c: car.CarControl) -> structs.CarState: def _update(self, c: structs.CarControl) -> structs.CarState:
pass 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 # parse can
for cp in self.can_parsers: for cp in self.can_parsers:
if cp is not None: if cp is not None:
@ -476,7 +476,7 @@ class CarControllerBase(ABC):
self.frame = 0 self.frame = 0
@abstractmethod @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 pass

@ -1,11 +1,10 @@
from cereal import car
from opendbc.can.packer import CANPacker 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.interfaces import CarControllerBase
from openpilot.selfdrive.car.mazda import mazdacan from openpilot.selfdrive.car.mazda import mazdacan
from openpilot.selfdrive.car.mazda.values import CarControllerParams, Buttons from openpilot.selfdrive.car.mazda.values import CarControllerParams, Buttons
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
class CarController(CarControllerBase): class CarController(CarControllerBase):

@ -47,6 +47,6 @@ class CarInterface(CarInterfaceBase):
elif self.CS.low_speed_alert: elif self.CS.low_speed_alert:
events.add(EventName.belowSteerSpeed) events.add(EventName.belowSteerSpeed)
ret.events = events.to_msg() # ret.events = events.to_msg()
return ret return ret

@ -1,11 +1,10 @@
from cereal import car
from opendbc.can.packer import CANPacker 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.interfaces import CarControllerBase
from openpilot.selfdrive.car.nissan import nissancan from openpilot.selfdrive.car.nissan import nissancan
from openpilot.selfdrive.car.nissan.values import CAR, CarControllerParams from openpilot.selfdrive.car.nissan.values import CAR, CarControllerParams
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
class CarController(CarControllerBase): class CarController(CarControllerBase):

@ -41,6 +41,6 @@ class CarInterface(CarInterfaceBase):
if self.CS.lkas_enabled: if self.CS.lkas_enabled:
events.add(car.CarEvent.EventName.invalidLkasSetting) events.add(car.CarEvent.EventName.invalidLkasSetting)
ret.events = events.to_msg() # ret.events = events.to_msg()
return ret return ret

@ -102,7 +102,7 @@ class CarInterface(CarInterfaceBase):
ret = self.CS.update(self.cp, self.cp_cam, self.cp_body) 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 return ret

@ -1,7 +1,7 @@
from cereal import car from openpilot.selfdrive.car import structs
from openpilot.selfdrive.car.subaru.values import CanBus 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): def create_steering_control(packer, apply_steer, steer_req):

@ -44,6 +44,6 @@ class CarInterface(CarInterfaceBase):
def _update(self, c) -> structs.CarState: def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam) 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 return ret

@ -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, structs
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.can_definitions import CanData 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.helpers import clip
from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.interfaces import CarControllerBase
from openpilot.selfdrive.car.toyota import toyotacan 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 UNSUPPORTED_DSU_CAR
from opendbc.can.packer import CANPacker from opendbc.can.packer import CANPacker
SteerControlType = CarParams.SteerControlType SteerControlType = structs.CarParams.SteerControlType
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
# LKA limits # LKA limits
# EPS faults if you apply torque while the steering rate is above 100 deg/s for too long # EPS faults if you apply torque while the steering rate is above 100 deg/s for too long

@ -175,6 +175,6 @@ class CarInterface(CarInterfaceBase):
# while in standstill, send a user alert # while in standstill, send a user alert
events.add(EventName.manualRestart) events.add(EventName.manualRestart)
ret.events = events.to_msg() # ret.events = events.to_msg()
return ret return ret

@ -1,15 +1,13 @@
from cereal import car
from opendbc.can.packer import CANPacker 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.conversions import Conversions as CV
from openpilot.selfdrive.car.structs import CarParams
from openpilot.selfdrive.car.helpers import clip from openpilot.selfdrive.car.helpers import clip
from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.interfaces import CarControllerBase
from openpilot.selfdrive.car.volkswagen import mqbcan, pqcan from openpilot.selfdrive.car.volkswagen import mqbcan, pqcan
from openpilot.selfdrive.car.volkswagen.values import CANBUS, CarControllerParams, VolkswagenFlags from openpilot.selfdrive.car.volkswagen.values import CANBUS, CarControllerParams, VolkswagenFlags
VisualAlert = car.CarControl.HUDControl.VisualAlert VisualAlert = structs.CarControl.HUDControl.VisualAlert
LongCtrlState = car.CarControl.Actuators.LongControlState LongCtrlState = structs.CarControl.Actuators.LongControlState
class CarController(CarControllerBase): class CarController(CarControllerBase):
@ -18,7 +16,7 @@ class CarController(CarControllerBase):
self.CCP = CarControllerParams(CP) self.CCP = CarControllerParams(CP)
self.CCS = pqcan if CP.flags & VolkswagenFlags.PQ else mqbcan self.CCS = pqcan if CP.flags & VolkswagenFlags.PQ else mqbcan
self.packer_pt = CANPacker(dbc_name) 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.apply_steer_last = 0
self.gra_acc_counter_last = None self.gra_acc_counter_last = None

@ -130,7 +130,7 @@ class CarInterface(CarInterfaceBase):
if self.CC.eps_timer_soft_disable_alert: if self.CC.eps_timer_soft_disable_alert:
events.add(EventName.steerTimeLimit) events.add(EventName.steerTimeLimit)
ret.events = events.to_msg() # ret.events = events.to_msg()
return ret return ret

Loading…
Cancel
Save