From 3c62d9da0952dc28fa7315e2ff5beb8e5942089f Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 26 Jan 2022 22:08:04 -0800 Subject: [PATCH] Toyota: Move EPS torque factor to openpilot (#23635) * use scaling * or we can do it this way * define default in one place * just specify * Revert "just specify" This reverts commit 40b7b28f8416497cd1337784d336c1dd4f5dd6e3. --- opendbc | 2 +- selfdrive/car/toyota/carstate.py | 5 +++-- selfdrive/car/toyota/interface.py | 12 ++---------- selfdrive/car/toyota/values.py | 3 +++ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/opendbc b/opendbc index e2acd0794c..d4a4614e06 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit e2acd0794c1e4c080231a9c2f85bbbc9dc423d34 +Subproject commit d4a4614e0639d3fa79bd03377e6a61db48b57f17 diff --git a/selfdrive/car/toyota/carstate.py b/selfdrive/car/toyota/carstate.py index 133b0e0c5d..c20434fb65 100644 --- a/selfdrive/car/toyota/carstate.py +++ b/selfdrive/car/toyota/carstate.py @@ -6,7 +6,7 @@ from opendbc.can.can_define import CANDefine from selfdrive.car.interfaces import CarStateBase from opendbc.can.parser import CANParser from selfdrive.config import Conversions as CV -from selfdrive.car.toyota.values import ToyotaFlags, CAR, DBC, STEER_THRESHOLD, NO_STOP_TIMER_CAR, TSS2_CAR +from selfdrive.car.toyota.values import ToyotaFlags, CAR, DBC, STEER_THRESHOLD, NO_STOP_TIMER_CAR, TSS2_CAR, EPS_SCALE class CarState(CarStateBase): @@ -14,6 +14,7 @@ class CarState(CarStateBase): super().__init__(CP) can_define = CANDefine(DBC[CP.carFingerprint]["pt"]) self.shifter_values = can_define.dv["GEAR_PACKET"]["GEAR"] + self.eps_torque_scale = EPS_SCALE[CP.carFingerprint] / 100. # On cars with cp.vl["STEER_TORQUE_SENSOR"]["STEER_ANGLE"] # the signal is zeroed to where the steering angle is at start. @@ -78,7 +79,7 @@ class CarState(CarStateBase): ret.rightBlinker = cp.vl["BLINKERS_STATE"]["TURN_SIGNALS"] == 2 ret.steeringTorque = cp.vl["STEER_TORQUE_SENSOR"]["STEER_TORQUE_DRIVER"] - ret.steeringTorqueEps = cp.vl["STEER_TORQUE_SENSOR"]["STEER_TORQUE_EPS"] + ret.steeringTorqueEps = cp.vl["STEER_TORQUE_SENSOR"]["STEER_TORQUE_EPS"] * self.eps_torque_scale # we could use the override bit from dbc, but it's triggered at too high torque values ret.steeringPressed = abs(ret.steeringTorque) > STEER_THRESHOLD ret.steerWarning = cp.vl["EPS_STATUS"]["LKA_STATE"] not in (1, 5) diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index fc13c53bf1..f0c61eeb22 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -2,7 +2,7 @@ from cereal import car from selfdrive.config import Conversions as CV from selfdrive.car.toyota.tunes import LatTunes, LongTunes, set_long_tune, set_lat_tune -from selfdrive.car.toyota.values import Ecu, CAR, ToyotaFlags, TSS2_CAR, NO_DSU_CAR, MIN_ACC_SPEED, CarControllerParams +from selfdrive.car.toyota.values import Ecu, CAR, ToyotaFlags, TSS2_CAR, NO_DSU_CAR, MIN_ACC_SPEED, EPS_SCALE, CarControllerParams from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, gen_empty_fingerprint, get_safety_config from selfdrive.car.interfaces import CarInterfaceBase @@ -20,17 +20,13 @@ class CarInterface(CarInterfaceBase): ret.carName = "toyota" ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.toyota)] + ret.safetyConfigs[0].safetyParam = EPS_SCALE[candidate] ret.steerActuatorDelay = 0.12 # Default delay, Prius has larger delay ret.steerLimitTimer = 0.4 - ret.stoppingControl = False # Toyota starts braking more when it thinks you want to stop - # Most cars use this default safety param - ret.safetyConfigs[0].safetyParam = 73 - if candidate == CAR.PRIUS: - ret.safetyConfigs[0].safetyParam = 66 # see conversion factor for STEER_TORQUE_EPS in dbc file stop_and_go = True ret.wheelbase = 2.70 ret.steerRatio = 15.74 # unknown end-to-end spec @@ -49,7 +45,6 @@ class CarInterface(CarInterfaceBase): set_lat_tune(ret.lateralTuning, LatTunes.LQR_RAV4) elif candidate == CAR.COROLLA: - ret.safetyConfigs[0].safetyParam = 88 stop_and_go = False ret.wheelbase = 2.70 ret.steerRatio = 18.27 @@ -154,7 +149,6 @@ class CarInterface(CarInterfaceBase): set_lat_tune(ret.lateralTuning, LatTunes.PID_J) elif candidate == CAR.LEXUS_IS: - ret.safetyConfigs[0].safetyParam = 77 stop_and_go = False ret.wheelbase = 2.79908 ret.steerRatio = 13.3 @@ -163,7 +157,6 @@ class CarInterface(CarInterfaceBase): set_lat_tune(ret.lateralTuning, LatTunes.PID_L) elif candidate == CAR.LEXUS_RC: - ret.safetyConfigs[0].safetyParam = 77 stop_and_go = False ret.wheelbase = 2.73050 ret.steerRatio = 13.3 @@ -172,7 +165,6 @@ class CarInterface(CarInterfaceBase): set_lat_tune(ret.lateralTuning, LatTunes.PID_L) elif candidate == CAR.LEXUS_CTH: - ret.safetyConfigs[0].safetyParam = 100 stop_and_go = True ret.wheelbase = 2.60 ret.steerRatio = 18.6 diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index d3a84a2c4c..cab16b72af 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -1,3 +1,4 @@ +from collections import defaultdict from enum import IntFlag from cereal import car @@ -1684,6 +1685,8 @@ DBC = { CAR.ALPHARD_TSS2: dbc_dict('toyota_nodsu_pt_generated', 'toyota_tss2_adas'), } +# These cars have non-standard EPS torque scale factors. All others are 73 +EPS_SCALE = defaultdict(lambda: 73, {CAR.PRIUS: 66, CAR.COROLLA: 88, CAR.LEXUS_IS: 77, CAR.LEXUS_RC: 77, CAR.LEXUS_CTH: 100}) # Toyota/Lexus Safety Sense 2.0 and 2.5 TSS2_CAR = {CAR.RAV4_TSS2, CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2, CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2, CAR.RAV4H_TSS2,