carrot/selfdrive/car/mazda/interface.py

78 lines
2.9 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2024-05-29 03:31:09 -07:00
from cereal import car, custom
from openpilot.common.conversions import Conversions as CV
from openpilot.selfdrive.car.mazda.values import CAR, LKAS_LIMITS, Buttons
from openpilot.selfdrive.car import create_button_events, get_safety_config
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.common.params import Params
params = Params()
ButtonType = car.CarState.ButtonEvent.Type
EventName = car.CarEvent.EventName
2024-05-09 20:03:47 -07:00
FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type
BUTTONS_DICT = {Buttons.SET_PLUS: ButtonType.accelCruise, Buttons.SET_MINUS: ButtonType.decelCruise,
Buttons.RESUME: ButtonType.resumeCruise, Buttons.CANCEL: ButtonType.cancel}
class CarInterface(CarInterfaceBase):
@staticmethod
def _get_params(ret, params, candidate, fingerprint, car_fw, disable_openpilot_long, experimental_long, docs):
ret.carName = "mazda"
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.mazda)]
ret.radarUnavailable = True
ret.dashcamOnly = False
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
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]
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)
# TODO: add button types for inc and dec
ret.buttonEvents = [
*create_button_events(self.CS.cruise_buttons, self.CS.prev_cruise_buttons, BUTTONS_DICT),
*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}),
]
# 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-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)