Abstract out common CarInterface.apply (#31924)

old-commit-hash: 3a7582d9a6
pull/32199/head
Adeeb Shihadeh 1 year ago committed by GitHub
parent 1f218e4169
commit cd74ed0489
  1. 3
      selfdrive/car/body/interface.py
  2. 3
      selfdrive/car/chrysler/interface.py
  3. 3
      selfdrive/car/ford/interface.py
  4. 3
      selfdrive/car/gm/interface.py
  5. 5
      selfdrive/car/honda/interface.py
  6. 3
      selfdrive/car/hyundai/interface.py
  7. 10
      selfdrive/car/interfaces.py
  8. 3
      selfdrive/car/mazda/interface.py
  9. 4
      selfdrive/car/mock/interface.py
  10. 3
      selfdrive/car/nissan/interface.py
  11. 3
      selfdrive/car/subaru/interface.py
  12. 3
      selfdrive/car/tesla/interface.py
  13. 5
      selfdrive/car/toyota/interface.py
  14. 7
      selfdrive/car/volkswagen/carcontroller.py
  15. 7
      selfdrive/car/volkswagen/interface.py

@ -37,6 +37,3 @@ class CarInterface(CarInterfaceBase):
self.frame += 1
return ret
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -94,6 +94,3 @@ class CarInterface(CarInterfaceBase):
ret.events = events.to_msg()
return ret
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -71,6 +71,3 @@ class CarInterface(CarInterfaceBase):
ret.events = events.to_msg()
return ret
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -237,6 +237,3 @@ class CarInterface(CarInterfaceBase):
ret.events = events.to_msg()
return ret
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -257,8 +257,3 @@ class CarInterface(CarInterfaceBase):
ret.events = events.to_msg()
return ret
# pass in a car.CarControl
# to be called @ 100hz
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -175,6 +175,3 @@ class CarInterface(CarInterfaceBase):
ret.events = events.to_msg()
return ret
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -93,10 +93,13 @@ class CarInterfaceBase(ABC):
self.cp_loopback = self.CS.get_loopback_can_parser(CP)
self.can_parsers = [self.cp, self.cp_cam, self.cp_adas, self.cp_body, self.cp_loopback]
self.CC = None
self.CC: CarControllerBase = None
if CarController is not None:
self.CC = CarController(self.cp.dbc_name, CP, self.VM)
def apply(self, c: car.CarControl, now_nanos: int) -> tuple[car.CarControl.Actuators, list[tuple[int, int, bytes, int]]]:
return self.CC.update(c, self.CS, now_nanos)
@staticmethod
def get_pid_accel_limits(CP, current_speed, cruise_speed):
return ACCEL_MIN, ACCEL_MAX
@ -250,9 +253,6 @@ class CarInterfaceBase(ABC):
return reader
@abstractmethod
def apply(self, c: car.CarControl, now_nanos: int) -> tuple[car.CarControl.Actuators, list[bytes]]:
pass
def create_common_events(self, cs_out, extra_gears=None, pcm_enable=True, allow_enable=True,
enable_buttons=(ButtonType.accelCruise, ButtonType.decelCruise)):
@ -460,7 +460,7 @@ SendCan = tuple[int, int, bytes, int]
class CarControllerBase(ABC):
@abstractmethod
def update(self, CC, CS, now_nanos) -> tuple[car.CarControl.Actuators, list[SendCan]]:
def update(self, CC: car.CarControl.Actuators, CS: car.CarState, now_nanos: int) -> tuple[car.CarControl.Actuators, list[SendCan]]:
pass

@ -48,6 +48,3 @@ class CarInterface(CarInterfaceBase):
ret.events = events.to_msg()
return ret
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -29,7 +29,3 @@ class CarInterface(CarInterfaceBase):
ret.vEgoRaw = self.sm[gps_sock].speed
return ret
def apply(self, c, now_nanos):
actuators = car.CarControl.Actuators.new_message()
return actuators, []

@ -42,6 +42,3 @@ class CarInterface(CarInterfaceBase):
ret.events = events.to_msg()
return ret
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -114,6 +114,3 @@ class CarInterface(CarInterfaceBase):
def init(CP, logcan, sendcan):
if CP.flags & SubaruFlags.DISABLE_EYESIGHT:
disable_ecu(logcan, sendcan, bus=2, addr=GLOBAL_ES_ADDR, com_cont_req=b'\x28\x03\x01')
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -50,6 +50,3 @@ class CarInterface(CarInterfaceBase):
ret.events = self.create_common_events(ret).to_msg()
return ret
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -200,8 +200,3 @@ class CarInterface(CarInterfaceBase):
ret.events = events.to_msg()
return ret
# pass in a car.CarControl
# to be called @ 100hz
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)

@ -18,6 +18,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 == car.CarParams.NetworkLocation.fwdCamera else CANBUS.cam
self.apply_steer_last = 0
self.gra_acc_counter_last = None
@ -26,7 +27,7 @@ class CarController(CarControllerBase):
self.hca_frame_timer_running = 0
self.hca_frame_same_torque = 0
def update(self, CC, CS, ext_bus, now_nanos):
def update(self, CC, CS, now_nanos):
actuators = CC.actuators
hud_control = CC.hudControl
can_sends = []
@ -108,7 +109,7 @@ class CarController(CarControllerBase):
gra_send_ready = self.CP.pcmCruise and CS.gra_stock_values["COUNTER"] != self.gra_acc_counter_last
if gra_send_ready and (CC.cruiseControl.cancel or CC.cruiseControl.resume):
can_sends.append(self.CCS.create_acc_buttons_control(self.packer_pt, ext_bus, CS.gra_stock_values,
can_sends.append(self.CCS.create_acc_buttons_control(self.packer_pt, self.ext_bus, CS.gra_stock_values,
cancel=CC.cruiseControl.cancel, resume=CC.cruiseControl.resume))
new_actuators = actuators.copy()
@ -117,4 +118,4 @@ class CarController(CarControllerBase):
self.gra_acc_counter_last = CS.gra_stock_values["COUNTER"]
self.frame += 1
return new_actuators, can_sends, self.eps_timer_soft_disable_alert
return new_actuators, can_sends

@ -19,8 +19,6 @@ class CarInterface(CarInterfaceBase):
self.ext_bus = CANBUS.cam
self.cp_ext = self.cp_cam
self.eps_timer_soft_disable_alert = False
@staticmethod
def _get_params(ret, candidate: CAR, fingerprint, car_fw, experimental_long, docs):
ret.carName = "volkswagen"
@ -126,13 +124,10 @@ class CarInterface(CarInterfaceBase):
if c.enabled and ret.vEgo < self.CP.minEnableSpeed:
events.add(EventName.speedTooLow)
if self.eps_timer_soft_disable_alert:
if self.CC.eps_timer_soft_disable_alert:
events.add(EventName.steerTimeLimit)
ret.events = events.to_msg()
return ret
def apply(self, c, now_nanos):
new_actuators, can_sends, self.eps_timer_soft_disable_alert = self.CC.update(c, self.CS, self.ext_bus, now_nanos)
return new_actuators, can_sends

Loading…
Cancel
Save