You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
4.8 KiB
105 lines
4.8 KiB
2 months ago
|
from opendbc.car import get_safety_config, structs
|
||
|
from opendbc.car.disable_ecu import disable_ecu
|
||
|
from opendbc.car.interfaces import CarInterfaceBase
|
||
|
from opendbc.car.subaru.carcontroller import CarController
|
||
|
from opendbc.car.subaru.carstate import CarState
|
||
|
from opendbc.car.subaru.values import CAR, GLOBAL_ES_ADDR, SubaruFlags, SubaruSafetyFlags
|
||
2 years ago
|
|
||
|
|
||
|
class CarInterface(CarInterfaceBase):
|
||
2 months ago
|
CarState = CarState
|
||
|
CarController = CarController
|
||
2 years ago
|
|
||
|
@staticmethod
|
||
2 months ago
|
def _get_params(ret: structs.CarParams, candidate: CAR, fingerprint, car_fw, experimental_long, docs) -> structs.CarParams:
|
||
|
ret.brand = "subaru"
|
||
2 years ago
|
ret.radarUnavailable = True
|
||
1 year ago
|
# for HYBRID CARS to be upstreamed, we need:
|
||
|
# - replacement for ES_Distance so we can cancel the cruise control
|
||
|
# - to find the Cruise_Activated bit from the car
|
||
|
# - proper panda safety setup (use the correct cruise_activated bit, throttle from Throttle_Hybrid, etc)
|
||
11 months ago
|
ret.dashcamOnly = bool(ret.flags & (SubaruFlags.PREGLOBAL | SubaruFlags.LKAS_ANGLE | SubaruFlags.HYBRID))
|
||
2 years ago
|
ret.autoResumeSng = False
|
||
|
|
||
|
# Detect infotainment message sent from the camera
|
||
11 months ago
|
if not (ret.flags & SubaruFlags.PREGLOBAL) and 0x323 in fingerprint[2]:
|
||
2 years ago
|
ret.flags |= SubaruFlags.SEND_INFOTAINMENT.value
|
||
|
|
||
11 months ago
|
if ret.flags & SubaruFlags.PREGLOBAL:
|
||
2 years ago
|
ret.enableBsm = 0x25c in fingerprint[0]
|
||
2 months ago
|
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.subaruPreglobal)]
|
||
2 years ago
|
else:
|
||
|
ret.enableBsm = 0x228 in fingerprint[0]
|
||
2 months ago
|
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.subaru)]
|
||
11 months ago
|
if ret.flags & SubaruFlags.GLOBAL_GEN2:
|
||
2 months ago
|
ret.safetyConfigs[0].safetyParam |= SubaruSafetyFlags.GEN2.value
|
||
2 years ago
|
|
||
|
ret.steerLimitTimer = 0.4
|
||
|
ret.steerActuatorDelay = 0.1
|
||
|
|
||
11 months ago
|
if ret.flags & SubaruFlags.LKAS_ANGLE:
|
||
2 months ago
|
ret.steerControlType = structs.CarParams.SteerControlType.angle
|
||
1 year ago
|
else:
|
||
|
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
|
||
|
|
||
11 months ago
|
if candidate in (CAR.SUBARU_ASCENT, CAR.SUBARU_ASCENT_2023):
|
||
|
ret.steerActuatorDelay = 0.3 # end-to-end angle controller
|
||
2 years ago
|
ret.lateralTuning.init('pid')
|
||
|
ret.lateralTuning.pid.kf = 0.00003
|
||
|
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0., 20.], [0., 20.]]
|
||
|
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.0025, 0.1], [0.00025, 0.01]]
|
||
|
|
||
11 months ago
|
elif candidate == CAR.SUBARU_IMPREZA:
|
||
|
ret.steerActuatorDelay = 0.4 # end-to-end angle controller
|
||
2 years ago
|
ret.lateralTuning.init('pid')
|
||
|
ret.lateralTuning.pid.kf = 0.00005
|
||
|
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0., 20.], [0., 20.]]
|
||
|
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2, 0.3], [0.02, 0.03]]
|
||
|
|
||
11 months ago
|
elif candidate == CAR.SUBARU_IMPREZA_2020:
|
||
2 years ago
|
ret.lateralTuning.init('pid')
|
||
|
ret.lateralTuning.pid.kf = 0.00005
|
||
|
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0., 14., 23.], [0., 14., 23.]]
|
||
|
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.045, 0.042, 0.20], [0.04, 0.035, 0.045]]
|
||
|
|
||
11 months ago
|
elif candidate == CAR.SUBARU_CROSSTREK_HYBRID:
|
||
1 year ago
|
ret.steerActuatorDelay = 0.1
|
||
|
|
||
11 months ago
|
elif candidate in (CAR.SUBARU_FORESTER, CAR.SUBARU_FORESTER_2022, CAR.SUBARU_FORESTER_HYBRID):
|
||
2 years ago
|
ret.lateralTuning.init('pid')
|
||
|
ret.lateralTuning.pid.kf = 0.000038
|
||
|
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0., 14., 23.], [0., 14., 23.]]
|
||
|
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.01, 0.065, 0.2], [0.001, 0.015, 0.025]]
|
||
|
|
||
11 months ago
|
elif candidate in (CAR.SUBARU_OUTBACK, CAR.SUBARU_LEGACY, CAR.SUBARU_OUTBACK_2023):
|
||
2 years ago
|
ret.steerActuatorDelay = 0.1
|
||
|
|
||
11 months ago
|
elif candidate in (CAR.SUBARU_FORESTER_PREGLOBAL, CAR.SUBARU_OUTBACK_PREGLOBAL_2018):
|
||
2 months ago
|
# Outback 2018-2019 and Forester have reversed driver torque signal
|
||
|
ret.safetyConfigs[0].safetyParam = SubaruSafetyFlags.PREGLOBAL_REVERSED_DRIVER_TORQUE.value
|
||
11 months ago
|
|
||
|
elif candidate == CAR.SUBARU_LEGACY_PREGLOBAL:
|
||
2 years ago
|
ret.steerActuatorDelay = 0.15
|
||
|
|
||
11 months ago
|
elif candidate == CAR.SUBARU_OUTBACK_PREGLOBAL:
|
||
|
pass
|
||
2 years ago
|
else:
|
||
|
raise ValueError(f"unknown car: {candidate}")
|
||
|
|
||
11 months ago
|
ret.experimentalLongitudinalAvailable = not (ret.flags & (SubaruFlags.GLOBAL_GEN2 | SubaruFlags.PREGLOBAL |
|
||
|
SubaruFlags.LKAS_ANGLE | SubaruFlags.HYBRID))
|
||
1 year ago
|
ret.openpilotLongitudinalControl = experimental_long and ret.experimentalLongitudinalAvailable
|
||
|
|
||
11 months ago
|
if ret.flags & SubaruFlags.GLOBAL_GEN2 and ret.openpilotLongitudinalControl:
|
||
1 year ago
|
ret.flags |= SubaruFlags.DISABLE_EYESIGHT.value
|
||
1 year ago
|
|
||
|
if ret.openpilotLongitudinalControl:
|
||
2 months ago
|
ret.safetyConfigs[0].safetyParam |= SubaruSafetyFlags.LONG.value
|
||
2 years ago
|
|
||
|
return ret
|
||
|
|
||
1 year ago
|
@staticmethod
|
||
2 months ago
|
def init(CP, can_recv, can_send):
|
||
1 year ago
|
if CP.flags & SubaruFlags.DISABLE_EYESIGHT:
|
||
2 months ago
|
disable_ecu(can_recv, can_send, bus=2, addr=GLOBAL_ES_ADDR, com_cont_req=b'\x28\x03\x01')
|