mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-30 19:33:45 +08:00
Abstract out common CarInterface.apply (#31924)
old-commit-hash: 3a7582d9a624ab7b43fd6cf98a19657252b11850
This commit is contained in:
@@ -37,6 +37,3 @@ class CarInterface(CarInterfaceBase):
|
|||||||
self.frame += 1
|
self.frame += 1
|
||||||
|
|
||||||
return ret
|
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()
|
ret.events = events.to_msg()
|
||||||
|
|
||||||
return ret
|
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()
|
ret.events = events.to_msg()
|
||||||
|
|
||||||
return ret
|
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()
|
ret.events = events.to_msg()
|
||||||
|
|
||||||
return ret
|
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()
|
ret.events = events.to_msg()
|
||||||
|
|
||||||
return ret
|
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()
|
ret.events = events.to_msg()
|
||||||
|
|
||||||
return ret
|
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.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.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:
|
if CarController is not None:
|
||||||
self.CC = CarController(self.cp.dbc_name, CP, self.VM)
|
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
|
@staticmethod
|
||||||
def get_pid_accel_limits(CP, current_speed, cruise_speed):
|
def get_pid_accel_limits(CP, current_speed, cruise_speed):
|
||||||
return ACCEL_MIN, ACCEL_MAX
|
return ACCEL_MIN, ACCEL_MAX
|
||||||
@@ -250,9 +253,6 @@ class CarInterfaceBase(ABC):
|
|||||||
|
|
||||||
return reader
|
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,
|
def create_common_events(self, cs_out, extra_gears=None, pcm_enable=True, allow_enable=True,
|
||||||
enable_buttons=(ButtonType.accelCruise, ButtonType.decelCruise)):
|
enable_buttons=(ButtonType.accelCruise, ButtonType.decelCruise)):
|
||||||
@@ -460,7 +460,7 @@ SendCan = tuple[int, int, bytes, int]
|
|||||||
|
|
||||||
class CarControllerBase(ABC):
|
class CarControllerBase(ABC):
|
||||||
@abstractmethod
|
@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
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,3 @@ class CarInterface(CarInterfaceBase):
|
|||||||
ret.events = events.to_msg()
|
ret.events = events.to_msg()
|
||||||
|
|
||||||
return ret
|
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
|
ret.vEgoRaw = self.sm[gps_sock].speed
|
||||||
|
|
||||||
return ret
|
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()
|
ret.events = events.to_msg()
|
||||||
|
|
||||||
return ret
|
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):
|
def init(CP, logcan, sendcan):
|
||||||
if CP.flags & SubaruFlags.DISABLE_EYESIGHT:
|
if CP.flags & SubaruFlags.DISABLE_EYESIGHT:
|
||||||
disable_ecu(logcan, sendcan, bus=2, addr=GLOBAL_ES_ADDR, com_cont_req=b'\x28\x03\x01')
|
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()
|
ret.events = self.create_common_events(ret).to_msg()
|
||||||
|
|
||||||
return ret
|
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()
|
ret.events = events.to_msg()
|
||||||
|
|
||||||
return ret
|
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.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 == car.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
|
||||||
@@ -26,7 +27,7 @@ class CarController(CarControllerBase):
|
|||||||
self.hca_frame_timer_running = 0
|
self.hca_frame_timer_running = 0
|
||||||
self.hca_frame_same_torque = 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
|
actuators = CC.actuators
|
||||||
hud_control = CC.hudControl
|
hud_control = CC.hudControl
|
||||||
can_sends = []
|
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
|
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):
|
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))
|
cancel=CC.cruiseControl.cancel, resume=CC.cruiseControl.resume))
|
||||||
|
|
||||||
new_actuators = actuators.copy()
|
new_actuators = actuators.copy()
|
||||||
@@ -117,4 +118,4 @@ class CarController(CarControllerBase):
|
|||||||
|
|
||||||
self.gra_acc_counter_last = CS.gra_stock_values["COUNTER"]
|
self.gra_acc_counter_last = CS.gra_stock_values["COUNTER"]
|
||||||
self.frame += 1
|
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.ext_bus = CANBUS.cam
|
||||||
self.cp_ext = self.cp_cam
|
self.cp_ext = self.cp_cam
|
||||||
|
|
||||||
self.eps_timer_soft_disable_alert = False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_params(ret, candidate: CAR, fingerprint, car_fw, experimental_long, docs):
|
def _get_params(ret, candidate: CAR, fingerprint, car_fw, experimental_long, docs):
|
||||||
ret.carName = "volkswagen"
|
ret.carName = "volkswagen"
|
||||||
@@ -126,13 +124,10 @@ class CarInterface(CarInterfaceBase):
|
|||||||
if c.enabled and ret.vEgo < self.CP.minEnableSpeed:
|
if c.enabled and ret.vEgo < self.CP.minEnableSpeed:
|
||||||
events.add(EventName.speedTooLow)
|
events.add(EventName.speedTooLow)
|
||||||
|
|
||||||
if self.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
|
||||||
|
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user