Skip to content

Commit

Permalink
Carstate: Parse follow distance button from steering wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Dec 26, 2023
1 parent 5e6290c commit 0f5b1d9
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 11 deletions.
3 changes: 3 additions & 0 deletions selfdrive/car/chrysler/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def update(self, cp, cp_cam):

ret = car.CarState.new_message()

self.prev_distance_button = self.distance_button
self.distance_button = cp.vl["CRUISE_BUTTONS"]["ACC_Distance_Dec"]

# lock info
ret.doorOpen = any([cp.vl["BCM_1"]["DOOR_OPEN_FL"],
cp.vl["BCM_1"]["DOOR_OPEN_FR"],
Expand Down
6 changes: 5 additions & 1 deletion selfdrive/car/chrysler/interface.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python3
from cereal import car
from panda import Panda
from openpilot.selfdrive.car import get_safety_config
from openpilot.selfdrive.car import create_button_events, get_safety_config
from openpilot.selfdrive.car.chrysler.values import CAR, RAM_HD, RAM_DT, RAM_CARS, ChryslerFlags
from openpilot.selfdrive.car.interfaces import CarInterfaceBase

ButtonType = car.CarState.ButtonEvent.Type


class CarInterface(CarInterfaceBase):
@staticmethod
Expand Down Expand Up @@ -90,6 +92,8 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
def _update(self, c):
ret = self.CS.update(self.cp, self.cp_cam)

ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})

# events
events = self.create_common_events(ret, extra_gears=[car.CarState.GearShifter.low])

Expand Down
3 changes: 3 additions & 0 deletions selfdrive/car/ford/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def __init__(self, CP):
def update(self, cp, cp_cam):
ret = car.CarState.new_message()

self.prev_distance_buttons = self.distance_button
self.distance_button = cp.vl["Steering_Data_FD1"]["AccButtnGapTogglePress"]

# Ford Q3 hybrid variants experience a bug where a message from the PCM sends invalid checksums,
# this must be root-caused before enabling support. Ford Q4 hybrids do not have this problem.
# TrnAin_Tq_Actl and its quality flag are only set on ICE platform variants
Expand Down
5 changes: 4 additions & 1 deletion selfdrive/car/ford/interface.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from cereal import car
from panda import Panda
from openpilot.common.conversions import Conversions as CV
from openpilot.selfdrive.car import get_safety_config
from openpilot.selfdrive.car import create_button_events, get_safety_config
from openpilot.selfdrive.car.ford.fordcan import CanBus
from openpilot.selfdrive.car.ford.values import CANFD_CAR, CAR, Ecu
from openpilot.selfdrive.car.interfaces import CarInterfaceBase

ButtonType = car.CarState.ButtonEvent.Type
TransmissionType = car.CarParams.TransmissionType
GearShifter = car.CarState.GearShifter

Expand Down Expand Up @@ -102,6 +103,8 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
def _update(self, c):
ret = self.CS.update(self.cp, self.cp_cam)

ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})

events = self.create_common_events(ret, extra_gears=[GearShifter.manumatic])
if not self.CS.vehicle_sensors_valid:
events.add(car.CarEvent.EventName.vehicleSensorsInvalid)
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/car/gm/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def update(self, pt_cp, cam_cp, loopback_cp):
ret = car.CarState.new_message()

self.prev_cruise_buttons = self.cruise_buttons
self.prev_distance_button = self.distance_button
self.cruise_buttons = pt_cp.vl["ASCMSteeringButton"]["ACCButtons"]
self.distance_button = pt_cp.vl["ASCMSteeringButton"]["DistanceButton"]
self.buttons_counter = pt_cp.vl["ASCMSteeringButton"]["RollingCounter"]
self.pscm_status = copy.copy(pt_cp.vl["PSCMStatus"])
self.moving_backward = pt_cp.vl["EBCMWheelSpdRear"]["MovingBackward"] != 0
Expand Down
10 changes: 8 additions & 2 deletions selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,16 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
def _update(self, c):
ret = self.CS.update(self.cp, self.cp_cam, self.cp_loopback)

cruise_btns_events = []
# Don't add event if transitioning from INIT, unless it's to an actual button
if self.CS.cruise_buttons != CruiseButtons.UNPRESS or self.CS.prev_cruise_buttons != CruiseButtons.INIT:
ret.buttonEvents = create_button_events(self.CS.cruise_buttons, self.CS.prev_cruise_buttons, BUTTONS_DICT,
unpressed_btn=CruiseButtons.UNPRESS)
cruise_btns_events = create_button_events(self.CS.cruise_buttons, self.CS.prev_cruise_buttons, BUTTONS_DICT,
unpressed_btn=CruiseButtons.UNPRESS)

distance_btn_events = create_button_events(self.CS.distance_button, self.CS.prev_distance_button,
{1: ButtonType.gapAdjustCruise})

ret.buttonEvents = [*cruise_btns_events, *distance_btn_events]

# The ECM allows enabling on falling edge of set, but only rising edge of resume
events = self.create_common_events(ret, extra_gears=[GearShifter.sport, GearShifter.low,
Expand Down
7 changes: 4 additions & 3 deletions selfdrive/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from panda import Panda
from openpilot.common.conversions import Conversions as CV
from openpilot.common.numpy_fast import interp
from openpilot.selfdrive.car.honda.values import CarControllerParams, CruiseButtons, HondaFlags, CAR, HONDA_BOSCH, HONDA_NIDEC_ALT_SCM_MESSAGES, \
HONDA_BOSCH_ALT_BRAKE_SIGNAL, HONDA_BOSCH_RADARLESS
from openpilot.selfdrive.car.honda.values import CarControllerParams, CruiseButtons, CruiseSettings, HondaFlags, CAR, HONDA_BOSCH, \
HONDA_NIDEC_ALT_SCM_MESSAGES, HONDA_BOSCH_ALT_BRAKE_SIGNAL, HONDA_BOSCH_RADARLESS
from openpilot.selfdrive.car import create_button_events, get_safety_config
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.selfdrive.car.disable_ecu import disable_ecu
Expand All @@ -15,6 +15,7 @@
TransmissionType = car.CarParams.TransmissionType
BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise,
CruiseButtons.MAIN: ButtonType.altButton3, CruiseButtons.CANCEL: ButtonType.cancel}
SETTINGS_BUTTONS_DICT = {CruiseSettings.DISTANCE: ButtonType.gapAdjustCruise, CruiseSettings.LKAS: ButtonType.altButton1}


class CarInterface(CarInterfaceBase):
Expand Down Expand Up @@ -313,7 +314,7 @@ def _update(self, c):

ret.buttonEvents = [
*create_button_events(self.CS.cruise_buttons, self.CS.prev_cruise_buttons, BUTTONS_DICT),
*create_button_events(self.CS.cruise_setting, self.CS.prev_cruise_setting, {1: ButtonType.altButton1}),
*create_button_events(self.CS.cruise_setting, self.CS.prev_cruise_setting, SETTINGS_BUTTONS_DICT),
]

# events
Expand Down
5 changes: 5 additions & 0 deletions selfdrive/car/honda/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class CruiseButtons:
MAIN = 1


class CruiseSettings:
DISTANCE = 3
LKAS = 1


# See dbc files for info on values
VISUAL_HUD = {
VisualAlert.none: 0,
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ def __init__(self, CP):
self.right_blinker_prev = False
self.cluster_speed_hyst_gap = 0.0
self.cluster_min_speed = 0.0 # min speed before dropping to 0
self.distance_button = 0
self.prev_distance_button = 0

Q = [[0.0, 0.0], [0.0, 100.0]]
R = 0.3
Expand Down
4 changes: 4 additions & 0 deletions selfdrive/car/mazda/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def __init__(self, CP):
def update(self, cp, cp_cam):

ret = car.CarState.new_message()

self.prev_distance_button = self.distance_button
self.distance_button = cp.vl["CRZ_BTNS"]["DISTANCE_LESS"]

ret.wheelSpeeds = self.get_wheel_speeds(
cp.vl["WHEEL_SPEEDS"]["FL"],
cp.vl["WHEEL_SPEEDS"]["FR"],
Expand Down
4 changes: 3 additions & 1 deletion selfdrive/car/mazda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from cereal import car
from openpilot.common.conversions import Conversions as CV
from openpilot.selfdrive.car.mazda.values import CAR, LKAS_LIMITS
from openpilot.selfdrive.car import get_safety_config
from openpilot.selfdrive.car import create_button_events, get_safety_config
from openpilot.selfdrive.car.interfaces import CarInterfaceBase

ButtonType = car.CarState.ButtonEvent.Type
Expand Down Expand Up @@ -52,6 +52,8 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):
def _update(self, c):
ret = self.CS.update(self.cp, self.cp_cam)

ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})

# events
events = self.create_common_events(ret)

Expand Down
3 changes: 3 additions & 0 deletions selfdrive/car/nissan/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def __init__(self, CP):
def update(self, cp, cp_adas, cp_cam):
ret = car.CarState.new_message()

self.prev_distance_button = self.distance_button
self.distance_button = cp.vl["CRUISE_THROTTLE"]["FOLLOW_DISTANCE_BUTTON"]

if self.CP.carFingerprint in (CAR.ROGUE, CAR.XTRAIL, CAR.ALTIMA):
ret.gas = cp.vl["GAS_PEDAL"]["GAS_PEDAL"]
elif self.CP.carFingerprint in (CAR.LEAF, CAR.LEAF_IC):
Expand Down
6 changes: 5 additions & 1 deletion selfdrive/car/nissan/interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from cereal import car
from panda import Panda
from openpilot.selfdrive.car import get_safety_config
from openpilot.selfdrive.car import create_button_events, get_safety_config
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.selfdrive.car.nissan.values import CAR

ButtonType = car.CarState.ButtonEvent.Type


class CarInterface(CarInterfaceBase):

Expand Down Expand Up @@ -47,6 +49,8 @@ def _update(self, c):
be.type = car.CarState.ButtonEvent.Type.accelCruise
buttonEvents.append(be)

ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})

events = self.create_common_events(ret, extra_gears=[car.CarState.GearShifter.brake])

if self.CS.lkas_enabled:
Expand Down
6 changes: 6 additions & 0 deletions selfdrive/car/subaru/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ def update(self, cp, cp_cam, cp_body):
if self.CP.flags & SubaruFlags.SEND_INFOTAINMENT:
self.es_infotainment_msg = copy.copy(cp_cam.vl["ES_Infotainment"])

self.prev_distance_button = self.distance_button
if self.car_fingerprint in PREGLOBAL_CARS:
self.distance_button = cp_cam.vl["ES_Distance"]["Distance_Swap"]
elif self.car_fingerprint not in HYBRID_CARS:
self.distance_button = cp_es_distance.vl["ES_Distance"]["Distance_Swap"]

return ret

@staticmethod
Expand Down
6 changes: 5 additions & 1 deletion selfdrive/car/subaru/interface.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from cereal import car
from panda import Panda
from openpilot.selfdrive.car import get_safety_config
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.selfdrive.car.subaru.values import CAR, GLOBAL_ES_ADDR, LKAS_ANGLE, GLOBAL_GEN2, PREGLOBAL_CARS, HYBRID_CARS, SubaruFlags

ButtonType = car.CarState.ButtonEvent.Type

class CarInterface(CarInterfaceBase):

Expand Down Expand Up @@ -140,6 +141,9 @@ def _update(self, c):

ret = self.CS.update(self.cp, self.cp_cam, self.cp_body)

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

ret.events = self.create_common_events(ret).to_msg()

return ret
Expand Down
10 changes: 10 additions & 0 deletions selfdrive/car/toyota/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ def update(self, cp, cp_cam):
if self.CP.carFingerprint != CAR.PRIUS_V:
self.lkas_hud = copy.copy(cp_cam.vl["LKAS_HUD"])

if self.CP.carFingerprint in TSS2_CAR or (self.CP.flags & ToyotaFlags.SMART_DSU):
self.prev_distance_button = self.distance_button
dist_bus = cp if self.CP.flags & ToyotaFlags.SMART_DSU else cp_acc
dist_src = "SDSU" if self.CP.flags & ToyotaFlags.SMART_DSU else "ACC_CONTROL"
dist_sig = "FD_BUTTON" if self.CP.flags & ToyotaFlags.SMART_DSU else "DISTANCE"
self.distance_button = dist_bus.vl[dist_src][dist_sig]

return ret

@staticmethod
Expand Down Expand Up @@ -207,6 +214,9 @@ def get_can_parser(CP):
("PRE_COLLISION", 33),
]

if CP.flags & ToyotaFlags.SMART_DSU:
messages.append(("SDSU", 33))

return CANParser(DBC[CP.carFingerprint]["pt"], messages, 0)

@staticmethod
Expand Down
5 changes: 4 additions & 1 deletion selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
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
from openpilot.selfdrive.car import get_safety_config
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

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

Expand Down Expand Up @@ -287,6 +288,8 @@ def init(CP, logcan, sendcan):
def _update(self, c):
ret = self.CS.update(self.cp, self.cp_cam)

ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})

# events
events = self.create_common_events(ret)

Expand Down

0 comments on commit 0f5b1d9

Please sign in to comment.