From 9f14c447db234d90a8fafe55d3e7b6439198f19f Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 13 Aug 2024 22:30:46 -0700 Subject: [PATCH] Move buttonEvents to CarState (#33292) * move mazda button events to carstate * do more * remove * some more * clean up --- selfdrive/car/body/interface.py | 4 +--- selfdrive/car/chrysler/carstate.py | 8 ++++++-- selfdrive/car/chrysler/interface.py | 10 ++-------- selfdrive/car/ford/carstate.py | 7 +++++-- selfdrive/car/ford/interface.py | 9 ++------- selfdrive/car/gm/carstate.py | 22 ++++++++++++++++++---- selfdrive/car/gm/interface.py | 21 +++------------------ selfdrive/car/honda/carstate.py | 17 ++++++++++++++--- selfdrive/car/honda/interface.py | 18 +++--------------- selfdrive/car/hyundai/carstate.py | 16 ++++++++++++++-- selfdrive/car/hyundai/interface.py | 13 +++---------- selfdrive/car/mazda/carstate.py | 9 +++++++-- selfdrive/car/mazda/interface.py | 10 ++-------- selfdrive/car/nissan/carstate.py | 8 ++++++-- selfdrive/car/nissan/interface.py | 10 ++-------- selfdrive/car/subaru/interface.py | 5 +---- selfdrive/car/tesla/interface.py | 4 +--- selfdrive/car/toyota/carstate.py | 11 ++++++----- selfdrive/car/toyota/interface.py | 10 ++-------- selfdrive/car/volkswagen/interface.py | 4 +--- 20 files changed, 99 insertions(+), 117 deletions(-) diff --git a/selfdrive/car/body/interface.py b/selfdrive/car/body/interface.py index 2c66074fd3..a22c7b6a27 100644 --- a/selfdrive/car/body/interface.py +++ b/selfdrive/car/body/interface.py @@ -26,6 +26,4 @@ class CarInterface(CarInterfaceBase): return ret def _update(self): - ret = self.CS.update(self.cp) - - return ret + return self.CS.update(self.cp) diff --git a/selfdrive/car/chrysler/carstate.py b/selfdrive/car/chrysler/carstate.py index c8b084aa62..33d76767bf 100644 --- a/selfdrive/car/chrysler/carstate.py +++ b/selfdrive/car/chrysler/carstate.py @@ -1,10 +1,13 @@ from cereal import car from opendbc.can.parser import CANParser from opendbc.can.can_define import CANDefine +from openpilot.selfdrive.car import create_button_events from openpilot.selfdrive.car.chrysler.values import DBC, STEER_THRESHOLD, RAM_CARS from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.interfaces import CarStateBase +ButtonType = car.CarState.ButtonEvent.Type + class CarState(CarStateBase): def __init__(self, CP): @@ -21,14 +24,13 @@ class CarState(CarStateBase): else: self.shifter_values = can_define.dv["GEAR"]["PRNDL"] - self.prev_distance_button = 0 self.distance_button = 0 def update(self, cp, cp_cam): ret = car.CarState.new_message() - self.prev_distance_button = self.distance_button + prev_distance_button = self.distance_button self.distance_button = cp.vl["CRUISE_BUTTONS"]["ACC_Distance_Dec"] # lock info @@ -101,6 +103,8 @@ class CarState(CarStateBase): self.lkas_car_model = cp_cam.vl["DAS_6"]["CAR_MODEL"] self.button_counter = cp.vl["CRUISE_BUTTONS"]["COUNTER"] + ret.buttonEvents = create_button_events(self.distance_button, prev_distance_button, {1: ButtonType.gapAdjustCruise}) + return ret @staticmethod diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index 04a7cc6c65..44ed2049c0 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -1,12 +1,10 @@ #!/usr/bin/env python3 from cereal import car from panda import Panda -from openpilot.selfdrive.car import create_button_events, get_safety_config +from openpilot.selfdrive.car import 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 @@ -77,8 +75,4 @@ class CarInterface(CarInterfaceBase): return ret def _update(self): - 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}) - - return ret + return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/ford/carstate.py b/selfdrive/car/ford/carstate.py index 5fe105482e..984b241a65 100644 --- a/selfdrive/car/ford/carstate.py +++ b/selfdrive/car/ford/carstate.py @@ -1,11 +1,13 @@ from cereal import car from opendbc.can.can_define import CANDefine from opendbc.can.parser import CANParser +from openpilot.selfdrive.car import create_button_events from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.ford.fordcan import CanBus from openpilot.selfdrive.car.ford.values import DBC, CarControllerParams, FordFlags from openpilot.selfdrive.car.interfaces import CarStateBase +ButtonType = car.CarState.ButtonEvent.Type GearShifter = car.CarState.GearShifter TransmissionType = car.CarParams.TransmissionType @@ -17,7 +19,6 @@ class CarState(CarStateBase): if CP.transmissionType == TransmissionType.automatic: self.shifter_values = can_define.dv["PowertrainData_10"]["TrnRng_D_Rq"] - self.prev_distance_button = 0 self.distance_button = 0 def update(self, cp, cp_cam): @@ -85,7 +86,7 @@ class CarState(CarStateBase): ret.rightBlinker = cp.vl["Steering_Data_FD1"]["TurnLghtSwtch_D_Stat"] == 2 # TODO: block this going to the camera otherwise it will enable stock TJA ret.genericToggle = bool(cp.vl["Steering_Data_FD1"]["TjaButtnOnOffPress"]) - self.prev_distance_button = self.distance_button + prev_distance_button = self.distance_button self.distance_button = cp.vl["Steering_Data_FD1"]["AccButtnGapTogglePress"] # lock info @@ -105,6 +106,8 @@ class CarState(CarStateBase): self.acc_tja_status_stock_values = cp_cam.vl["ACCDATA_3"] self.lkas_status_stock_values = cp_cam.vl["IPMA_Data"] + ret.buttonEvents = create_button_events(self.distance_button, prev_distance_button, {1: ButtonType.gapAdjustCruise}) + return ret @staticmethod diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 8c50561a13..0180f5948e 100644 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -1,12 +1,11 @@ from cereal import car from panda import Panda -from openpilot.selfdrive.car import create_button_events, get_safety_config +from openpilot.selfdrive.car import get_safety_config from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.ford.fordcan import CanBus from openpilot.selfdrive.car.ford.values import Ecu, FordFlags from openpilot.selfdrive.car.interfaces import CarInterfaceBase -ButtonType = car.CarState.ButtonEvent.Type TransmissionType = car.CarParams.TransmissionType @@ -67,8 +66,4 @@ class CarInterface(CarInterfaceBase): return ret def _update(self): - 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}) - - return ret + return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/gm/carstate.py b/selfdrive/car/gm/carstate.py index 97dbd389f4..b6f3ad5ebb 100644 --- a/selfdrive/car/gm/carstate.py +++ b/selfdrive/car/gm/carstate.py @@ -2,15 +2,21 @@ import copy from cereal import car from opendbc.can.can_define import CANDefine from opendbc.can.parser import CANParser +from openpilot.selfdrive.car import create_button_events from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.helpers import mean from openpilot.selfdrive.car.interfaces import CarStateBase -from openpilot.selfdrive.car.gm.values import DBC, AccState, CanBus, STEER_THRESHOLD +from openpilot.selfdrive.car.gm.values import DBC, AccState, CanBus, CruiseButtons, STEER_THRESHOLD +ButtonType = car.CarState.ButtonEvent.Type TransmissionType = car.CarParams.TransmissionType NetworkLocation = car.CarParams.NetworkLocation + STANDSTILL_THRESHOLD = 10 * 0.0311 * CV.KPH_TO_MS +BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise, + CruiseButtons.MAIN: ButtonType.altButton3, CruiseButtons.CANCEL: ButtonType.cancel} + class CarState(CarStateBase): def __init__(self, CP): @@ -26,14 +32,13 @@ class CarState(CarStateBase): self.cam_lka_steering_cmd_counter = 0 self.buttons_counter = 0 - self.prev_distance_button = 0 self.distance_button = 0 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 + prev_cruise_buttons = self.cruise_buttons + 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"] @@ -124,6 +129,15 @@ class CarState(CarStateBase): ret.leftBlindspot = pt_cp.vl["BCMBlindSpotMonitor"]["LeftBSM"] == 1 ret.rightBlindspot = pt_cp.vl["BCMBlindSpotMonitor"]["RightBSM"] == 1 + # Don't add event if transitioning from INIT, unless it's to an actual button + if self.cruise_buttons != CruiseButtons.UNPRESS or prev_cruise_buttons != CruiseButtons.INIT: + ret.buttonEvents = [ + *create_button_events(self.cruise_buttons, prev_cruise_buttons, BUTTONS_DICT, + unpressed_btn=CruiseButtons.UNPRESS), + *create_button_events(self.distance_button, prev_distance_button, + {1: ButtonType.gapAdjustCruise}) + ] + return ret @staticmethod diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 50c1cf510e..ba93318911 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -5,19 +5,15 @@ from math import fabs, exp from panda import Panda from openpilot.common.basedir import BASEDIR -from openpilot.selfdrive.car import create_button_events, get_safety_config, get_friction +from openpilot.selfdrive.car import get_safety_config, get_friction from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.gm.radar_interface import RADAR_HEADER_MSG -from openpilot.selfdrive.car.gm.values import CAR, CruiseButtons, CarControllerParams, EV_CAR, CAMERA_ACC_CAR, CanBus +from openpilot.selfdrive.car.gm.values import CAR, CarControllerParams, EV_CAR, CAMERA_ACC_CAR, CanBus from openpilot.selfdrive.car.interfaces import CarInterfaceBase, TorqueFromLateralAccelCallbackType, FRICTION_THRESHOLD, LatControlInputs, NanoFFModel -ButtonType = car.CarState.ButtonEvent.Type TransmissionType = car.CarParams.TransmissionType NetworkLocation = car.CarParams.NetworkLocation -BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise, - CruiseButtons.MAIN: ButtonType.altButton3, CruiseButtons.CANCEL: ButtonType.cancel} - NON_LINEAR_TORQUE_PARAMS = { CAR.CHEVROLET_BOLT_EUV: [2.6531724862969748, 1.0, 0.1919764879840985, 0.009054123646805178], CAR.GMC_ACADIA: [4.78003305, 1.0, 0.3122, 0.05591772], @@ -200,15 +196,4 @@ class CarInterface(CarInterfaceBase): # returns a car.CarState def _update(self): - ret = self.CS.update(self.cp, self.cp_cam, self.cp_loopback) - - # 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), - *create_button_events(self.CS.distance_button, self.CS.prev_distance_button, - {1: ButtonType.gapAdjustCruise}) - ] - - return ret + return self.CS.update(self.cp, self.cp_cam, self.cp_loopback) diff --git a/selfdrive/car/honda/carstate.py b/selfdrive/car/honda/carstate.py index 956e6a3bd3..97c4bd2eb2 100644 --- a/selfdrive/car/honda/carstate.py +++ b/selfdrive/car/honda/carstate.py @@ -3,15 +3,21 @@ from collections import defaultdict from cereal import car from opendbc.can.can_define import CANDefine from opendbc.can.parser import CANParser +from openpilot.selfdrive.car import create_button_events from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.helpers import interp from openpilot.selfdrive.car.honda.hondacan import CanBus, get_cruise_speed_conversion from openpilot.selfdrive.car.honda.values import CAR, DBC, STEER_THRESHOLD, HONDA_BOSCH, \ HONDA_NIDEC_ALT_SCM_MESSAGES, HONDA_BOSCH_RADARLESS, \ - HondaFlags + HondaFlags, CruiseButtons, CruiseSettings from openpilot.selfdrive.car.interfaces import CarStateBase TransmissionType = car.CarParams.TransmissionType +ButtonType = car.CarState.ButtonEvent.Type + +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} def get_can_messages(CP, gearbox_msg): @@ -112,8 +118,8 @@ class CarState(CarStateBase): v_weight_bp = [1., 6.] # smooth blending, below ~0.6m/s the smooth speed snaps to zero # update prevs, update must run once per loop - self.prev_cruise_buttons = self.cruise_buttons - self.prev_cruise_setting = self.cruise_setting + prev_cruise_buttons = self.cruise_buttons + prev_cruise_setting = self.cruise_setting self.cruise_setting = cp.vl["SCM_BUTTONS"]["CRUISE_SETTING"] self.cruise_buttons = cp.vl["SCM_BUTTONS"]["CRUISE_BUTTONS"] @@ -258,6 +264,11 @@ class CarState(CarStateBase): ret.leftBlindspot = cp_body.vl["BSM_STATUS_LEFT"]["BSM_ALERT"] == 1 ret.rightBlindspot = cp_body.vl["BSM_STATUS_RIGHT"]["BSM_ALERT"] == 1 + ret.buttonEvents = [ + *create_button_events(self.cruise_buttons, prev_cruise_buttons, BUTTONS_DICT), + *create_button_events(self.cruise_setting, prev_cruise_setting, SETTINGS_BUTTONS_DICT), + ] + return ret def get_can_parser(self, CP): diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 65e0a32414..711577355b 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -4,19 +4,14 @@ from panda import Panda from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.helpers import interp from openpilot.selfdrive.car.honda.hondacan import CanBus -from openpilot.selfdrive.car.honda.values import CarControllerParams, CruiseButtons, CruiseSettings, HondaFlags, CAR, HONDA_BOSCH, \ +from openpilot.selfdrive.car.honda.values import CarControllerParams, HondaFlags, CAR, HONDA_BOSCH, \ HONDA_NIDEC_ALT_SCM_MESSAGES, HONDA_BOSCH_RADARLESS -from openpilot.selfdrive.car import create_button_events, get_safety_config +from openpilot.selfdrive.car import get_safety_config from openpilot.selfdrive.car.interfaces import CarInterfaceBase from openpilot.selfdrive.car.disable_ecu import disable_ecu -ButtonType = car.CarState.ButtonEvent.Type 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): @staticmethod @@ -222,11 +217,4 @@ class CarInterface(CarInterfaceBase): # returns a car.CarState def _update(self): - ret = self.CS.update(self.cp, self.cp_cam, self.cp_body) - - 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, SETTINGS_BUTTONS_DICT), - ] - - return ret + return self.CS.update(self.cp, self.cp_cam, self.cp_body) diff --git a/selfdrive/car/hyundai/carstate.py b/selfdrive/car/hyundai/carstate.py index 1b56b3304e..0cc0a6e1a9 100644 --- a/selfdrive/car/hyundai/carstate.py +++ b/selfdrive/car/hyundai/carstate.py @@ -5,16 +5,22 @@ import math from cereal import car from opendbc.can.parser import CANParser from opendbc.can.can_define import CANDefine +from openpilot.selfdrive.car import create_button_events from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, CAN_GEARS, CAMERA_SCC_CAR, \ CANFD_CAR, Buttons, CarControllerParams from openpilot.selfdrive.car.interfaces import CarStateBase +ButtonType = car.CarState.ButtonEvent.Type + PREV_BUTTON_SAMPLES = 8 CLUSTER_SAMPLE_RATE = 20 # frames STANDSTILL_THRESHOLD = 12 * 0.03125 * CV.KPH_TO_MS +BUTTONS_DICT = {Buttons.RES_ACCEL: ButtonType.accelCruise, Buttons.SET_DECEL: ButtonType.decelCruise, + Buttons.GAP_DIST: ButtonType.gapAdjustCruise, Buttons.CANCEL: ButtonType.cancel} + class CarState(CarStateBase): def __init__(self, CP): @@ -162,10 +168,13 @@ class CarState(CarStateBase): self.lkas11 = copy.copy(cp_cam.vl["LKAS11"]) self.clu11 = copy.copy(cp.vl["CLU11"]) self.steer_state = cp.vl["MDPS12"]["CF_Mdps_ToiActive"] # 0 NOT ACTIVE, 1 ACTIVE - self.prev_cruise_buttons = self.cruise_buttons[-1] + prev_cruise_buttons = self.cruise_buttons[-1] self.cruise_buttons.extend(cp.vl_all["CLU11"]["CF_Clu_CruiseSwState"]) self.main_buttons.extend(cp.vl_all["CLU11"]["CF_Clu_CruiseSwMain"]) + if self.CP.openpilotLongitudinalControl: + ret.buttonEvents = create_button_events(self.cruise_buttons[-1], prev_cruise_buttons, BUTTONS_DICT) + return ret def update_canfd(self, cp, cp_cam): @@ -238,7 +247,7 @@ class CarState(CarStateBase): if self.CP.flags & HyundaiFlags.EV: ret.cruiseState.nonAdaptive = cp.vl["MANUAL_SPEED_LIMIT_ASSIST"]["MSLA_ENABLED"] == 1 - self.prev_cruise_buttons = self.cruise_buttons[-1] + prev_cruise_buttons = self.cruise_buttons[-1] self.cruise_buttons.extend(cp.vl_all[self.cruise_btns_msg_canfd]["CRUISE_BUTTONS"]) self.main_buttons.extend(cp.vl_all[self.cruise_btns_msg_canfd]["ADAPTIVE_CRUISE_MAIN_BTN"]) self.buttons_counter = cp.vl[self.cruise_btns_msg_canfd]["COUNTER"] @@ -248,6 +257,9 @@ class CarState(CarStateBase): self.hda2_lfa_block_msg = copy.copy(cp_cam.vl["CAM_0x362"] if self.CP.flags & HyundaiFlags.CANFD_HDA2_ALT_STEERING else cp_cam.vl["CAM_0x2a4"]) + if self.CP.openpilotLongitudinalControl: + ret.buttonEvents = create_button_events(self.cruise_buttons[-1], prev_cruise_buttons, BUTTONS_DICT) + return ret def get_can_parser(self, CP): diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index e94c1080e5..38d6603bff 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -1,19 +1,17 @@ from cereal import car from panda import Panda +from openpilot.selfdrive.car import get_safety_config from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, CANFD_CAR, CAMERA_SCC_CAR, CANFD_RADAR_SCC_CAR, \ CANFD_UNSUPPORTED_LONGITUDINAL_CAR, EV_CAR, HYBRID_CAR, LEGACY_SAFETY_MODE_CAR, \ UNSUPPORTED_LONGITUDINAL_CAR, Buttons from openpilot.selfdrive.car.hyundai.radar_interface import RADAR_START_ADDR -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 Ecu = car.CarParams.Ecu -ButtonType = car.CarState.ButtonEvent.Type + ENABLE_BUTTONS = (Buttons.RES_ACCEL, Buttons.SET_DECEL, Buttons.CANCEL) -BUTTONS_DICT = {Buttons.RES_ACCEL: ButtonType.accelCruise, Buttons.SET_DECEL: ButtonType.decelCruise, - Buttons.GAP_DIST: ButtonType.gapAdjustCruise, Buttons.CANCEL: ButtonType.cancel} class CarInterface(CarInterfaceBase): @@ -150,9 +148,4 @@ class CarInterface(CarInterfaceBase): disable_ecu(can_recv, can_send, bus=CanBus(CP).ECAN, addr=0x7B1, com_cont_req=b'\x28\x83\x01') def _update(self): - ret = self.CS.update(self.cp, self.cp_cam) - - if self.CS.CP.openpilotLongitudinalControl: - ret.buttonEvents = create_button_events(self.CS.cruise_buttons[-1], self.CS.prev_cruise_buttons, BUTTONS_DICT) - - return ret + return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/mazda/carstate.py b/selfdrive/car/mazda/carstate.py index b07e75a225..a55d02a8d8 100644 --- a/selfdrive/car/mazda/carstate.py +++ b/selfdrive/car/mazda/carstate.py @@ -1,10 +1,13 @@ from cereal import car from opendbc.can.can_define import CANDefine from opendbc.can.parser import CANParser +from openpilot.selfdrive.car import create_button_events from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.interfaces import CarStateBase from openpilot.selfdrive.car.mazda.values import DBC, LKAS_LIMITS, MazdaFlags +ButtonType = car.CarState.ButtonEvent.Type + class CarState(CarStateBase): def __init__(self, CP): @@ -19,14 +22,13 @@ class CarState(CarStateBase): self.lkas_allowed_speed = False self.lkas_disabled = False - self.prev_distance_button = 0 self.distance_button = 0 def update(self, cp, cp_cam): ret = car.CarState.new_message() - self.prev_distance_button = self.distance_button + prev_distance_button = self.distance_button self.distance_button = cp.vl["CRZ_BTNS"]["DISTANCE_LESS"] ret.wheelSpeeds = self.get_wheel_speeds( @@ -111,6 +113,9 @@ class CarState(CarStateBase): self.cam_laneinfo = cp_cam.vl["CAM_LANEINFO"] ret.steerFaultPermanent = cp_cam.vl["CAM_LKAS"]["ERR_BIT_1"] == 1 + # TODO: add button types for inc and dec + ret.buttonEvents = create_button_events(self.distance_button, prev_distance_button, {1: ButtonType.gapAdjustCruise}) + return ret @staticmethod diff --git a/selfdrive/car/mazda/interface.py b/selfdrive/car/mazda/interface.py index 07d40553d7..a4e1ffe413 100755 --- a/selfdrive/car/mazda/interface.py +++ b/selfdrive/car/mazda/interface.py @@ -1,11 +1,10 @@ #!/usr/bin/env python3 from cereal import car -from openpilot.selfdrive.car import create_button_events, get_safety_config +from openpilot.selfdrive.car import get_safety_config from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.mazda.values import CAR, LKAS_LIMITS from openpilot.selfdrive.car.interfaces import CarInterfaceBase -ButtonType = car.CarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): @@ -32,9 +31,4 @@ class CarInterface(CarInterfaceBase): # returns a car.CarState def _update(self): - ret = self.CS.update(self.cp, self.cp_cam) - - # TODO: add button types for inc and dec - ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}) - - return ret + return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/nissan/carstate.py b/selfdrive/car/nissan/carstate.py index a9e9d9e9ba..32ac8014eb 100644 --- a/selfdrive/car/nissan/carstate.py +++ b/selfdrive/car/nissan/carstate.py @@ -3,10 +3,13 @@ from collections import deque from cereal import car from opendbc.can.can_define import CANDefine from opendbc.can.parser import CANParser +from openpilot.selfdrive.car import create_button_events from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.interfaces import CarStateBase from openpilot.selfdrive.car.nissan.values import CAR, DBC, CarControllerParams +ButtonType = car.CarState.ButtonEvent.Type + TORQUE_SAMPLES = 12 @@ -21,13 +24,12 @@ class CarState(CarStateBase): self.steeringTorqueSamples = deque(TORQUE_SAMPLES*[0], TORQUE_SAMPLES) self.shifter_values = can_define.dv["GEARBOX"]["GEAR_SHIFTER"] - self.prev_distance_button = 0 self.distance_button = 0 def update(self, cp, cp_adas, cp_cam): ret = car.CarState.new_message() - self.prev_distance_button = self.distance_button + prev_distance_button = self.distance_button self.distance_button = cp.vl["CRUISE_THROTTLE"]["FOLLOW_DISTANCE_BUTTON"] if self.CP.carFingerprint in (CAR.NISSAN_ROGUE, CAR.NISSAN_XTRAIL, CAR.NISSAN_ALTIMA): @@ -122,6 +124,8 @@ class CarState(CarStateBase): self.lkas_hud_msg = copy.copy(cp_adas.vl["PROPILOT_HUD"]) self.lkas_hud_info_msg = copy.copy(cp_adas.vl["PROPILOT_HUD_INFO_MSG"]) + ret.buttonEvents = create_button_events(self.distance_button, prev_distance_button, {1: ButtonType.gapAdjustCruise}) + return ret @staticmethod diff --git a/selfdrive/car/nissan/interface.py b/selfdrive/car/nissan/interface.py index 2df6b91f85..a12e28231b 100644 --- a/selfdrive/car/nissan/interface.py +++ b/selfdrive/car/nissan/interface.py @@ -1,11 +1,9 @@ from cereal import car from panda import Panda -from openpilot.selfdrive.car import create_button_events, get_safety_config +from openpilot.selfdrive.car import 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): @@ -30,8 +28,4 @@ class CarInterface(CarInterfaceBase): # returns a car.CarState def _update(self): - ret = self.CS.update(self.cp, self.cp_adas, self.cp_cam) - - ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}) - - return ret + return self.CS.update(self.cp, self.cp_adas, self.cp_cam) diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index d44be3de3b..0eb7d0be3f 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -98,10 +98,7 @@ class CarInterface(CarInterfaceBase): # returns a car.CarState def _update(self): - - ret = self.CS.update(self.cp, self.cp_cam, self.cp_body) - - return ret + return self.CS.update(self.cp, self.cp_cam, self.cp_body) @staticmethod def init(CP, can_recv, can_send): diff --git a/selfdrive/car/tesla/interface.py b/selfdrive/car/tesla/interface.py index 9b8834ccf7..e31ae28604 100755 --- a/selfdrive/car/tesla/interface.py +++ b/selfdrive/car/tesla/interface.py @@ -40,6 +40,4 @@ class CarInterface(CarInterfaceBase): return ret def _update(self): - ret = self.CS.update(self.cp, self.cp_cam) - - return ret + return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/toyota/carstate.py b/selfdrive/car/toyota/carstate.py index 7c2d0e6ce6..ed0ece4997 100644 --- a/selfdrive/car/toyota/carstate.py +++ b/selfdrive/car/toyota/carstate.py @@ -3,7 +3,7 @@ import copy from cereal import car from opendbc.can.can_define import CANDefine from opendbc.can.parser import CANParser -from openpilot.selfdrive.car import DT_CTRL +from openpilot.selfdrive.car import DT_CTRL, create_button_events from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.filter_simple import FirstOrderFilter from openpilot.selfdrive.car.helpers import mean @@ -11,6 +11,7 @@ from openpilot.selfdrive.car.interfaces import CarStateBase from openpilot.selfdrive.car.toyota.values import ToyotaFlags, CAR, DBC, STEER_THRESHOLD, NO_STOP_TIMER_CAR, \ TSS2_CAR, RADAR_ACC_CAR, EPS_SCALE, UNSUPPORTED_DSU_CAR +ButtonType = car.CarState.ButtonEvent.Type SteerControlType = car.CarParams.SteerControlType # These steering fault definitions seem to be common across LKA (torque) and LTA (angle): @@ -40,7 +41,6 @@ class CarState(CarStateBase): 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.pcm_follow_distance = 0 @@ -172,9 +172,10 @@ class CarState(CarStateBase): if self.CP.carFingerprint in (TSS2_CAR - RADAR_ACC_CAR): # distance button is wired to the ACC module (camera or radar) - self.prev_distance_button = self.distance_button - if self.CP.carFingerprint in (TSS2_CAR - RADAR_ACC_CAR): - self.distance_button = cp_acc.vl["ACC_CONTROL"]["DISTANCE"] + prev_distance_button = self.distance_button + self.distance_button = cp_acc.vl["ACC_CONTROL"]["DISTANCE"] + + ret.buttonEvents = create_button_events(self.distance_button, prev_distance_button, {1: ButtonType.gapAdjustCruise}) return ret diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 0968fbf7f3..bf26d01de6 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -3,11 +3,10 @@ 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 -from openpilot.selfdrive.car import create_button_events, get_safety_config +from openpilot.selfdrive.car import get_safety_config from openpilot.selfdrive.car.disable_ecu import disable_ecu from openpilot.selfdrive.car.interfaces import CarInterfaceBase -ButtonType = car.CarState.ButtonEvent.Type SteerControlType = car.CarParams.SteerControlType @@ -145,9 +144,4 @@ class CarInterface(CarInterfaceBase): # returns a car.CarState def _update(self): - 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}) - - return ret + return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/volkswagen/interface.py b/selfdrive/car/volkswagen/interface.py index 3bd31a4d49..015f9b81d9 100644 --- a/selfdrive/car/volkswagen/interface.py +++ b/selfdrive/car/volkswagen/interface.py @@ -99,6 +99,4 @@ class CarInterface(CarInterfaceBase): # returns a car.CarState def _update(self): - ret = self.CS.update(self.cp, self.cp_cam, self.cp_ext, self.CP.transmissionType) - - return ret + return self.CS.update(self.cp, self.cp_cam, self.cp_ext, self.CP.transmissionType)