dragonpilot - 基於 openpilot 的開源駕駛輔助系統
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.

123 lines
5.0 KiB

5 years ago
from cereal import car
from panda import Panda
from openpilot.selfdrive.car import get_safety_config
from openpilot.selfdrive.car.values import Platform
from openpilot.selfdrive.car.disable_ecu import disable_ecu
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.selfdrive.car.subaru.values import CAR, GLOBAL_ES_ADDR, LKAS_ANGLE, GLOBAL_GEN2, PREGLOBAL_CARS, HYBRID_CARS, SubaruFlags
5 years ago
class CarInterface(CarInterfaceBase):
@staticmethod
def _get_params(ret, candidate: Platform, fingerprint, car_fw, experimental_long, docs):
5 years ago
ret.carName = "subaru"
ret.radarUnavailable = True
# 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)
ret.dashcamOnly = candidate in (PREGLOBAL_CARS | LKAS_ANGLE | HYBRID_CARS)
ret.autoResumeSng = False
# Detect infotainment message sent from the camera
if candidate not in PREGLOBAL_CARS and 0x323 in fingerprint[2]:
ret.flags |= SubaruFlags.SEND_INFOTAINMENT.value
if candidate in PREGLOBAL_CARS:
ret.enableBsm = 0x25c in fingerprint[0]
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.subaruPreglobal)]
else:
ret.enableBsm = 0x228 in fingerprint[0]
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.subaru)]
if candidate in GLOBAL_GEN2:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_SUBARU_GEN2
5 years ago
ret.steerLimitTimer = 0.4
ret.steerActuatorDelay = 0.1
if candidate in LKAS_ANGLE:
ret.steerControlType = car.CarParams.SteerControlType.angle
else:
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
5 years ago
ret.centerToFront = ret.wheelbase * 0.5
if candidate in (CAR.ASCENT, CAR.ASCENT_2023):
ret.steerActuatorDelay = 0.3 # end-to-end angle controller
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]]
elif candidate == CAR.IMPREZA:
5 years ago
ret.steerActuatorDelay = 0.4 # end-to-end angle controller
ret.lateralTuning.init('pid')
5 years ago
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]]
elif candidate == CAR.IMPREZA_2020:
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]]
elif candidate == CAR.CROSSTREK_HYBRID:
ret.steerActuatorDelay = 0.1
elif candidate in (CAR.FORESTER, CAR.FORESTER_2022, CAR.FORESTER_HYBRID):
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]]
elif candidate in (CAR.OUTBACK, CAR.LEGACY, CAR.OUTBACK_2023):
ret.steerActuatorDelay = 0.1
elif candidate in (CAR.FORESTER_PREGLOBAL, CAR.OUTBACK_PREGLOBAL_2018):
ret.safetyConfigs[0].safetyParam = Panda.FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE # Outback 2018-2019 and Forester have reversed driver torque signal
elif candidate == CAR.LEGACY_PREGLOBAL:
ret.steerActuatorDelay = 0.15
elif candidate == CAR.OUTBACK_PREGLOBAL:
pass
else:
raise ValueError(f"unknown car: {candidate}")
ret.experimentalLongitudinalAvailable = candidate not in (GLOBAL_GEN2 | PREGLOBAL_CARS | LKAS_ANGLE | HYBRID_CARS)
Subaru: Global gen1 experimental longitudinal (#28872) * Add longitudinal support for Subaru Crosstrek and Impreza * Update experimentalLongitudinalAvailable check * Update supported cars list * bump panda * Remove/rename es_lkas_msg to es_lkas_state_msg * Use stockAeb for AEB passthrough * bump panda * bump panda * remove stockFcw from stockAeb * Subaru: Add FCW_Cont_Beep to stockFcw signals * bump panda * bump panda * update poetry deps: shellingham * bump panda * bump panda * Revert "update poetry deps: shellingham" This reverts commit 6e9b20964890c8a5c416a17b8aaad4cc16fddcfc. * Merge fixes * bump panda * bump panda * update supported cars list * dont use counters for long control * fix unittests * submodules update * only soft disable in long control * use common functions and cleanup * apply hystersis correctly * move to comma repo * use CanBus * cleanup * explicit copy * behind a flag * remove unrequired rpm checks * add comment * fix flag issue * we still need to check rpm * update docs * enable long for a test route * unit tests * inactive throttle fix * Update subarucan.py * Update carcontroller.py * Update carcontroller.py * inactive throttle fix * Delete settings * fix rate limit * bump submodules * bump panda * bump panda * bump panda * bump panda * simplify initial implementation, remove AEB * reduce initial complexity by not intercepting cruisecontrol or brake_status * fix fwd hook test * show pcb off warning * cleanup and setup for tuning * fix sumobuldes * revert unrelated changes * only whats required * only whats required * clean that up * better comments * behind the flag for now * comments and minimize diff * align stuff * cleanup for PR * apply review suggestions --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee>
2 years ago
ret.openpilotLongitudinalControl = experimental_long and ret.experimentalLongitudinalAvailable
if candidate in GLOBAL_GEN2 and ret.openpilotLongitudinalControl:
ret.flags |= SubaruFlags.DISABLE_EYESIGHT.value
Subaru: Global gen1 experimental longitudinal (#28872) * Add longitudinal support for Subaru Crosstrek and Impreza * Update experimentalLongitudinalAvailable check * Update supported cars list * bump panda * Remove/rename es_lkas_msg to es_lkas_state_msg * Use stockAeb for AEB passthrough * bump panda * bump panda * remove stockFcw from stockAeb * Subaru: Add FCW_Cont_Beep to stockFcw signals * bump panda * bump panda * update poetry deps: shellingham * bump panda * bump panda * Revert "update poetry deps: shellingham" This reverts commit 6e9b20964890c8a5c416a17b8aaad4cc16fddcfc. * Merge fixes * bump panda * bump panda * update supported cars list * dont use counters for long control * fix unittests * submodules update * only soft disable in long control * use common functions and cleanup * apply hystersis correctly * move to comma repo * use CanBus * cleanup * explicit copy * behind a flag * remove unrequired rpm checks * add comment * fix flag issue * we still need to check rpm * update docs * enable long for a test route * unit tests * inactive throttle fix * Update subarucan.py * Update carcontroller.py * Update carcontroller.py * inactive throttle fix * Delete settings * fix rate limit * bump submodules * bump panda * bump panda * bump panda * bump panda * simplify initial implementation, remove AEB * reduce initial complexity by not intercepting cruisecontrol or brake_status * fix fwd hook test * show pcb off warning * cleanup and setup for tuning * fix sumobuldes * revert unrelated changes * only whats required * only whats required * clean that up * better comments * behind the flag for now * comments and minimize diff * align stuff * cleanup for PR * apply review suggestions --------- Co-authored-by: Martin Lillepuu <martin@mlp.ee>
2 years ago
if ret.openpilotLongitudinalControl:
ret.longitudinalTuning.kpBP = [0., 5., 35.]
ret.longitudinalTuning.kpV = [0.8, 1.0, 1.5]
ret.longitudinalTuning.kiBP = [0., 35.]
ret.longitudinalTuning.kiV = [0.54, 0.36]
ret.stoppingControl = True
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_SUBARU_LONG
5 years ago
return ret
# returns a car.CarState
def _update(self, c):
5 years ago
ret = self.CS.update(self.cp, self.cp_cam, self.cp_body)
5 years ago
ret.events = self.create_common_events(ret).to_msg()
5 years ago
return ret
5 years ago
@staticmethod
def init(CP, logcan, sendcan):
if CP.flags & SubaruFlags.DISABLE_EYESIGHT:
disable_ecu(logcan, sendcan, bus=2, addr=GLOBAL_ES_ADDR, com_cont_req=b'\x28\x03\x01')
def apply(self, c, now_nanos):
return self.CC.update(c, self.CS, now_nanos)