Skip to content

Commit

Permalink
Merge pull request commaai#322 from ShaneSmiskol/SA-staging
Browse files Browse the repository at this point in the history
Only use pedal under 19 mph for Toyota
  • Loading branch information
sshane authored Jan 21, 2021
2 parents 837a9ab + 21dd0fb commit 0a1568c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions selfdrive/car/toyota/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from selfdrive.car.toyota.toyotacan import create_steer_command, create_ui_command, \
create_accel_command, create_acc_cancel_command, \
create_fcw_command
from selfdrive.car.toyota.values import Ecu, CAR, STATIC_MSGS, NO_STOP_TIMER_CAR, SteerLimitParams
from selfdrive.car.toyota.values import Ecu, CAR, STATIC_MSGS, NO_STOP_TIMER_CAR, MIN_ACC_SPEED, SteerLimitParams
from opendbc.can.packer import CANPacker
from common.op_params import opParams

Expand Down Expand Up @@ -60,7 +60,7 @@ def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, hud_alert,

apply_gas = clip(actuators.gas, 0., 1.)

if CS.CP.enableGasInterceptor:
if CS.CP.enableGasInterceptor and CS.out.vEgo < MIN_ACC_SPEED:
# send only negative accel if interceptor is detected. otherwise, send the regular value
# +0.06 offset to reduce ABS pump usage when OP is engaged
apply_accel = 0.06 - actuators.brake
Expand Down Expand Up @@ -134,7 +134,7 @@ def __init__(self, STEER_MAX, STEER_DELTA_UP, STEER_DELTA_DOWN, STEER_ERROR_MAX)
else:
can_sends.append(create_accel_command(self.packer, 0, pcm_cancel_cmd, False, lead))

if (frame % 2 == 0) and (CS.CP.enableGasInterceptor):
if frame % 2 == 0 and CS.CP.enableGasInterceptor and CS.out.vEgo < MIN_ACC_SPEED:
# send exactly zero if apply_gas is zero. Interceptor will send the max between read value and apply_gas.
# This prevents unexpected pedal range rescaling
can_sends.append(create_gas_command(self.packer, apply_gas, frame//2))
Expand Down
20 changes: 9 additions & 11 deletions selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
from cereal import car
from selfdrive.config import Conversions as CV
from selfdrive.car.toyota.values import Ecu, ECU_FINGERPRINT, CAR, TSS2_CAR, FINGERPRINTS
from selfdrive.car.toyota.values import Ecu, ECU_FINGERPRINT, CAR, TSS2_CAR, FINGERPRINTS, MIN_ACC_SPEED
from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, is_ecu_disconnected, gen_empty_fingerprint
from selfdrive.swaglog import cloudlog
from selfdrive.car.interfaces import CarInterfaceBase
Expand Down Expand Up @@ -370,7 +370,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,

# min speed to enable ACC. if car can do stop and go, then set enabling speed
# to a negative value, so it won't matter.
ret.minEnableSpeed = -1. if (stop_and_go or ret.enableGasInterceptor) else 19. * CV.MPH_TO_MS
ret.minEnableSpeed = -1. if (stop_and_go or ret.enableGasInterceptor) else MIN_ACC_SPEED

# removing the DSU disables AEB and it's considered a community maintained feature
# intercepting the DSU is a community feature since it requires unofficial hardware
Expand All @@ -381,16 +381,14 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
ret.longitudinalTuning.kpBP = [0., 5., 35.]
ret.longitudinalTuning.kiBP = [0., 35.]

ret.gasMaxBP = [0.]
ret.gasMaxV = [0.5]
ret.longitudinalTuning.kpV = [3.6, 2.4, 1.5]
ret.longitudinalTuning.kiV = [0.54, 0.36]

if ret.enableGasInterceptor:
ret.gasMaxBP = [0., 9., 35]
ret.gasMaxV = [0.2, 0.5, 0.7]
ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
ret.longitudinalTuning.kiV = [0.18, 0.12]
else:
ret.gasMaxBP = [0.]
ret.gasMaxV = [0.5]
ret.longitudinalTuning.kpV = [3.6, 2.4, 1.5]
ret.longitudinalTuning.kiV = [0.54, 0.36]
ret.gasMaxBP = [0., MIN_ACC_SPEED]
ret.gasMaxV = [0.2, 0.5]

return ret

Expand Down
3 changes: 3 additions & 0 deletions selfdrive/car/toyota/values.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# flake8: noqa

from selfdrive.car import dbc_dict
from selfdrive.config import Conversions as CV
from cereal import car
Ecu = car.CarParams.Ecu

MIN_ACC_SPEED = 19. * CV.MPH_TO_MS # for non-stop-and-go cars only

# Steer torque limits
class SteerLimitParams:
STEER_MAX = 1500
Expand Down

0 comments on commit 0a1568c

Please sign in to comment.