Compare commits

...

3 Commits

Author SHA1 Message Date
Shane Smiskol dbbd2872ed this matters 2022-03-23 11:19:49 -07:00
Shane Smiskol b5e7a443cf tune and fix input value 2022-03-23 03:16:31 -07:00
Shane Smiskol a77d718398 try limiting torque by driver torque like other makes 2022-03-22 00:43:11 -07:00
4 changed files with 18 additions and 8 deletions

View File

@ -1,6 +1,6 @@
# functions common among cars
from cereal import car
from common.numpy_fast import clip
from common.numpy_fast import clip, interp
# kg of standard extra cargo to count for drive, gas, etc...
STD_CARGO_KG = 136.
@ -65,12 +65,14 @@ def apply_std_steer_torque_limits(apply_torque, apply_torque_last, driver_torque
return int(round(float(apply_torque)))
def apply_toyota_steer_torque_limits(apply_torque, apply_torque_last, motor_torque, LIMITS):
# limits due to comparison of commanded torque VS motor reported torque
max_lim = min(max(motor_torque + LIMITS.STEER_ERROR_MAX, LIMITS.STEER_ERROR_MAX), LIMITS.STEER_MAX)
min_lim = max(min(motor_torque - LIMITS.STEER_ERROR_MAX, -LIMITS.STEER_ERROR_MAX), -LIMITS.STEER_MAX)
def apply_toyota_steer_torque_limits(apply_torque, apply_torque_last, driver_torque, LIMITS):
# limits due to driver torque
driver_torque = 0 if abs(driver_torque) <= 10 else driver_torque
driver_torque_min = driver_torque - interp(abs(driver_torque), [100, 300], [LIMITS.STEER_MAX, LIMITS.STEER_MAX / 5])
driver_torque_max = driver_torque + (interp(abs(driver_torque), [100, 300], [LIMITS.STEER_MAX, LIMITS.STEER_MAX / 5]))
apply_torque = clip(apply_torque, min_lim, max_lim)
apply_torque = clip(apply_torque, driver_torque_min, driver_torque_max)
apply_torque = clip(apply_torque, -LIMITS.STEER_MAX, LIMITS.STEER_MAX)
# slow rate if steer torque increases in magnitude
if apply_torque_last > 0:

View File

@ -49,7 +49,7 @@ class CarController:
# steer torque
new_steer = int(round(actuators.steer * CarControllerParams.STEER_MAX))
apply_steer = apply_toyota_steer_torque_limits(new_steer, self.last_steer, CS.out.steeringTorqueEps, CarControllerParams)
apply_steer = apply_toyota_steer_torque_limits(new_steer, self.last_steer, CS.out.steeringTorque, CarControllerParams)
self.steer_rate_limited = new_steer != apply_steer
# Cut steering while we're in a known fault state (2s)

View File

@ -198,6 +198,10 @@ class CarInterface(CarInterfaceBase):
ret.mass = 4305. * CV.LB_TO_KG + STD_CARGO_KG
set_lat_tune(ret.lateralTuning, LatTunes.PID_J)
if ret.lateralTuning.which() == 'pid':
ret.lateralTuning.pid.kpV = [p / 10. for p in ret.lateralTuning.pid.kpV]
ret.lateralTuning.pid.kiV = [p / 10. for p in ret.lateralTuning.pid.kiV]
ret.steerRateCost = 1.
ret.centerToFront = ret.wheelbase * 0.44

View File

@ -20,7 +20,11 @@ class CarControllerParams:
STEER_MAX = 1500
STEER_DELTA_UP = 10 # 1.5s time to peak torque
STEER_DELTA_DOWN = 25 # always lower than 45 otherwise the Rav4 faults (Prius seems ok with 50)
STEER_ERROR_MAX = 350 # max delta between torque cmd and torque motor
# these are for std torque limits
STEER_DRIVER_MULTIPLIER = 10 # TODO: find value that makes sense
STEER_DRIVER_FACTOR = 10 # TODO: doesn't totally match
STEER_DRIVER_ALLOWANCE = (STEER_MAX / (384 / 50)) / STEER_DRIVER_FACTOR # TODO: copied from Hyundai
class ToyotaFlags(IntFlag):