2021-06-23 14:56:59 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
from cereal import car
|
2021-11-18 13:57:12 +01:00
|
|
|
from panda import Panda
|
2024-03-06 21:14:48 +01:00
|
|
|
from openpilot.selfdrive.car.tesla.values import CANBUS, CAR
|
2023-08-20 20:49:55 -07:00
|
|
|
from openpilot.selfdrive.car import get_safety_config
|
|
|
|
|
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
|
2021-06-23 14:56:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CarInterface(CarInterfaceBase):
|
|
|
|
|
@staticmethod
|
2023-04-18 12:22:22 -07:00
|
|
|
def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
|
2021-06-23 14:56:59 +02:00
|
|
|
ret.carName = "tesla"
|
|
|
|
|
|
|
|
|
|
# There is no safe way to do steer blending with user torque,
|
|
|
|
|
# so the steering behaves like autopilot. This is not
|
|
|
|
|
# how openpilot should be, hence dashcamOnly
|
|
|
|
|
ret.dashcamOnly = True
|
|
|
|
|
|
|
|
|
|
ret.steerControlType = car.CarParams.SteerControlType.angle
|
2021-11-18 13:57:12 +01:00
|
|
|
|
|
|
|
|
# Set kP and kI to 0 over the whole speed range to have the planner accel as actuator command
|
|
|
|
|
ret.longitudinalTuning.kpBP = [0]
|
|
|
|
|
ret.longitudinalTuning.kpV = [0]
|
|
|
|
|
ret.longitudinalTuning.kiBP = [0]
|
|
|
|
|
ret.longitudinalTuning.kiV = [0]
|
|
|
|
|
ret.longitudinalActuatorDelayUpperBound = 0.5 # s
|
|
|
|
|
ret.radarTimeStep = (1.0 / 8) # 8Hz
|
|
|
|
|
|
|
|
|
|
# Check if we have messages on an auxiliary panda, and that 0x2bf (DAS_control) is present on the AP powertrain bus
|
|
|
|
|
# If so, we assume that it is connected to the longitudinal harness.
|
2024-03-19 20:29:50 -04:00
|
|
|
flags = (Panda.FLAG_TESLA_RAVEN if candidate == CAR.TESLA_MODELS_RAVEN else 0)
|
2021-11-18 13:57:12 +01:00
|
|
|
if (CANBUS.autopilot_powertrain in fingerprint.keys()) and (0x2bf in fingerprint[CANBUS.autopilot_powertrain].keys()):
|
|
|
|
|
ret.openpilotLongitudinalControl = True
|
2024-03-06 21:14:48 +01:00
|
|
|
flags |= Panda.FLAG_TESLA_LONG_CONTROL
|
2021-11-18 13:57:12 +01:00
|
|
|
ret.safetyConfigs = [
|
2024-03-06 21:14:48 +01:00
|
|
|
get_safety_config(car.CarParams.SafetyModel.tesla, flags),
|
|
|
|
|
get_safety_config(car.CarParams.SafetyModel.tesla, flags | Panda.FLAG_TESLA_POWERTRAIN),
|
2021-11-18 13:57:12 +01:00
|
|
|
]
|
|
|
|
|
else:
|
|
|
|
|
ret.openpilotLongitudinalControl = False
|
2024-03-06 21:14:48 +01:00
|
|
|
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.tesla, flags)]
|
2021-06-23 14:56:59 +02:00
|
|
|
|
2022-01-26 08:10:41 -08:00
|
|
|
ret.steerLimitTimer = 1.0
|
2022-02-23 16:03:31 +01:00
|
|
|
ret.steerActuatorDelay = 0.25
|
2021-06-23 14:56:59 +02:00
|
|
|
return ret
|
|
|
|
|
|
2022-04-12 22:58:34 -07:00
|
|
|
def _update(self, c):
|
2021-06-23 14:56:59 +02:00
|
|
|
ret = self.CS.update(self.cp, self.cp_cam)
|
|
|
|
|
|
2022-04-12 22:58:34 -07:00
|
|
|
ret.events = self.create_common_events(ret).to_msg()
|
2021-06-23 14:56:59 +02:00
|
|
|
|
2022-04-12 22:58:34 -07:00
|
|
|
return ret
|