mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-18 12:42:06 +08:00
b2cdfc09ae
* init * deprecated * in controlsd directly * update * unused * combine * only once * fix * better * cleanup * more * Update CHANGELOGS.md
97 lines
3.6 KiB
Python
Executable File
97 lines
3.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
from cereal import car
|
|
from openpilot.common.conversions import Conversions as CV
|
|
from openpilot.selfdrive.car.mazda.values import CAR, LKAS_LIMITS
|
|
from openpilot.selfdrive.car import create_button_events, get_safety_config
|
|
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
|
|
|
|
ButtonType = car.CarState.ButtonEvent.Type
|
|
EventName = car.CarEvent.EventName
|
|
GearShifter = car.CarState.GearShifter
|
|
|
|
class CarInterface(CarInterfaceBase):
|
|
def __init__(self, CP, CarController, CarState):
|
|
super().__init__(CP, CarController, CarState)
|
|
|
|
@staticmethod
|
|
def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
|
|
ret.carName = "mazda"
|
|
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.mazda)]
|
|
ret.radarUnavailable = True
|
|
ret.customStockLongAvailable = True
|
|
|
|
ret.dashcamOnly = candidate not in (CAR.MAZDA_CX5_2022, CAR.MAZDA_CX9_2021)
|
|
|
|
ret.steerActuatorDelay = 0.1
|
|
ret.steerLimitTimer = 0.8
|
|
|
|
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
|
|
|
|
if candidate not in (CAR.MAZDA_CX5_2022, ):
|
|
ret.minSteerSpeed = LKAS_LIMITS.DISABLE_SPEED * CV.KPH_TO_MS
|
|
|
|
ret.centerToFront = ret.wheelbase * 0.41
|
|
|
|
return ret
|
|
|
|
# returns a car.CarState
|
|
def _update(self, c):
|
|
ret = self.CS.update(self.cp, self.cp_cam)
|
|
|
|
# TODO: add button types for inc and dec
|
|
self.CS.button_events = [
|
|
*self.CS.button_events,
|
|
*create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}),
|
|
*create_button_events(self.CS.lkas_enabled, self.CS.prev_lkas_enabled, {1: ButtonType.altButton1}),
|
|
]
|
|
|
|
self.CS.mads_enabled = self.get_sp_cruise_main_state(ret)
|
|
|
|
self.CS.accEnabled = self.get_sp_v_cruise_non_pcm_state(ret, c.vCruise, self.CS.accEnabled)
|
|
|
|
if ret.cruiseState.available:
|
|
if self.enable_mads:
|
|
if not self.CS.prev_mads_enabled and self.CS.mads_enabled:
|
|
self.CS.madsEnabled = True
|
|
if any(b.type == ButtonType.altButton1 and b.pressed for b in self.CS.button_events):
|
|
self.CS.madsEnabled = not self.CS.madsEnabled
|
|
self.CS.madsEnabled = self.get_acc_mads(ret, self.CS.madsEnabled)
|
|
else:
|
|
self.CS.madsEnabled = False
|
|
|
|
if not self.CP.pcmCruise or (self.CP.pcmCruise and self.CP.minEnableSpeed > 0) or not self.CP.pcmCruiseSpeed:
|
|
if any(b.type == ButtonType.cancel for b in self.CS.button_events):
|
|
self.get_sp_cancel_cruise_state()
|
|
if self.get_sp_pedal_disengage(ret):
|
|
self.get_sp_cancel_cruise_state()
|
|
ret.cruiseState.enabled = ret.cruiseState.enabled if not self.enable_mads else False if self.CP.pcmCruise else self.CS.accEnabled
|
|
|
|
if self.CP.pcmCruise and self.CP.minEnableSpeed > 0 and self.CP.pcmCruiseSpeed:
|
|
if ret.gasPressed and not ret.cruiseState.enabled:
|
|
self.CS.accEnabled = False
|
|
self.CS.accEnabled = ret.cruiseState.enabled or self.CS.accEnabled
|
|
|
|
ret = self.get_sp_common_state(ret)
|
|
|
|
ret.buttonEvents = [
|
|
*self.CS.button_events,
|
|
*self.button_events.create_mads_event(self.CS.madsEnabled, self.CS.out.madsEnabled) # MADS BUTTON
|
|
]
|
|
|
|
# events
|
|
events = self.create_common_events(ret, c, extra_gears=[GearShifter.sport, GearShifter.low, GearShifter.brake],
|
|
pcm_enable=False)
|
|
|
|
events, ret = self.create_sp_events(ret, events)
|
|
|
|
#if self.CS.lkas_disabled:
|
|
# events.add(EventName.lkasDisabled)
|
|
if self.CS.low_speed_alert:
|
|
events.add(EventName.belowSteerSpeed)
|
|
|
|
ret.customStockLong = self.update_custom_stock_long()
|
|
|
|
ret.events = events.to_msg()
|
|
|
|
return ret
|