Skip to content

Commit d14bdd5

Browse files
committed
fix toyota pedal gas
1 parent a05af01 commit d14bdd5

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

selfdrive/car/toyota/carcontroller.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ def accel_hysteresis(accel, accel_steady, enabled):
2525
return accel, accel_steady
2626

2727

28+
def coast_accel(speed): # given a speed, output coasting acceleration
29+
points = [[0.0, 0.03], [.166, .424], [.335, .568],
30+
[.731, .440], [1.886, 0.262], [2.809, -0.207],
31+
[3.443, -0.249], [MIN_ACC_SPEED, -0.145]]
32+
return interp(speed, *zip(*points))
33+
34+
35+
def compute_gb_pedal(accel, speed):
36+
_a3, _a4, _a5, _offset, _e1, _e2, _e3, _e4, _e5, _e6, _e7, _e8 = [-0.07264304340456754, -0.007522016704006004, 0.16234124452228196, 0.0029096574419830296, 1.1674372321165579e-05, -0.008010070095545522, -5.834025253616562e-05, 0.04722441060805912, 0.001887454016549489, -0.0014370672920621269, -0.007577594283906699, 0.01943515032956308]
37+
speed_part = (_e5 * accel + _e6) * speed ** 2 + (_e7 * accel + _e8) * speed
38+
accel_part = ((_e1 * speed + _e2) * accel ** 5 + (_e3 * speed + _e4) * accel ** 4 + _a3 * accel ** 3 + _a4 * accel ** 2 + _a5 * accel)
39+
return speed_part + accel_part + _offset
40+
41+
2842
class CarController():
2943
def __init__(self, dbc_name, CP, VM):
3044
self.last_steer = 0
@@ -56,9 +70,8 @@ def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, hud_alert,
5670
if self.use_interceptor and enabled:
5771
# only send negative accel when using interceptor. gas handles acceleration
5872
# +0.18 m/s^2 offset to reduce ABS pump usage when OP is engaged
59-
MAX_INTERCEPTOR_GAS = interp(CS.out.vEgo, [0.0, MIN_ACC_SPEED], [0.2, 0.5])
60-
interceptor_gas_cmd = clip(actuators.accel / PEDAL_SCALE, 0., MAX_INTERCEPTOR_GAS)
61-
pcm_accel_cmd = 0.18 - max(0, -actuators.accel)
73+
if pcm_accel_cmd > coast_accel(CS.out.vEgo):
74+
interceptor_gas_cmd = clip(compute_gb_pedal(pcm_accel_cmd, CS.out.vEgo), 0., 1.)
6275

6376
pcm_accel_cmd, self.accel_steady = accel_hysteresis(pcm_accel_cmd, self.accel_steady, enabled)
6477
pcm_accel_cmd = clip(pcm_accel_cmd, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)

selfdrive/car/toyota/interface.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]): # py
315315
# intercepting the DSU is a community feature since it requires unofficial hardware
316316
ret.communityFeature = ret.enableGasInterceptor or ret.enableDsu or smartDsu
317317

318-
if ret.enableGasInterceptor:
319-
ret.longitudinalTuning.kpBP = [0., 5., MIN_ACC_SPEED, MIN_ACC_SPEED + PEDAL_HYST_GAP, 35.]
320-
ret.longitudinalTuning.kpV = [1.2, 0.8, 0.765, 2.255, 1.5]
321-
ret.longitudinalTuning.kiBP = [0., MIN_ACC_SPEED, MIN_ACC_SPEED + PEDAL_HYST_GAP, 35.]
322-
ret.longitudinalTuning.kiV = [0.18, 0.165, 0.489, 0.36]
323-
elif candidate in [CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2, CAR.RAV4_TSS2, CAR.RAV4H_TSS2, CAR.LEXUS_NX_TSS2]:
318+
if candidate in [CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2, CAR.RAV4_TSS2, CAR.RAV4H_TSS2, CAR.LEXUS_NX_TSS2]:
324319
# Improved longitudinal tune
325320
ret.longitudinalTuning.deadzoneBP = [0., 8.05]
326321
ret.longitudinalTuning.deadzoneV = [.0, .14]

0 commit comments

Comments
 (0)