2024-03-18 06:57:41 -07:00
|
|
|
#!/usr/bin/env python3
|
2024-05-29 03:31:09 -07:00
|
|
|
from cereal import car, custom
|
2024-03-18 06:57:41 -07:00
|
|
|
from openpilot.common.conversions import Conversions as CV
|
2024-05-26 07:01:08 -04:00
|
|
|
from openpilot.selfdrive.car.mazda.values import CAR, LKAS_LIMITS, Buttons
|
2024-03-18 06:57:41 -07:00
|
|
|
from openpilot.selfdrive.car import create_button_events, get_safety_config
|
|
|
|
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
|
2024-05-26 07:01:08 -04:00
|
|
|
from openpilot.common.params import Params
|
|
|
|
|
|
|
|
params = Params()
|
2024-03-18 06:57:41 -07:00
|
|
|
|
|
|
|
ButtonType = car.CarState.ButtonEvent.Type
|
|
|
|
EventName = car.CarEvent.EventName
|
2024-05-09 20:03:47 -07:00
|
|
|
FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type
|
2024-05-26 07:01:08 -04:00
|
|
|
BUTTONS_DICT = {Buttons.SET_PLUS: ButtonType.accelCruise, Buttons.SET_MINUS: ButtonType.decelCruise,
|
|
|
|
Buttons.RESUME: ButtonType.resumeCruise, Buttons.CANCEL: ButtonType.cancel}
|
2024-03-18 06:57:41 -07:00
|
|
|
|
|
|
|
class CarInterface(CarInterfaceBase):
|
|
|
|
|
|
|
|
@staticmethod
|
2024-05-10 23:44:26 -07:00
|
|
|
def _get_params(ret, params, candidate, fingerprint, car_fw, disable_openpilot_long, experimental_long, docs):
|
2024-03-18 06:57:41 -07:00
|
|
|
ret.carName = "mazda"
|
|
|
|
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.mazda)]
|
|
|
|
ret.radarUnavailable = True
|
|
|
|
|
2024-05-09 22:33:33 -07:00
|
|
|
ret.dashcamOnly = False
|
2024-03-18 06:57:41 -07:00
|
|
|
|
|
|
|
ret.steerActuatorDelay = 0.1
|
|
|
|
ret.steerLimitTimer = 0.8
|
|
|
|
|
|
|
|
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
|
|
|
|
|
|
|
|
if candidate not in (CAR.CX5_2022, ):
|
|
|
|
ret.minSteerSpeed = LKAS_LIMITS.DISABLE_SPEED * CV.KPH_TO_MS
|
|
|
|
|
|
|
|
ret.centerToFront = ret.wheelbase * 0.41
|
|
|
|
|
2024-05-26 07:01:08 -04:00
|
|
|
if params.get_bool("CSLCEnabled"):
|
|
|
|
# Used for CEM with CSLC
|
|
|
|
ret.openpilotLongitudinalControl = True
|
|
|
|
ret.longitudinalTuning.deadzoneBP = [0.]
|
|
|
|
ret.longitudinalTuning.deadzoneV = [0.9] # == 2 mph allowable delta
|
|
|
|
ret.stoppingDecelRate = 4.5 # == 10 mph/s
|
|
|
|
ret.longitudinalActuatorDelayLowerBound = 1.
|
|
|
|
ret.longitudinalActuatorDelayUpperBound = 2.
|
|
|
|
|
|
|
|
ret.longitudinalTuning.kpBP = [8.94, 7.2, 28.] # 8.94 m/s == 20 mph
|
|
|
|
ret.longitudinalTuning.kpV = [0., 4., 2.] # set lower end to 0 since we can't drive below that speed
|
|
|
|
ret.longitudinalTuning.kiBP = [0.]
|
|
|
|
ret.longitudinalTuning.kiV = [0.1]
|
|
|
|
|
2024-03-18 06:57:41 -07:00
|
|
|
return ret
|
|
|
|
|
|
|
|
# returns a car.CarState
|
2024-05-24 02:41:19 -07:00
|
|
|
def _update(self, c, frogpilot_variables):
|
|
|
|
ret, fp_ret = self.CS.update(self.cp, self.cp_cam, frogpilot_variables)
|
2024-03-18 06:57:41 -07:00
|
|
|
|
|
|
|
# TODO: add button types for inc and dec
|
2024-05-26 22:30:17 -07:00
|
|
|
ret.buttonEvents = [
|
2024-05-26 07:01:08 -04:00
|
|
|
*create_button_events(self.CS.cruise_buttons, self.CS.prev_cruise_buttons, BUTTONS_DICT),
|
2024-05-26 22:30:17 -07:00
|
|
|
*create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}),
|
|
|
|
*create_button_events(self.CS.lkas_enabled, self.CS.lkas_previously_enabled, {1: FrogPilotButtonType.lkas}),
|
|
|
|
]
|
2024-03-18 06:57:41 -07:00
|
|
|
|
|
|
|
# events
|
|
|
|
events = self.create_common_events(ret)
|
|
|
|
|
|
|
|
if self.CS.lkas_disabled:
|
|
|
|
events.add(EventName.lkasDisabled)
|
|
|
|
elif self.CS.low_speed_alert:
|
|
|
|
events.add(EventName.belowSteerSpeed)
|
|
|
|
|
|
|
|
ret.events = events.to_msg()
|
|
|
|
|
2024-05-29 03:31:09 -07:00
|
|
|
return ret, fp_ret
|
2024-03-18 06:57:41 -07:00
|
|
|
|
2024-05-24 02:41:19 -07:00
|
|
|
def apply(self, c, now_nanos, frogpilot_variables):
|
|
|
|
return self.CC.update(c, self.CS, now_nanos, frogpilot_variables)
|