2025-01-29 09:09:58 +00:00
|
|
|
import numpy as np
|
2023-09-27 15:45:31 -07:00
|
|
|
from panda import Panda
|
2025-01-29 09:09:58 +00:00
|
|
|
from opendbc.car import Bus, get_safety_config, structs
|
|
|
|
from opendbc.car.common.conversions import Conversions as CV
|
|
|
|
from opendbc.car.ford.fordcan import CanBus
|
|
|
|
from opendbc.car.ford.values import CarControllerParams, DBC, Ecu, FordFlags, RADAR
|
|
|
|
from opendbc.car.interfaces import CarInterfaceBase
|
2023-09-27 15:45:31 -07:00
|
|
|
|
2025-01-29 09:09:58 +00:00
|
|
|
TransmissionType = structs.CarParams.TransmissionType
|
2023-09-27 15:45:31 -07:00
|
|
|
|
|
|
|
|
|
|
|
class CarInterface(CarInterfaceBase):
|
|
|
|
@staticmethod
|
2025-01-29 09:09:58 +00:00
|
|
|
def get_pid_accel_limits(CP, current_speed, cruise_speed):
|
|
|
|
# PCM doesn't allow acceleration near cruise_speed,
|
|
|
|
# so limit limits of pid to prevent windup
|
|
|
|
ACCEL_MAX_VALS = [CarControllerParams.ACCEL_MAX, 0.2]
|
|
|
|
ACCEL_MAX_BP = [cruise_speed - 2., cruise_speed - .4]
|
|
|
|
return CarControllerParams.ACCEL_MIN, np.interp(current_speed, ACCEL_MAX_BP, ACCEL_MAX_VALS)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs) -> structs.CarParams:
|
|
|
|
ret.brand = "ford"
|
2024-06-11 01:36:40 +00:00
|
|
|
ret.dashcamOnly = bool(ret.flags & FordFlags.CANFD)
|
2023-09-27 15:45:31 -07:00
|
|
|
|
2025-01-29 09:09:58 +00:00
|
|
|
ret.radarUnavailable = Bus.radar not in DBC[candidate]
|
|
|
|
ret.steerControlType = structs.CarParams.SteerControlType.angle
|
2023-09-27 15:45:31 -07:00
|
|
|
ret.steerActuatorDelay = 0.2
|
|
|
|
ret.steerLimitTimer = 1.0
|
|
|
|
|
2025-01-29 09:09:58 +00:00
|
|
|
ret.longitudinalTuning.kiBP = [0.]
|
|
|
|
ret.longitudinalTuning.kiV = [0.5]
|
|
|
|
|
|
|
|
if not ret.radarUnavailable and DBC[candidate][Bus.radar] == RADAR.DELPHI_MRR:
|
|
|
|
# average of 33.3 Hz radar timestep / 4 scan modes = 60 ms
|
|
|
|
# MRR_Header_Timestamps->CAN_DET_TIME_SINCE_MEAS reports 61.3 ms
|
|
|
|
ret.radarDelay = 0.06
|
2024-02-21 23:02:43 +00:00
|
|
|
|
2023-09-27 15:45:31 -07:00
|
|
|
CAN = CanBus(fingerprint=fingerprint)
|
2025-01-29 09:09:58 +00:00
|
|
|
cfgs = [get_safety_config(structs.CarParams.SafetyModel.ford)]
|
2023-09-27 15:45:31 -07:00
|
|
|
if CAN.main >= 4:
|
2025-01-29 09:09:58 +00:00
|
|
|
cfgs.insert(0, get_safety_config(structs.CarParams.SafetyModel.noOutput))
|
2023-09-27 15:45:31 -07:00
|
|
|
ret.safetyConfigs = cfgs
|
|
|
|
|
2025-01-29 09:09:58 +00:00
|
|
|
# TODO: verify stock AEB compatibility and longitudinal limit safety before shipping to release
|
|
|
|
ret.experimentalLongitudinalAvailable = ret.radarUnavailable
|
|
|
|
if experimental_long or not ret.radarUnavailable:
|
2023-09-27 15:45:31 -07:00
|
|
|
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_FORD_LONG_CONTROL
|
|
|
|
ret.openpilotLongitudinalControl = True
|
|
|
|
|
2024-06-11 01:36:40 +00:00
|
|
|
if ret.flags & FordFlags.CANFD:
|
2023-09-27 15:45:31 -07:00
|
|
|
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_FORD_CANFD
|
|
|
|
else:
|
2024-06-11 01:36:40 +00:00
|
|
|
# Lock out if the car does not have needed lateral and longitudinal control APIs.
|
|
|
|
# Note that we also check CAN for adaptive cruise, but no known signal for LCA exists
|
|
|
|
pscm_config = next((fw for fw in car_fw if fw.ecu == Ecu.eps and b'\x22\xDE\x01' in fw.request), None)
|
|
|
|
if pscm_config:
|
|
|
|
if len(pscm_config.fwVersion) != 24:
|
|
|
|
ret.dashcamOnly = True
|
|
|
|
else:
|
|
|
|
config_tja = pscm_config.fwVersion[7] # Traffic Jam Assist
|
|
|
|
config_lca = pscm_config.fwVersion[8] # Lane Centering Assist
|
|
|
|
if config_tja != 0xFF or config_lca != 0xFF:
|
|
|
|
ret.dashcamOnly = True
|
2023-09-27 15:45:31 -07:00
|
|
|
|
|
|
|
# Auto Transmission: 0x732 ECU or Gear_Shift_by_Wire_FD1
|
|
|
|
found_ecus = [fw.ecu for fw in car_fw]
|
|
|
|
if Ecu.shiftByWire in found_ecus or 0x5A in fingerprint[CAN.main] or docs:
|
|
|
|
ret.transmissionType = TransmissionType.automatic
|
|
|
|
else:
|
|
|
|
ret.transmissionType = TransmissionType.manual
|
|
|
|
ret.minEnableSpeed = 20.0 * CV.MPH_TO_MS
|
|
|
|
|
|
|
|
# BSM: Side_Detect_L_Stat, Side_Detect_R_Stat
|
|
|
|
# TODO: detect bsm in car_fw?
|
|
|
|
ret.enableBsm = 0x3A6 in fingerprint[CAN.main] and 0x3A7 in fingerprint[CAN.main]
|
|
|
|
|
|
|
|
# LCA can steer down to zero
|
|
|
|
ret.minSteerSpeed = 0.
|
|
|
|
|
|
|
|
ret.autoResumeSng = ret.minEnableSpeed == -1.
|
|
|
|
ret.centerToFront = ret.wheelbase * 0.44
|
|
|
|
return ret
|