Skip to content

Commit

Permalink
Add new accel to gas function for pedal (commaai#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
sshane authored Mar 10, 2021
1 parent 80690bb commit 2ab5b62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions selfdrive/car/toyota/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ def accel_hysteresis(accel, accel_steady, enabled):


def coast_accel(speed): # given a speed, output coasting acceleration
points = [[0, .504], [1.697, .266],
[2.839, -.187], [3.413, -.233],
[MIN_ACC_SPEED, -.145]]
points = [[0.0, 0.03], [.166, .424], [.335, .568],
[.731, .440], [1.886, 0.262], [2.809, -0.207],
[3.443, -0.249], [MIN_ACC_SPEED, -0.145]]
return interp(speed, *zip(*points))


def compute_gb_pedal(desired_accel, speed):
_c1, _c2, _c3, _c4 = [0.04412016647510183, 0.018224465923095633, 0.09983653162564889, 0.08837909527049172]
return (desired_accel * _c1 + (_c4 * (speed * _c2 + 1))) * (speed * _c3 + 1)
def compute_gb_pedal(accel, speed):
_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]
speed_part = (_e5 * accel + _e6) * speed ** 2 + (_e7 * accel + _e8) * speed
accel_part = ((_e1 * speed + _e2) * accel ** 5 + (_e3 * speed + _e4) * accel ** 4 + _a3 * accel ** 3 + _a4 * accel ** 2 + _a5 * accel)
return speed_part + accel_part + _offset


class CarController():
Expand Down Expand Up @@ -66,10 +68,12 @@ def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, hud_alert,
apply_gas = 0.
apply_accel = actuators.gas - actuators.brake

if CS.CP.enableGasInterceptor and enabled and CS.out.vEgo < MIN_ACC_SPEED and apply_accel * CarControllerParams.ACCEL_SCALE > coast_accel(CS.out.vEgo):
if CS.CP.enableGasInterceptor and enabled and CS.out.vEgo < MIN_ACC_SPEED:
# converts desired acceleration to gas percentage for pedal
apply_gas = clip(compute_gb_pedal(apply_accel * CarControllerParams.ACCEL_SCALE, CS.out.vEgo), 0., 1.)
apply_accel += 0.06
# +0.06 offset to reduce ABS pump usage when applying very small gas
if apply_accel * CarControllerParams.ACCEL_SCALE > coast_accel(CS.out.vEgo):
apply_gas = clip(compute_gb_pedal(apply_accel * CarControllerParams.ACCEL_SCALE, CS.out.vEgo), 0., 1.)
apply_accel = 0.06 - actuators.brake

apply_accel, self.accel_steady = accel_hysteresis(apply_accel, self.accel_steady, enabled)
apply_accel = clip(apply_accel * CarControllerParams.ACCEL_SCALE, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
ret.lateralTuning.pid.kpBP, ret.lateralTuning.pid.kpV = [[20, 31], [0.04, 0.08]] # 45 to 70 mph
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kiV = [[20, 31], [0.001, 0.01]]
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[20, 31], [0.1, 0.2]]
ret.lateralTuning.pid.kf = 0.00006908923778520113 * 0.9 # full torque for 20 deg at 80mph means 0.00007818594
ret.lateralTuning.pid.kf = 0.00006908923778520113 # full torque for 20 deg at 80mph means 0.00007818594
ret.lateralTuning.pid.newKfTuned = True

elif candidate == CAR.LEXUS_RX:
Expand Down

0 comments on commit 2ab5b62

Please sign in to comment.