diff --git a/opendbc/car/tesla/carcontroller.py b/opendbc/car/tesla/carcontroller.py index b92c804425..de02f90209 100644 --- a/opendbc/car/tesla/carcontroller.py +++ b/opendbc/car/tesla/carcontroller.py @@ -4,7 +4,7 @@ from opendbc.car import apply_std_steer_angle_limits from opendbc.car.interfaces import CarControllerBase from opendbc.car.tesla.teslacan import TeslaCAN -from opendbc.car.tesla.values import DBC, CarControllerParams +from opendbc.car.tesla.values import CarControllerParams class CarController(CarControllerBase): @@ -41,18 +41,15 @@ def update(self, CC, CS, now_nanos): if self.CP.openpilotLongitudinalControl and self.frame % 4 == 0: state = CS.das_control["DAS_accState"] if hands_on_fault: - state = 13 # "ACC_CANCEL_GENERIC_SILENT" + state = 13 # "ACC_CANCEL_GENERIC_SILENT" accel = clip(actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX) - speed = max(CS.out.vEgo + (accel * CarControllerParams.ACCEL_TO_SPEED_MULTIPLIER), 0) - min_accel = max(accel, 0) - max_accel = accel - cntr = (self.frame // 4) % 8 - can_sends.append(self.tesla_can.create_longitudinal_command(state, speed, max_accel, min_accel, cntr)) + cntr = (self.frame // 4) % 8 + can_sends.append(self.tesla_can.create_longitudinal_command(state, accel, cntr)) # Increment counter so cancel is prioritized even without openpilot longitudinal if hands_on_fault and not self.CP.openpilotLongitudinalControl: cntr = (CS.das_control["DAS_controlCounter"] + 1) % 8 - can_sends.append(self.tesla_can.create_cancel_command(cntr)) + can_sends.append(self.tesla_can.create_longitudinal_command(13, 0, cntr)) # TODO: HUD control new_actuators = copy.copy(actuators) diff --git a/opendbc/car/tesla/teslacan.py b/opendbc/car/tesla/teslacan.py index 10db3a4096..d727afecc4 100644 --- a/opendbc/car/tesla/teslacan.py +++ b/opendbc/car/tesla/teslacan.py @@ -1,4 +1,4 @@ -from opendbc.car.common.conversions import Conversions as CV +from opendbc.car.interfaces import V_CRUISE_MAX from opendbc.car.tesla.values import CANBUS, CarControllerParams @@ -24,21 +24,18 @@ def create_steering_control(self, angle, enabled, counter): values["DAS_steeringControlChecksum"] = self.checksum(0x488, data[:3]) return self.packer.make_can_msg("DAS_steeringControl", CANBUS.party, values) - def create_longitudinal_command(self, acc_state, speed, min_accel, max_accel, cntr): + def create_longitudinal_command(self, acc_state, accel, cntr): values = { - "DAS_setSpeed": speed * CV.MS_TO_KPH, + "DAS_setSpeed": 0 if accel < 0 else V_CRUISE_MAX, "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_accelMin": max(accel, 0), + "DAS_accelMax": accel, "DAS_controlCounter": cntr, "DAS_controlChecksum": 0, } data = self.packer.make_can_msg("DAS_control", CANBUS.party, values)[1] values["DAS_controlChecksum"] = self.checksum(0x2b9, data[:7]) return self.packer.make_can_msg("DAS_control", CANBUS.party, values) - - def create_cancel_command(self, cntr): - return self.create_longitudinal_command(13, 0, 0, 0, cntr) diff --git a/opendbc/car/tesla/values.py b/opendbc/car/tesla/values.py index 2ace668fd3..a9e61e1f75 100644 --- a/opendbc/car/tesla/values.py +++ b/opendbc/car/tesla/values.py @@ -54,7 +54,6 @@ class CarControllerParams: ACCEL_MAX = 2.0 # m/s^2 JERK_LIMIT_MAX = 5 JERK_LIMIT_MIN = -5 - ACCEL_TO_SPEED_MULTIPLIER = 3 def __init__(self, CP): pass