From 8fc38619c059ed00e261220c5c68f161d21a5316 Mon Sep 17 00:00:00 2001 From: rbiasini Date: Fri, 21 Feb 2020 18:24:37 -0800 Subject: [PATCH] Abstract gasPressed for all cars (#1151) * min_steer_speed alert (with adjusted hysteresis) for all cars, abstracted gas pre_enable event * move lines a bit * more GM cleanup * typo * move espDisabled to carState packet * brought back min steer speed alert only in hyundai. It's a bit tricky and behavior should be changed * ops, wrong change * bug * update cereal * update ref old-commit-hash: 9685a5a74318dc168cf4f3da994f983df5db08c0 --- cereal | 2 +- selfdrive/car/chrysler/carstate.py | 2 +- selfdrive/car/ford/interface.py | 3 --- selfdrive/car/gm/carstate.py | 9 +++------ selfdrive/car/gm/interface.py | 12 +++--------- selfdrive/car/honda/carstate.py | 2 +- selfdrive/car/honda/interface.py | 3 --- selfdrive/car/hyundai/carstate.py | 2 +- selfdrive/car/hyundai/interface.py | 19 +++++-------------- selfdrive/car/interfaces.py | 7 +++++-- selfdrive/car/subaru/interface.py | 3 --- selfdrive/car/toyota/carstate.py | 2 +- selfdrive/car/toyota/interface.py | 3 --- selfdrive/car/volkswagen/carstate.py | 2 +- selfdrive/car/volkswagen/interface.py | 2 -- selfdrive/test/process_replay/ref_commit | 2 +- 16 files changed, 23 insertions(+), 52 deletions(-) diff --git a/cereal b/cereal index bb13121282..b2e2e07151 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit bb13121282b8c0800e808b4b27d0e0ac4a770f93 +Subproject commit b2e2e071510754a1b6767e35e8129b0e13e36187 diff --git a/selfdrive/car/chrysler/carstate.py b/selfdrive/car/chrysler/carstate.py index 3d217b925c..99e09f00f3 100644 --- a/selfdrive/car/chrysler/carstate.py +++ b/selfdrive/car/chrysler/carstate.py @@ -30,7 +30,7 @@ class CarState(CarStateBase): ret.gas = cp.vl["ACCEL_GAS_134"]['ACCEL_134'] ret.gasPressed = ret.gas > 1e-5 - self.esp_disabled = (cp.vl["TRACTION_BUTTON"]['TRACTION_OFF'] == 1) + ret.espDisabled = (cp.vl["TRACTION_BUTTON"]['TRACTION_OFF'] == 1) ret.wheelSpeeds.fl = cp.vl['WHEEL_SPEEDS']['WHEEL_SPEED_FL'] ret.wheelSpeeds.rr = cp.vl['WHEEL_SPEEDS']['WHEEL_SPEED_RR'] diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 69145ba39b..fb6ed1890f 100755 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -72,9 +72,6 @@ class CarInterface(CarInterfaceBase): (ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001)): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) - if self.CS.lkas_state not in [2, 3] and ret.vEgo > 13.* CV.MPH_TO_MS and ret.cruiseState.enabled: events.append(create_event('steerTempUnavailableMute', [ET.WARNING])) diff --git a/selfdrive/car/gm/carstate.py b/selfdrive/car/gm/carstate.py index 442ae38d9e..cb849c0d2e 100644 --- a/selfdrive/car/gm/carstate.py +++ b/selfdrive/car/gm/carstate.py @@ -9,7 +9,6 @@ from selfdrive.car.gm.values import DBC, CAR, AccState, CanBus, \ STEER_THRESHOLD, SUPERCRUISE_CARS - class CarState(CarStateBase): def __init__(self, CP): super().__init__(CP) @@ -57,15 +56,13 @@ class CarState(CarStateBase): if self.car_fingerprint in SUPERCRUISE_CARS: self.park_brake = False ret.cruiseState.available = False - self.acc_active = pt_cp.vl["ASCMActiveCruiseControlStatus"]['ACCCmdActive'] - self.esp_disabled = False + ret.espDisabled = False regen_pressed = False - self.pcm_acc_status = int(self.acc_active) + self.pcm_acc_status = int(pt_cp.vl["ASCMActiveCruiseControlStatus"]['ACCCmdActive']) else: self.park_brake = pt_cp.vl["EPBStatus"]['EPBClosed'] ret.cruiseState.available = bool(pt_cp.vl["ECMEngineStatus"]['CruiseMainOn']) - self.acc_active = False - self.esp_disabled = pt_cp.vl["ESPStatus"]['TractionControlOn'] != 1 + ret.espDisabled = pt_cp.vl["ESPStatus"]['TractionControlOn'] != 1 self.pcm_acc_status = pt_cp.vl["AcceleratorPedal2"]['CruiseState'] if self.car_fingerprint == CAR.VOLT: regen_pressed = bool(pt_cp.vl["EBCMRegenPaddle"]['RegenPaddle']) diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 1005b3930b..1cc664bdfd 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -10,10 +10,6 @@ from selfdrive.car.interfaces import CarInterfaceBase ButtonType = car.CarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): - def __init__(self, CP, CarController, CarState): - super().__init__(CP, CarController, CarState) - - self.acc_active_prev = 0 @staticmethod def compute_gb(accel, speed): @@ -166,9 +162,9 @@ class CarInterface(CarInterfaceBase): events = self.create_common_events(ret) if self.CS.car_fingerprint in SUPERCRUISE_CARS: - if self.CS.acc_active and not self.acc_active_prev: + if ret.cruiseState.enabled and not self.cruise_enabled_prev: events.append(create_event('pcmEnable', [ET.ENABLE])) - if not self.CS.acc_active: + if not ret.cruiseState.enabled: events.append(create_event('pcmDisable', [ET.USER_DISABLE])) else: @@ -181,8 +177,6 @@ class CarInterface(CarInterfaceBase): if (ret.gasPressed and not self.gas_pressed_prev) or \ (ret.brakePressed): # and (not self.brake_pressed_prev or ret.vEgo > 0.001)): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) if ret.cruiseState.standstill: events.append(create_event('resumeRequired', [ET.WARNING])) if self.CS.pcm_acc_status == AccState.FAULTED: @@ -200,7 +194,7 @@ class CarInterface(CarInterfaceBase): ret.events = events # update previous brake/gas pressed - self.acc_active_prev = self.CS.acc_active + self.cruise_enabled_prev = ret.cruiseState.enabled self.gas_pressed_prev = ret.gasPressed self.brake_pressed_prev = ret.brakePressed diff --git a/selfdrive/car/honda/carstate.py b/selfdrive/car/honda/carstate.py index 5a2b96451b..0feadb6540 100644 --- a/selfdrive/car/honda/carstate.py +++ b/selfdrive/car/honda/carstate.py @@ -199,7 +199,7 @@ class CarState(CarStateBase): self.brake_error = 0 else: self.brake_error = cp.vl["STANDSTILL"]['BRAKE_ERROR_1'] or cp.vl["STANDSTILL"]['BRAKE_ERROR_2'] - self.esp_disabled = cp.vl["VSA_STATUS"]['ESP_DISABLED'] + ret.espDisabled = cp.vl["VSA_STATUS"]['ESP_DISABLED'] != 0 speed_factor = SPEED_FACTOR[self.CP.carFingerprint] ret.wheelSpeeds.fl = cp.vl["WHEEL_SPEEDS"]['WHEEL_SPEED_FL'] * CV.KPH_TO_MS * speed_factor diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 5a95da7098..ee40e3003b 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -455,9 +455,6 @@ class CarInterface(CarInterfaceBase): (ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001)): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) - # it can happen that car cruise disables while comma system is enabled: need to # keep braking if needed or if the speed is very low if self.CP.enableCruise and not ret.cruiseState.enabled and (c.actuators.brake <= 0. or not self.CP.openpilotLongitudinalControl): diff --git a/selfdrive/car/hyundai/carstate.py b/selfdrive/car/hyundai/carstate.py index 809e7bcfef..d3e62b0c64 100644 --- a/selfdrive/car/hyundai/carstate.py +++ b/selfdrive/car/hyundai/carstate.py @@ -52,6 +52,7 @@ class CarState(CarStateBase): pedal_gas = cp.vl["EMS12"]['TPS'] ret.gasPressed = pedal_gas > 1e-3 ret.gas = cp.vl["EMS12"]['TPS'] + ret.espDisabled = cp.vl["TCS15"]['ESC_Off_Step'] != 0 # Gear Selecton - This is not compatible with all Kia/Hyundai's, But is the best way for those it is compatible with gear = cp.vl["LVR12"]["CF_Lvr_Gear"] @@ -100,7 +101,6 @@ class CarState(CarStateBase): # save the entire LKAS11 and CLU11 self.lkas11 = cp_cam.vl["LKAS11"] self.clu11 = cp.vl["CLU11"] - self.esp_disabled = cp.vl["TCS15"]['ESC_Off_Step'] self.park_brake = cp.vl["CGW1"]['CF_Gway_ParkBrakeSw'] self.steer_state = cp.vl["MDPS12"]['CF_Mdps_ToiActive'] #0 NOT ACTIVE, 1 ACTIVE self.steer_warning = cp.vl["MDPS12"]['CF_Mdps_ToiUnavail'] diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index cabb7e16a3..dfc1042649 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -7,10 +7,6 @@ from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, from selfdrive.car.interfaces import CarInterfaceBase class CarInterface(CarInterfaceBase): - def __init__(self, CP, CarController, CarState): - super().__init__(CP, CarController, CarState) - - self.low_speed_alert = False @staticmethod def compute_gb(accel, speed): @@ -103,18 +99,11 @@ class CarInterface(CarInterfaceBase): self.cp_cam.update_strings(can_strings) ret = self.CS.update(self.cp, self.cp_cam) - ret.canValid = self.cp.can_valid and self.cp_cam.can_valid # TODO: button presses ret.buttonEvents = [] - # low speed steer alert hysteresis logic (only for cars with steer cut off above 10 m/s) - if ret.vEgo < (self.CP.minSteerSpeed + 2.) and self.CP.minSteerSpeed > 10.: - self.low_speed_alert = True - if ret.vEgo > (self.CP.minSteerSpeed + 4.): - self.low_speed_alert = False - events = self.create_common_events(ret) if ret.cruiseState.enabled and not self.cruise_enabled_prev: @@ -127,9 +116,11 @@ class CarInterface(CarInterfaceBase): (ret.brakePressed and (not self.brake_pressed_prev or ret.vEgoRaw > 0.1)): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) - + # low speed steer alert hysteresis logic (only for cars with steer cut off above 10 m/s) + if ret.vEgo < (self.CP.minSteerSpeed + 2.) and self.CP.minSteerSpeed > 10.: + self.low_speed_alert = True + if ret.vEgo > (self.CP.minSteerSpeed + 4.): + self.low_speed_alert = False if self.low_speed_alert: events.append(create_event('belowSteerSpeed', [ET.WARNING])) diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 55ee17e186..adbb65f9a6 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -20,6 +20,7 @@ class CarInterfaceBase(): self.gas_pressed_prev = False self.brake_pressed_prev = False self.cruise_enabled_prev = False + self.low_speed_alert = False self.CS = CarState(CP) self.cp = self.CS.get_can_parser(CP) @@ -93,14 +94,16 @@ class CarInterfaceBase(): events.append(create_event('reverseGear', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) if not cs_out.cruiseState.available: events.append(create_event('wrongCarMode', [ET.NO_ENTRY, ET.USER_DISABLE])) + if cs_out.espDisabled: + events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + if cs_out.gasPressed: + events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) # TODO: move this stuff to the capnp strut if getattr(self.CS, "steer_error", False): events.append(create_event('steerUnavailable', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE, ET.PERMANENT])) elif getattr(self.CS, "steer_warning", False): events.append(create_event('steerTempUnavailable', [ET.NO_ENTRY, ET.WARNING])) - if getattr(self.CS, "esp_disabled", False): - events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) return events diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index ef0bfc9c1a..327800524e 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -75,9 +75,6 @@ class CarInterface(CarInterfaceBase): if (ret.gasPressed and not self.gas_pressed_prev): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) - ret.events = events self.gas_pressed_prev = ret.gasPressed diff --git a/selfdrive/car/toyota/carstate.py b/selfdrive/car/toyota/carstate.py index 0dd5603a6d..d6bc5d487e 100644 --- a/selfdrive/car/toyota/carstate.py +++ b/selfdrive/car/toyota/carstate.py @@ -86,7 +86,7 @@ class CarState(CarStateBase): ret.genericToggle = bool(cp.vl["LIGHT_STALK"]['AUTO_HIGH_BEAM']) ret.stockAeb = bool(cp_cam.vl["PRE_COLLISION"]["PRECOLLISION_ACTIVE"] and cp_cam.vl["PRE_COLLISION"]["FORCE"] < -1e-5) - self.esp_disabled = cp.vl["ESP_CONTROL"]['TC_DISABLED'] + ret.espDisabled = cp.vl["ESP_CONTROL"]['TC_DISABLED'] != 0 # 2 is standby, 10 is active. TODO: check that everything else is really a faulty state self.steer_state = cp.vl["EPS_STATUS"]['LKA_STATE'] self.steer_warning = cp.vl["EPS_STATUS"]['LKA_STATE'] not in [1, 5] diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index e600fb3039..44030b2b63 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -323,9 +323,6 @@ class CarInterface(CarInterfaceBase): (ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001)): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) - ret.events = events self.gas_pressed_prev = ret.gasPressed diff --git a/selfdrive/car/volkswagen/carstate.py b/selfdrive/car/volkswagen/carstate.py index 2c18c3fc2d..a726aad5c9 100644 --- a/selfdrive/car/volkswagen/carstate.py +++ b/selfdrive/car/volkswagen/carstate.py @@ -116,7 +116,7 @@ class CarState(CarStateBase): # Additional safety checks performed in CarInterface. self.parkingBrakeSet = bool(pt_cp.vl["Kombi_01"]['KBI_Handbremse']) # FIXME: need to include an EPB check as well - self.esp_disabled = pt_cp.vl["ESP_21"]['ESP_Tastung_passiv'] + ret.espDisabled = pt_cp.vl["ESP_21"]['ESP_Tastung_passiv'] != 0 return ret diff --git a/selfdrive/car/volkswagen/interface.py b/selfdrive/car/volkswagen/interface.py index b9b43edc22..7318a188be 100644 --- a/selfdrive/car/volkswagen/interface.py +++ b/selfdrive/car/volkswagen/interface.py @@ -119,8 +119,6 @@ class CarInterface(CarInterfaceBase): if (ret.gasPressed and not self.gas_pressed_prev) or \ (ret.brakePressed and (not self.brake_pressed_prev or not ret.standstill)): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) # Engagement and longitudinal control using stock ACC. Make sure OP is # disengaged if stock ACC is disengaged. diff --git a/selfdrive/test/process_replay/ref_commit b/selfdrive/test/process_replay/ref_commit index 9d3abf799e..d4b1ef5914 100644 --- a/selfdrive/test/process_replay/ref_commit +++ b/selfdrive/test/process_replay/ref_commit @@ -1 +1 @@ -0491cad238025a44b7fc636cf03efc27d80dcdae +bc912a9ead7664ae4e393a7dc7cd38ba733dd694 \ No newline at end of file