Skip to content

Commit

Permalink
Toyota TSS2: parse distance button (commaai#31722)
Browse files Browse the repository at this point in the history
* Enable the distance button to switch personalities for Toyota/Lexus

* Default to the "standard" personality for now

* only parsing first

* only parse

* no personality in card

* safe

* comment

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>
  • Loading branch information
2 people authored and cydia2020 committed May 14, 2024
1 parent 1ece955 commit fc9cd94
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
8 changes: 8 additions & 0 deletions selfdrive/car/toyota/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __init__(self, CP):
self.accurate_steer_angle_seen = False
self.angle_offset = FirstOrderFilter(None, 60.0, DT_CTRL, initialized=False)

self.prev_distance_button = 0
self.distance_button = 0

self.low_speed_lockout = False
self.acc_type = 1
self.lkas_hud = {}
Expand Down Expand Up @@ -194,6 +197,11 @@ def update(self, cp, cp_cam):
ret.accelY = (cp.vl["KINEMATICS"]["ACCEL_Y"])
ret.yawRate = (cp.vl["KINEMATICS"]["YAW_RATE"])

# distance button is wired to the ACC module (camera or radar)
if self.CP.carFingerprint in (TSS2_CAR - RADAR_ACC_CAR):
self.prev_distance_button = self.distance_button
self.distance_button = cp_acc.vl["ACC_CONTROL"]["DISTANCE"]

return ret

@staticmethod
Expand Down
18 changes: 6 additions & 12 deletions selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from panda import Panda
from panda.python import uds
from openpilot.selfdrive.car.toyota.values import Ecu, CAR, DBC, ToyotaFlags, CarControllerParams, TSS2_CAR, RADAR_ACC_CAR, NO_DSU_CAR, \
MIN_ACC_SPEED, EPS_SCALE, UNSUPPORTED_DSU_CAR, NO_STOP_TIMER_CAR, ANGLE_CONTROL_CAR, STOP_AND_GO_CAR
from openpilot.selfdrive.car import get_safety_config
MIN_ACC_SPEED, EPS_SCALE, UNSUPPORTED_DSU_CAR, NO_STOP_TIMER_CAR, ANGLE_CONTROL_CAR
from openpilot.selfdrive.car import create_button_events, get_safety_config
from openpilot.selfdrive.car.disable_ecu import disable_ecu
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.common.params import Params

ButtonType = car.CarState.ButtonEvent.Type
EventName = car.CarEvent.EventName
SteerControlType = car.CarParams.SteerControlType

Expand Down Expand Up @@ -183,19 +184,12 @@ def init(CP, logcan, sendcan):
def _update(self, c):
ret = self.CS.update(self.cp, self.cp_cam)

if self.CP.carFingerprint in (TSS2_CAR - RADAR_ACC_CAR):
ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})

# events
events = self.create_common_events(ret)

if self.CS.pcmFollowDistance == 1 and self.pcmFollowDistancePrev != 1:
Params().put_nonblocking("LongitudinalPersonality", str(log.LongitudinalPersonality.relaxed))
self.pcmFollowDistancePrev = 1
if self.CS.pcmFollowDistance == 2 and self.pcmFollowDistancePrev != 2:
Params().put_nonblocking("LongitudinalPersonality", str(log.LongitudinalPersonality.standard))
self.pcmFollowDistancePrev = 2
if self.CS.pcmFollowDistance == 3 and self.pcmFollowDistancePrev != 3:
Params().put_nonblocking("LongitudinalPersonality", str(log.LongitudinalPersonality.aggressive))
self.pcmFollowDistancePrev = 3

# LDA faults if user does not put their hands on the steering wheel
# disallow engagement if LDA Steering Assist is ON
if self.CS.lda_sa_toggle == 1:
Expand Down

0 comments on commit fc9cd94

Please sign in to comment.