openpilot v0.9.6 release
date: 2024-01-12T10:13:37 master commit: ba792d576a49a0899b88a753fa1c52956bedf9e6
This commit is contained in:
0
selfdrive/car/tesla/__init__.py
Normal file
0
selfdrive/car/tesla/__init__.py
Normal file
66
selfdrive/car/tesla/carcontroller.py
Normal file
66
selfdrive/car/tesla/carcontroller.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from openpilot.common.numpy_fast import clip
|
||||
from opendbc.can.packer import CANPacker
|
||||
from openpilot.selfdrive.car import apply_std_steer_angle_limits
|
||||
from openpilot.selfdrive.car.tesla.teslacan import TeslaCAN
|
||||
from openpilot.selfdrive.car.tesla.values import DBC, CANBUS, CarControllerParams
|
||||
|
||||
|
||||
class CarController:
|
||||
def __init__(self, dbc_name, CP, VM):
|
||||
self.CP = CP
|
||||
self.frame = 0
|
||||
self.apply_angle_last = 0
|
||||
self.packer = CANPacker(dbc_name)
|
||||
self.pt_packer = CANPacker(DBC[CP.carFingerprint]['pt'])
|
||||
self.tesla_can = TeslaCAN(self.packer, self.pt_packer)
|
||||
|
||||
def update(self, CC, CS, now_nanos):
|
||||
actuators = CC.actuators
|
||||
pcm_cancel_cmd = CC.cruiseControl.cancel
|
||||
|
||||
can_sends = []
|
||||
|
||||
# Temp disable steering on a hands_on_fault, and allow for user override
|
||||
hands_on_fault = CS.steer_warning == "EAC_ERROR_HANDS_ON" and CS.hands_on_level >= 3
|
||||
lkas_enabled = CC.latActive and not hands_on_fault
|
||||
|
||||
if self.frame % 2 == 0:
|
||||
if lkas_enabled:
|
||||
# Angular rate limit based on speed
|
||||
apply_angle = apply_std_steer_angle_limits(actuators.steeringAngleDeg, self.apply_angle_last, CS.out.vEgo, CarControllerParams)
|
||||
|
||||
# To not fault the EPS
|
||||
apply_angle = clip(apply_angle, CS.out.steeringAngleDeg - 20, CS.out.steeringAngleDeg + 20)
|
||||
else:
|
||||
apply_angle = CS.out.steeringAngleDeg
|
||||
|
||||
self.apply_angle_last = apply_angle
|
||||
can_sends.append(self.tesla_can.create_steering_control(apply_angle, lkas_enabled, (self.frame // 2) % 16))
|
||||
|
||||
# Longitudinal control (in sync with stock message, about 40Hz)
|
||||
if self.CP.openpilotLongitudinalControl:
|
||||
target_accel = actuators.accel
|
||||
target_speed = max(CS.out.vEgo + (target_accel * CarControllerParams.ACCEL_TO_SPEED_MULTIPLIER), 0)
|
||||
max_accel = 0 if target_accel < 0 else target_accel
|
||||
min_accel = 0 if target_accel > 0 else target_accel
|
||||
|
||||
while len(CS.das_control_counters) > 0:
|
||||
can_sends.extend(self.tesla_can.create_longitudinal_commands(CS.acc_state, target_speed, min_accel, max_accel, CS.das_control_counters.popleft()))
|
||||
|
||||
# Cancel on user steering override, since there is no steering torque blending
|
||||
if hands_on_fault:
|
||||
pcm_cancel_cmd = True
|
||||
|
||||
if self.frame % 10 == 0 and pcm_cancel_cmd:
|
||||
# Spam every possible counter value, otherwise it might not be accepted
|
||||
for counter in range(16):
|
||||
can_sends.append(self.tesla_can.create_action_request(CS.msg_stw_actn_req, pcm_cancel_cmd, CANBUS.chassis, counter))
|
||||
can_sends.append(self.tesla_can.create_action_request(CS.msg_stw_actn_req, pcm_cancel_cmd, CANBUS.autopilot_chassis, counter))
|
||||
|
||||
# TODO: HUD control
|
||||
|
||||
new_actuators = actuators.copy()
|
||||
new_actuators.steeringAngleDeg = self.apply_angle_last
|
||||
|
||||
self.frame += 1
|
||||
return new_actuators, can_sends
|
||||
125
selfdrive/car/tesla/carstate.py
Normal file
125
selfdrive/car/tesla/carstate.py
Normal file
@@ -0,0 +1,125 @@
|
||||
import copy
|
||||
from collections import deque
|
||||
from cereal import car
|
||||
from openpilot.common.conversions import Conversions as CV
|
||||
from openpilot.selfdrive.car.tesla.values import DBC, CANBUS, GEAR_MAP, DOORS, BUTTONS
|
||||
from openpilot.selfdrive.car.interfaces import CarStateBase
|
||||
from opendbc.can.parser import CANParser
|
||||
from opendbc.can.can_define import CANDefine
|
||||
|
||||
class CarState(CarStateBase):
|
||||
def __init__(self, CP):
|
||||
super().__init__(CP)
|
||||
self.button_states = {button.event_type: False for button in BUTTONS}
|
||||
self.can_define = CANDefine(DBC[CP.carFingerprint]['chassis'])
|
||||
|
||||
# Needed by carcontroller
|
||||
self.msg_stw_actn_req = None
|
||||
self.hands_on_level = 0
|
||||
self.steer_warning = None
|
||||
self.acc_state = 0
|
||||
self.das_control_counters = deque(maxlen=32)
|
||||
|
||||
def update(self, cp, cp_cam):
|
||||
ret = car.CarState.new_message()
|
||||
|
||||
# Vehicle speed
|
||||
ret.vEgoRaw = cp.vl["ESP_B"]["ESP_vehicleSpeed"] * CV.KPH_TO_MS
|
||||
ret.vEgo, ret.aEgo = self.update_speed_kf(ret.vEgoRaw)
|
||||
ret.standstill = (ret.vEgo < 0.1)
|
||||
|
||||
# Gas pedal
|
||||
ret.gas = cp.vl["DI_torque1"]["DI_pedalPos"] / 100.0
|
||||
ret.gasPressed = (ret.gas > 0)
|
||||
|
||||
# Brake pedal
|
||||
ret.brake = 0
|
||||
ret.brakePressed = bool(cp.vl["BrakeMessage"]["driverBrakeStatus"] != 1)
|
||||
|
||||
# Steering wheel
|
||||
self.hands_on_level = cp.vl["EPAS_sysStatus"]["EPAS_handsOnLevel"]
|
||||
self.steer_warning = self.can_define.dv["EPAS_sysStatus"]["EPAS_eacErrorCode"].get(int(cp.vl["EPAS_sysStatus"]["EPAS_eacErrorCode"]), None)
|
||||
steer_status = self.can_define.dv["EPAS_sysStatus"]["EPAS_eacStatus"].get(int(cp.vl["EPAS_sysStatus"]["EPAS_eacStatus"]), None)
|
||||
|
||||
ret.steeringAngleDeg = -cp.vl["EPAS_sysStatus"]["EPAS_internalSAS"]
|
||||
ret.steeringRateDeg = -cp.vl["STW_ANGLHP_STAT"]["StW_AnglHP_Spd"] # This is from a different angle sensor, and at different rate
|
||||
ret.steeringTorque = -cp.vl["EPAS_sysStatus"]["EPAS_torsionBarTorque"]
|
||||
ret.steeringPressed = (self.hands_on_level > 0)
|
||||
ret.steerFaultPermanent = steer_status == "EAC_FAULT"
|
||||
ret.steerFaultTemporary = (self.steer_warning not in ("EAC_ERROR_IDLE", "EAC_ERROR_HANDS_ON"))
|
||||
|
||||
# Cruise state
|
||||
cruise_state = self.can_define.dv["DI_state"]["DI_cruiseState"].get(int(cp.vl["DI_state"]["DI_cruiseState"]), None)
|
||||
speed_units = self.can_define.dv["DI_state"]["DI_speedUnits"].get(int(cp.vl["DI_state"]["DI_speedUnits"]), None)
|
||||
|
||||
acc_enabled = (cruise_state in ("ENABLED", "STANDSTILL", "OVERRIDE", "PRE_FAULT", "PRE_CANCEL"))
|
||||
|
||||
ret.cruiseState.enabled = acc_enabled
|
||||
if speed_units == "KPH":
|
||||
ret.cruiseState.speed = cp.vl["DI_state"]["DI_digitalSpeed"] * CV.KPH_TO_MS
|
||||
elif speed_units == "MPH":
|
||||
ret.cruiseState.speed = cp.vl["DI_state"]["DI_digitalSpeed"] * CV.MPH_TO_MS
|
||||
ret.cruiseState.available = ((cruise_state == "STANDBY") or ret.cruiseState.enabled)
|
||||
ret.cruiseState.standstill = False # This needs to be false, since we can resume from stop without sending anything special
|
||||
|
||||
# Gear
|
||||
ret.gearShifter = GEAR_MAP[self.can_define.dv["DI_torque2"]["DI_gear"].get(int(cp.vl["DI_torque2"]["DI_gear"]), "DI_GEAR_INVALID")]
|
||||
|
||||
# Buttons
|
||||
buttonEvents = []
|
||||
for button in BUTTONS:
|
||||
state = (cp.vl[button.can_addr][button.can_msg] in button.values)
|
||||
if self.button_states[button.event_type] != state:
|
||||
event = car.CarState.ButtonEvent.new_message()
|
||||
event.type = button.event_type
|
||||
event.pressed = state
|
||||
buttonEvents.append(event)
|
||||
self.button_states[button.event_type] = state
|
||||
ret.buttonEvents = buttonEvents
|
||||
|
||||
# Doors
|
||||
ret.doorOpen = any((self.can_define.dv["GTW_carState"][door].get(int(cp.vl["GTW_carState"][door]), "OPEN") == "OPEN") for door in DOORS)
|
||||
|
||||
# Blinkers
|
||||
ret.leftBlinker = (cp.vl["GTW_carState"]["BC_indicatorLStatus"] == 1)
|
||||
ret.rightBlinker = (cp.vl["GTW_carState"]["BC_indicatorRStatus"] == 1)
|
||||
|
||||
# Seatbelt
|
||||
ret.seatbeltUnlatched = (cp.vl["SDM1"]["SDM_bcklDrivStatus"] != 1)
|
||||
|
||||
# TODO: blindspot
|
||||
|
||||
# AEB
|
||||
ret.stockAeb = (cp_cam.vl["DAS_control"]["DAS_aebEvent"] == 1)
|
||||
|
||||
# Messages needed by carcontroller
|
||||
self.msg_stw_actn_req = copy.copy(cp.vl["STW_ACTN_RQ"])
|
||||
self.acc_state = cp_cam.vl["DAS_control"]["DAS_accState"]
|
||||
self.das_control_counters.extend(cp_cam.vl_all["DAS_control"]["DAS_controlCounter"])
|
||||
|
||||
return ret
|
||||
|
||||
@staticmethod
|
||||
def get_can_parser(CP):
|
||||
messages = [
|
||||
# sig_address, frequency
|
||||
("ESP_B", 50),
|
||||
("DI_torque1", 100),
|
||||
("DI_torque2", 100),
|
||||
("STW_ANGLHP_STAT", 100),
|
||||
("EPAS_sysStatus", 25),
|
||||
("DI_state", 10),
|
||||
("STW_ACTN_RQ", 10),
|
||||
("GTW_carState", 10),
|
||||
("SDM1", 10),
|
||||
("BrakeMessage", 50),
|
||||
]
|
||||
return CANParser(DBC[CP.carFingerprint]['chassis'], messages, CANBUS.chassis)
|
||||
|
||||
@staticmethod
|
||||
def get_cam_can_parser(CP):
|
||||
messages = [
|
||||
# sig_address, frequency
|
||||
("DAS_control", 40),
|
||||
]
|
||||
return CANParser(DBC[CP.carFingerprint]['chassis'], messages, CANBUS.autopilot_chassis)
|
||||
28
selfdrive/car/tesla/fingerprints.py
Normal file
28
selfdrive/car/tesla/fingerprints.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# ruff: noqa: E501
|
||||
from cereal import car
|
||||
from openpilot.selfdrive.car.tesla.values import CAR
|
||||
|
||||
Ecu = car.CarParams.Ecu
|
||||
|
||||
FINGERPRINTS = {
|
||||
CAR.AP1_MODELS: [{
|
||||
1: 8, 3: 8, 14: 8, 21: 4, 69: 8, 109: 4, 257: 3, 264: 8, 267: 5, 277: 6, 280: 6, 283: 5, 293: 4, 296: 4, 309: 5, 325: 8, 328: 5, 336: 8, 341: 8, 360: 7, 373: 8, 389: 8, 415: 8, 513: 5, 516: 8, 520: 4, 522: 8, 524: 8, 526: 8, 532: 3, 536: 8, 537: 3, 542: 8, 551: 5, 552: 2, 556: 8, 558: 8, 568: 8, 569: 8, 574: 8, 577: 8, 582: 5, 584: 4, 585: 8, 590: 8, 606: 8, 622: 8, 627: 6, 638: 8, 641: 8, 643: 8, 660: 5, 693: 8, 696: 8, 697: 8, 712: 8, 728: 8, 744: 8, 760: 8, 772: 8, 775: 8, 776: 8, 777: 8, 778: 8, 782: 8, 788: 8, 791: 8, 792: 8, 796: 2, 797: 8, 798: 6, 799: 8, 804: 8, 805: 8, 807: 8, 808: 1, 809: 8, 812: 8, 813: 8, 814: 5, 815: 8, 820: 8, 823: 8, 824: 8, 829: 8, 830: 5, 836: 8, 840: 8, 841: 8, 845: 8, 846: 5, 852: 8, 856: 4, 857: 6, 861: 8, 862: 5, 872: 8, 873: 8, 877: 8, 878: 8, 879: 8, 880: 8, 884: 8, 888: 8, 889: 8, 893: 8, 896: 8, 901: 6, 904: 3, 905: 8, 908: 2, 909: 8, 920: 8, 921: 8, 925: 4, 936: 8, 937: 8, 941: 8, 949: 8, 952: 8, 953: 6, 957: 8, 968: 8, 973: 8, 984: 8, 987: 8, 989: 8, 990: 8, 1000: 8, 1001: 8, 1006: 8, 1016: 8, 1026: 8, 1028: 8, 1029: 8, 1030: 8, 1032: 1, 1033: 1, 1034: 8, 1048: 1, 1064: 8, 1070: 8, 1080: 8, 1160: 4, 1281: 8, 1329: 8, 1332: 8, 1335: 8, 1337: 8, 1368: 8, 1412: 8, 1436: 8, 1465: 8, 1476: 8, 1497: 8, 1524: 8, 1527: 8, 1601: 8, 1605: 8, 1611: 8, 1614: 8, 1617: 8, 1621: 8, 1627: 8, 1630: 8, 1800: 4, 1804: 8, 1812: 8, 1815: 8, 1816: 8, 1828: 8, 1831: 8, 1832: 8, 1840: 8, 1848: 8, 1864: 8, 1880: 8, 1892: 8, 1896: 8, 1912: 8, 1960: 8, 1992: 8, 2008: 3, 2043: 5, 2045: 4
|
||||
}],
|
||||
}
|
||||
|
||||
FW_VERSIONS = {
|
||||
CAR.AP2_MODELS: {
|
||||
(Ecu.adas, 0x649, None): [
|
||||
b'\x01\x00\x8b\x07\x01\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11',
|
||||
],
|
||||
(Ecu.electricBrakeBooster, 0x64d, None): [
|
||||
b'1037123-00-A',
|
||||
],
|
||||
(Ecu.fwdRadar, 0x671, None): [
|
||||
b'\x01\x00W\x00\x00\x00\x07\x00\x00\x00\x00\x08\x01\x00\x00\x00\x07\xff\xfe',
|
||||
],
|
||||
(Ecu.eps, 0x730, None): [
|
||||
b'\x10#\x01',
|
||||
],
|
||||
},
|
||||
}
|
||||
62
selfdrive/car/tesla/interface.py
Executable file
62
selfdrive/car/tesla/interface.py
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
from cereal import car
|
||||
from panda import Panda
|
||||
from openpilot.selfdrive.car.tesla.values import CANBUS, CAR
|
||||
from openpilot.selfdrive.car import get_safety_config
|
||||
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
|
||||
|
||||
|
||||
class CarInterface(CarInterfaceBase):
|
||||
@staticmethod
|
||||
def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
|
||||
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
|
||||
|
||||
# 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.
|
||||
if (CANBUS.autopilot_powertrain in fingerprint.keys()) and (0x2bf in fingerprint[CANBUS.autopilot_powertrain].keys()):
|
||||
ret.openpilotLongitudinalControl = True
|
||||
ret.safetyConfigs = [
|
||||
get_safety_config(car.CarParams.SafetyModel.tesla, Panda.FLAG_TESLA_LONG_CONTROL),
|
||||
get_safety_config(car.CarParams.SafetyModel.tesla, Panda.FLAG_TESLA_LONG_CONTROL | Panda.FLAG_TESLA_POWERTRAIN),
|
||||
]
|
||||
else:
|
||||
ret.openpilotLongitudinalControl = False
|
||||
ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.tesla, 0)]
|
||||
|
||||
ret.steerLimitTimer = 1.0
|
||||
ret.steerActuatorDelay = 0.25
|
||||
|
||||
if candidate in (CAR.AP2_MODELS, CAR.AP1_MODELS):
|
||||
ret.mass = 2100.
|
||||
ret.wheelbase = 2.959
|
||||
ret.centerToFront = ret.wheelbase * 0.5
|
||||
ret.steerRatio = 15.0
|
||||
else:
|
||||
raise ValueError(f"Unsupported car: {candidate}")
|
||||
|
||||
return ret
|
||||
|
||||
def _update(self, c):
|
||||
ret = self.CS.update(self.cp, self.cp_cam)
|
||||
|
||||
ret.events = self.create_common_events(ret).to_msg()
|
||||
|
||||
return ret
|
||||
|
||||
def apply(self, c, now_nanos):
|
||||
return self.CC.update(c, self.CS, now_nanos)
|
||||
89
selfdrive/car/tesla/radar_interface.py
Executable file
89
selfdrive/car/tesla/radar_interface.py
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python3
|
||||
from cereal import car
|
||||
from opendbc.can.parser import CANParser
|
||||
from openpilot.selfdrive.car.tesla.values import DBC, CANBUS
|
||||
from openpilot.selfdrive.car.interfaces import RadarInterfaceBase
|
||||
|
||||
RADAR_MSGS_A = list(range(0x310, 0x36E, 3))
|
||||
RADAR_MSGS_B = list(range(0x311, 0x36F, 3))
|
||||
NUM_POINTS = len(RADAR_MSGS_A)
|
||||
|
||||
def get_radar_can_parser(CP):
|
||||
# Status messages
|
||||
messages = [
|
||||
('TeslaRadarSguInfo', 10),
|
||||
]
|
||||
|
||||
# Radar tracks. There are also raw point clouds available,
|
||||
# we don't use those.
|
||||
for i in range(NUM_POINTS):
|
||||
msg_id_a = RADAR_MSGS_A[i]
|
||||
msg_id_b = RADAR_MSGS_B[i]
|
||||
messages.extend([
|
||||
(msg_id_a, 8),
|
||||
(msg_id_b, 8),
|
||||
])
|
||||
|
||||
return CANParser(DBC[CP.carFingerprint]['radar'], messages, CANBUS.radar)
|
||||
|
||||
class RadarInterface(RadarInterfaceBase):
|
||||
def __init__(self, CP):
|
||||
super().__init__(CP)
|
||||
self.rcp = get_radar_can_parser(CP)
|
||||
self.updated_messages = set()
|
||||
self.track_id = 0
|
||||
self.trigger_msg = RADAR_MSGS_B[-1]
|
||||
|
||||
def update(self, can_strings):
|
||||
if self.rcp is None:
|
||||
return super().update(None)
|
||||
|
||||
values = self.rcp.update_strings(can_strings)
|
||||
self.updated_messages.update(values)
|
||||
|
||||
if self.trigger_msg not in self.updated_messages:
|
||||
return None
|
||||
|
||||
ret = car.RadarData.new_message()
|
||||
|
||||
# Errors
|
||||
errors = []
|
||||
sgu_info = self.rcp.vl['TeslaRadarSguInfo']
|
||||
if not self.rcp.can_valid:
|
||||
errors.append('canError')
|
||||
if sgu_info['RADC_HWFail'] or sgu_info['RADC_SGUFail'] or sgu_info['RADC_SensorDirty']:
|
||||
errors.append('fault')
|
||||
ret.errors = errors
|
||||
|
||||
# Radar tracks
|
||||
for i in range(NUM_POINTS):
|
||||
msg_a = self.rcp.vl[RADAR_MSGS_A[i]]
|
||||
msg_b = self.rcp.vl[RADAR_MSGS_B[i]]
|
||||
|
||||
# Make sure msg A and B are together
|
||||
if msg_a['Index'] != msg_b['Index2']:
|
||||
continue
|
||||
|
||||
# Check if it's a valid track
|
||||
if not msg_a['Tracked']:
|
||||
if i in self.pts:
|
||||
del self.pts[i]
|
||||
continue
|
||||
|
||||
# New track!
|
||||
if i not in self.pts:
|
||||
self.pts[i] = car.RadarData.RadarPoint.new_message()
|
||||
self.pts[i].trackId = self.track_id
|
||||
self.track_id += 1
|
||||
|
||||
# Parse track data
|
||||
self.pts[i].dRel = msg_a['LongDist']
|
||||
self.pts[i].yRel = msg_a['LatDist']
|
||||
self.pts[i].vRel = msg_a['LongSpeed']
|
||||
self.pts[i].aRel = msg_a['LongAccel']
|
||||
self.pts[i].yvRel = msg_b['LatSpeed']
|
||||
self.pts[i].measured = bool(msg_a['Meas'])
|
||||
|
||||
ret.points = list(self.pts.values())
|
||||
self.updated_messages.clear()
|
||||
return ret
|
||||
94
selfdrive/car/tesla/teslacan.py
Normal file
94
selfdrive/car/tesla/teslacan.py
Normal file
@@ -0,0 +1,94 @@
|
||||
import crcmod
|
||||
|
||||
from openpilot.common.conversions import Conversions as CV
|
||||
from openpilot.selfdrive.car.tesla.values import CANBUS, CarControllerParams
|
||||
|
||||
|
||||
class TeslaCAN:
|
||||
def __init__(self, packer, pt_packer):
|
||||
self.packer = packer
|
||||
self.pt_packer = pt_packer
|
||||
self.crc = crcmod.mkCrcFun(0x11d, initCrc=0x00, rev=False, xorOut=0xff)
|
||||
|
||||
@staticmethod
|
||||
def checksum(msg_id, dat):
|
||||
# TODO: get message ID from name instead
|
||||
ret = (msg_id & 0xFF) + ((msg_id >> 8) & 0xFF)
|
||||
ret += sum(dat)
|
||||
return ret & 0xFF
|
||||
|
||||
def create_steering_control(self, angle, enabled, counter):
|
||||
values = {
|
||||
"DAS_steeringAngleRequest": -angle,
|
||||
"DAS_steeringHapticRequest": 0,
|
||||
"DAS_steeringControlType": 1 if enabled else 0,
|
||||
"DAS_steeringControlCounter": counter,
|
||||
}
|
||||
|
||||
data = self.packer.make_can_msg("DAS_steeringControl", CANBUS.chassis, values)[2]
|
||||
values["DAS_steeringControlChecksum"] = self.checksum(0x488, data[:3])
|
||||
return self.packer.make_can_msg("DAS_steeringControl", CANBUS.chassis, values)
|
||||
|
||||
def create_action_request(self, msg_stw_actn_req, cancel, bus, counter):
|
||||
# We copy this whole message when spamming cancel
|
||||
values = {s: msg_stw_actn_req[s] for s in [
|
||||
"SpdCtrlLvr_Stat",
|
||||
"VSL_Enbl_Rq",
|
||||
"SpdCtrlLvrStat_Inv",
|
||||
"DTR_Dist_Rq",
|
||||
"TurnIndLvr_Stat",
|
||||
"HiBmLvr_Stat",
|
||||
"WprWashSw_Psd",
|
||||
"WprWash_R_Sw_Posn_V2",
|
||||
"StW_Lvr_Stat",
|
||||
"StW_Cond_Flt",
|
||||
"StW_Cond_Psd",
|
||||
"HrnSw_Psd",
|
||||
"StW_Sw00_Psd",
|
||||
"StW_Sw01_Psd",
|
||||
"StW_Sw02_Psd",
|
||||
"StW_Sw03_Psd",
|
||||
"StW_Sw04_Psd",
|
||||
"StW_Sw05_Psd",
|
||||
"StW_Sw06_Psd",
|
||||
"StW_Sw07_Psd",
|
||||
"StW_Sw08_Psd",
|
||||
"StW_Sw09_Psd",
|
||||
"StW_Sw10_Psd",
|
||||
"StW_Sw11_Psd",
|
||||
"StW_Sw12_Psd",
|
||||
"StW_Sw13_Psd",
|
||||
"StW_Sw14_Psd",
|
||||
"StW_Sw15_Psd",
|
||||
"WprSw6Posn",
|
||||
"MC_STW_ACTN_RQ",
|
||||
"CRC_STW_ACTN_RQ",
|
||||
]}
|
||||
|
||||
if cancel:
|
||||
values["SpdCtrlLvr_Stat"] = 1
|
||||
values["MC_STW_ACTN_RQ"] = counter
|
||||
|
||||
data = self.packer.make_can_msg("STW_ACTN_RQ", bus, values)[2]
|
||||
values["CRC_STW_ACTN_RQ"] = self.crc(data[:7])
|
||||
return self.packer.make_can_msg("STW_ACTN_RQ", bus, values)
|
||||
|
||||
def create_longitudinal_commands(self, acc_state, speed, min_accel, max_accel, cnt):
|
||||
messages = []
|
||||
values = {
|
||||
"DAS_setSpeed": speed * CV.MS_TO_KPH,
|
||||
"DAS_accState": acc_state,
|
||||
"DAS_aebEvent": 0,
|
||||
"DAS_jerkMin": CarControllerParams.JERK_LIMIT_MIN,
|
||||
"DAS_jerkMax": CarControllerParams.JERK_LIMIT_MAX,
|
||||
"DAS_accelMin": min_accel,
|
||||
"DAS_accelMax": max_accel,
|
||||
"DAS_controlCounter": cnt,
|
||||
"DAS_controlChecksum": 0,
|
||||
}
|
||||
|
||||
for packer, bus in [(self.packer, CANBUS.chassis), (self.pt_packer, CANBUS.powertrain)]:
|
||||
data = packer.make_can_msg("DAS_control", bus, values)[2]
|
||||
values["DAS_controlChecksum"] = self.checksum(0x2b9, data[:7])
|
||||
messages.append(packer.make_can_msg("DAS_control", bus, values))
|
||||
return messages
|
||||
91
selfdrive/car/tesla/values.py
Normal file
91
selfdrive/car/tesla/values.py
Normal file
@@ -0,0 +1,91 @@
|
||||
from collections import namedtuple
|
||||
from enum import StrEnum
|
||||
from typing import Dict, List, Union
|
||||
|
||||
from cereal import car
|
||||
from openpilot.selfdrive.car import AngleRateLimit, dbc_dict
|
||||
from openpilot.selfdrive.car.docs_definitions import CarInfo
|
||||
from openpilot.selfdrive.car.fw_query_definitions import FwQueryConfig, Request, StdQueries
|
||||
|
||||
Ecu = car.CarParams.Ecu
|
||||
|
||||
Button = namedtuple('Button', ['event_type', 'can_addr', 'can_msg', 'values'])
|
||||
|
||||
|
||||
class CAR(StrEnum):
|
||||
AP1_MODELS = 'TESLA AP1 MODEL S'
|
||||
AP2_MODELS = 'TESLA AP2 MODEL S'
|
||||
|
||||
|
||||
CAR_INFO: Dict[str, Union[CarInfo, List[CarInfo]]] = {
|
||||
CAR.AP1_MODELS: CarInfo("Tesla AP1 Model S", "All"),
|
||||
CAR.AP2_MODELS: CarInfo("Tesla AP2 Model S", "All"),
|
||||
}
|
||||
|
||||
|
||||
DBC = {
|
||||
CAR.AP2_MODELS: dbc_dict('tesla_powertrain', 'tesla_radar', chassis_dbc='tesla_can'),
|
||||
CAR.AP1_MODELS: dbc_dict('tesla_powertrain', 'tesla_radar', chassis_dbc='tesla_can'),
|
||||
}
|
||||
|
||||
FW_QUERY_CONFIG = FwQueryConfig(
|
||||
requests=[
|
||||
Request(
|
||||
[StdQueries.TESTER_PRESENT_REQUEST, StdQueries.UDS_VERSION_REQUEST],
|
||||
[StdQueries.TESTER_PRESENT_RESPONSE, StdQueries.UDS_VERSION_RESPONSE],
|
||||
whitelist_ecus=[Ecu.eps],
|
||||
rx_offset=0x08,
|
||||
bus=0,
|
||||
),
|
||||
Request(
|
||||
[StdQueries.TESTER_PRESENT_REQUEST, StdQueries.UDS_VERSION_REQUEST],
|
||||
[StdQueries.TESTER_PRESENT_RESPONSE, StdQueries.UDS_VERSION_RESPONSE],
|
||||
whitelist_ecus=[Ecu.adas, Ecu.electricBrakeBooster, Ecu.fwdRadar],
|
||||
rx_offset=0x10,
|
||||
bus=0,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class CANBUS:
|
||||
# Lateral harness
|
||||
chassis = 0
|
||||
radar = 1
|
||||
autopilot_chassis = 2
|
||||
|
||||
# Longitudinal harness
|
||||
powertrain = 4
|
||||
private = 5
|
||||
autopilot_powertrain = 6
|
||||
|
||||
GEAR_MAP = {
|
||||
"DI_GEAR_INVALID": car.CarState.GearShifter.unknown,
|
||||
"DI_GEAR_P": car.CarState.GearShifter.park,
|
||||
"DI_GEAR_R": car.CarState.GearShifter.reverse,
|
||||
"DI_GEAR_N": car.CarState.GearShifter.neutral,
|
||||
"DI_GEAR_D": car.CarState.GearShifter.drive,
|
||||
"DI_GEAR_SNA": car.CarState.GearShifter.unknown,
|
||||
}
|
||||
|
||||
DOORS = ["DOOR_STATE_FL", "DOOR_STATE_FR", "DOOR_STATE_RL", "DOOR_STATE_RR", "DOOR_STATE_FrontTrunk", "BOOT_STATE"]
|
||||
|
||||
# Make sure the message and addr is also in the CAN parser!
|
||||
BUTTONS = [
|
||||
Button(car.CarState.ButtonEvent.Type.leftBlinker, "STW_ACTN_RQ", "TurnIndLvr_Stat", [1]),
|
||||
Button(car.CarState.ButtonEvent.Type.rightBlinker, "STW_ACTN_RQ", "TurnIndLvr_Stat", [2]),
|
||||
Button(car.CarState.ButtonEvent.Type.accelCruise, "STW_ACTN_RQ", "SpdCtrlLvr_Stat", [4, 16]),
|
||||
Button(car.CarState.ButtonEvent.Type.decelCruise, "STW_ACTN_RQ", "SpdCtrlLvr_Stat", [8, 32]),
|
||||
Button(car.CarState.ButtonEvent.Type.cancel, "STW_ACTN_RQ", "SpdCtrlLvr_Stat", [1]),
|
||||
Button(car.CarState.ButtonEvent.Type.resumeCruise, "STW_ACTN_RQ", "SpdCtrlLvr_Stat", [2]),
|
||||
]
|
||||
|
||||
class CarControllerParams:
|
||||
ANGLE_RATE_LIMIT_UP = AngleRateLimit(speed_bp=[0., 5., 15.], angle_v=[10., 1.6, .3])
|
||||
ANGLE_RATE_LIMIT_DOWN = AngleRateLimit(speed_bp=[0., 5., 15.], angle_v=[10., 7.0, 0.8])
|
||||
JERK_LIMIT_MAX = 8
|
||||
JERK_LIMIT_MIN = -8
|
||||
ACCEL_TO_SPEED_MULTIPLIER = 3
|
||||
|
||||
def __init__(self, CP):
|
||||
pass
|
||||
Reference in New Issue
Block a user