From e8cb6ea06a2470dd89a6ad8fd17bd1d1b62034cc Mon Sep 17 00:00:00 2001 From: Adeeb <8762862+quillford@users.noreply.github.com> Date: Thu, 20 Feb 2020 16:22:25 -0800 Subject: [PATCH] Abstract common events + event cleanup (#1129) * too many if * unused * whitespace * key * sefldrive/car/* * no more gctx * lower * start abstracting common events * all cars * start small * all cars * reverse gear * wrongCarMode * wrongGear * espDisabled * steerUnvailable * make linter happy * c isn't used * fix esp_disabled in VW * update ref * more red * more cleanup * fix subaru * update ref --- selfdrive/athena/athenad.py | 2 +- selfdrive/boardd/tests/boardd_old.py | 2 +- selfdrive/car/chrysler/interface.py | 27 +-------- selfdrive/car/ford/interface.py | 5 +- selfdrive/car/gm/carstate.py | 2 +- selfdrive/car/gm/interface.py | 17 +----- selfdrive/car/honda/interface.py | 19 +------ selfdrive/car/hyundai/carstate.py | 2 +- selfdrive/car/hyundai/interface.py | 22 +------- selfdrive/car/interfaces.py | 25 +++++++++ selfdrive/car/subaru/interface.py | 19 ++----- selfdrive/car/toyota/carstate.py | 2 +- selfdrive/car/toyota/interface.py | 19 +------ selfdrive/car/volkswagen/carstate.py | 2 +- selfdrive/car/volkswagen/interface.py | 13 +---- selfdrive/controls/gps_plannerd.py | 2 +- selfdrive/controls/lib/alerts.py | 28 +++++----- selfdrive/locationd/test/ubloxd.py | 2 +- selfdrive/locationd/test/ubloxd_easy.py | 2 +- selfdrive/loggerd/deleter.py | 2 +- selfdrive/loggerd/ethernetsniffer.py | 2 +- selfdrive/loggerd/uploader.py | 2 +- selfdrive/logmessaged.py | 2 +- selfdrive/manager.py | 55 ++++++++----------- selfdrive/mapd/mapd.py | 2 +- selfdrive/pandad.py | 2 +- .../test_longitudinal.py | 1 - selfdrive/test/process_replay/ref_commit | 2 +- selfdrive/thermald.py | 2 +- selfdrive/tombstoned.py | 2 +- selfdrive/ui/SConscript | 4 +- selfdrive/ui/ui.cc | 1 - selfdrive/updated.py | 2 +- 33 files changed, 97 insertions(+), 196 deletions(-) diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index e3a1bf2f19..90043bfed8 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -294,7 +294,7 @@ def ws_send(ws, end_event): def backoff(retries): return random.randrange(0, min(128, int(2 ** retries))) -def main(gctx=None): +def main(): params = Params() dongle_id = params.get("DongleId").decode('utf-8') ws_uri = ATHENA_HOST + "/ws/v2/" + dongle_id diff --git a/selfdrive/boardd/tests/boardd_old.py b/selfdrive/boardd/tests/boardd_old.py index 48c7a94595..135bde3931 100755 --- a/selfdrive/boardd/tests/boardd_old.py +++ b/selfdrive/boardd/tests/boardd_old.py @@ -232,7 +232,7 @@ def boardd_proxy_loop(rate=100, address="192.168.2.251"): rk.keep_time() -def main(gctx=None): +def main(): if os.getenv("MOCK") is not None: boardd_mock_loop() elif os.getenv("PROXY") is not None: diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index bd239ef73a..3a71988ed6 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -6,14 +6,7 @@ from selfdrive.car.chrysler.values import Ecu, ECU_FINGERPRINT, CAR, FINGERPRINT from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, is_ecu_disconnected, gen_empty_fingerprint from selfdrive.car.interfaces import CarInterfaceBase -GearShifter = car.CarState.GearShifter -ButtonType = car.CarState.ButtonEvent.Type - 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): @@ -76,24 +69,8 @@ class CarInterface(CarInterfaceBase): ret.buttonEvents = [] - self.low_speed_alert = (ret.vEgo < self.CP.minSteerSpeed) - # events - events = [] - if not (ret.gearShifter in (GearShifter.drive, GearShifter.low)): - events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.doorOpen: - events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.seatbeltUnlatched: - events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if self.CS.esp_disabled: - events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if not ret.cruiseState.available: - events.append(create_event('wrongCarMode', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gearShifter == GearShifter.reverse: - events.append(create_event('reverseGear', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) - if self.CS.steer_error: - events.append(create_event('steerUnavailable', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE, ET.PERMANENT])) + events = self.create_common_events(ret, extra_gears=[car.CarState.GearShifter.low]) if ret.cruiseState.enabled and not self.cruise_enabled_prev: events.append(create_event('pcmEnable', [ET.ENABLE])) @@ -105,7 +82,7 @@ class CarInterface(CarInterfaceBase): if (ret.gasPressed and (not self.gas_pressed_prev) and ret.vEgo > 2.0): events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if self.low_speed_alert: + if ret.vEgo < self.CP.minSteerSpeed: events.append(create_event('belowSteerSpeed', [ET.WARNING])) ret.events = events diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 827babe14a..69145ba39b 100755 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -59,10 +59,7 @@ class CarInterface(CarInterfaceBase): ret.canValid = self.cp.can_valid # events - events = [] - - if self.CS.steer_error: - events.append(create_event('steerUnavailable', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE, ET.PERMANENT])) + events = self.create_common_events(ret) # enable request in prius is simple, as we activate when Toyota is active (rising edge) if ret.cruiseState.enabled and not self.cruise_enabled_prev: diff --git a/selfdrive/car/gm/carstate.py b/selfdrive/car/gm/carstate.py index 8dd9b127d7..442ae38d9e 100644 --- a/selfdrive/car/gm/carstate.py +++ b/selfdrive/car/gm/carstate.py @@ -79,7 +79,7 @@ class CarState(CarStateBase): # 0 - inactive, 1 - active, 2 - temporary limited, 3 - failed self.lkas_status = pt_cp.vl["PSCMStatus"]['LKATorqueDeliveredStatus'] - self.steer_not_allowed = not is_eps_status_ok(self.lkas_status, self.car_fingerprint) + self.steer_warning = not is_eps_status_ok(self.lkas_status, self.car_fingerprint) return ret diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 523d57ddf2..1005b3930b 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -163,13 +163,7 @@ class CarInterface(CarInterfaceBase): ret.buttonEvents = buttonEvents - events = [] - if self.CS.steer_not_allowed: - events.append(create_event('steerTempUnavailable', [ET.NO_ENTRY, ET.WARNING])) - if ret.doorOpen: - events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.seatbeltUnlatched: - events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + 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: @@ -178,14 +172,7 @@ class CarInterface(CarInterfaceBase): events.append(create_event('pcmDisable', [ET.USER_DISABLE])) else: - if ret.gearShifter != car.CarState.GearShifter.drive: - events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if self.CS.esp_disabled: - events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if not ret.cruiseState.available: - events.append(create_event('wrongCarMode', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gearShifter == car.CarState.GearShifter.reverse: - events.append(create_event('reverseGear', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) + # TODO: why is this only not supercruise? ignore supercruise? if ret.vEgo < self.CP.minEnableSpeed: events.append(create_event('speedTooLow', [ET.NO_ENTRY])) if self.CS.park_brake: diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 7e5399b6a3..1c493e0d24 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -14,7 +14,6 @@ from selfdrive.car.interfaces import CarInterfaceBase A_ACC_MAX = max(_A_CRUISE_MAX_V_FOLLOWING) ButtonType = car.CarState.ButtonEvent.Type -GearShifter = car.CarState.GearShifter def compute_gb_honda(accel, speed): creep_brake = 0.0 @@ -440,25 +439,9 @@ class CarInterface(CarInterfaceBase): ret.buttonEvents = buttonEvents # events - events = [] - if self.CS.steer_error: - events.append(create_event('steerUnavailable', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE, ET.PERMANENT])) - elif self.CS.steer_warning: - events.append(create_event('steerTempUnavailable', [ET.WARNING])) + events = self.create_common_events(ret) if self.CS.brake_error: events.append(create_event('brakeUnavailable', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE, ET.PERMANENT])) - if not ret.gearShifter == GearShifter.drive: - events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.doorOpen: - events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.seatbeltUnlatched: - events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if self.CS.esp_disabled: - events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if not ret.cruiseState.available: - events.append(create_event('wrongCarMode', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gearShifter == GearShifter.reverse: - events.append(create_event('reverseGear', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) if self.CS.brake_hold and self.CS.CP.carFingerprint not in HONDA_BOSCH: events.append(create_event('brakeHold', [ET.NO_ENTRY, ET.USER_DISABLE])) if self.CS.park_brake: diff --git a/selfdrive/car/hyundai/carstate.py b/selfdrive/car/hyundai/carstate.py index 16ac3207f6..809e7bcfef 100644 --- a/selfdrive/car/hyundai/carstate.py +++ b/selfdrive/car/hyundai/carstate.py @@ -103,7 +103,7 @@ class CarState(CarStateBase): 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_error = cp.vl["MDPS12"]['CF_Mdps_ToiUnavail'] + self.steer_warning = cp.vl["MDPS12"]['CF_Mdps_ToiUnavail'] self.brake_error = 0 return ret diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 9caf13b6ea..cabb7e16a3 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -6,16 +6,10 @@ from selfdrive.car.hyundai.values import Ecu, ECU_FINGERPRINT, CAR, get_hud_aler from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, is_ecu_disconnected, gen_empty_fingerprint from selfdrive.car.interfaces import CarInterfaceBase -GearShifter = car.CarState.GearShifter -ButtonType = car.CarState.ButtonEvent.Type - class CarInterface(CarInterfaceBase): def __init__(self, CP, CarController, CarState): super().__init__(CP, CarController, CarState) - self.idx = 0 - self.lanes = 0 - self.lkas_request = 0 self.low_speed_alert = False @staticmethod @@ -121,21 +115,7 @@ class CarInterface(CarInterfaceBase): if ret.vEgo > (self.CP.minSteerSpeed + 4.): self.low_speed_alert = False - events = [] - if not ret.gearShifter == GearShifter.drive: - events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.doorOpen: - events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.seatbeltUnlatched: - events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if self.CS.esp_disabled: - events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if not ret.cruiseState.available: - events.append(create_event('wrongCarMode', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gearShifter == GearShifter.reverse: - events.append(create_event('reverseGear', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) - if self.CS.steer_error: - events.append(create_event('steerTempUnavailable', [ET.NO_ENTRY, ET.WARNING])) + events = self.create_common_events(ret) if ret.cruiseState.enabled and not self.cruise_enabled_prev: events.append(create_event('pcmEnable', [ET.ENABLE])) diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 6a7c706bdb..55ee17e186 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -4,6 +4,7 @@ from cereal import car from common.kalman.simple_kalman import KF1D from common.realtime import DT_CTRL from selfdrive.car import gen_empty_fingerprint +from selfdrive.controls.lib.drive_helpers import EventTypes as ET, create_event from selfdrive.controls.lib.vehicle_model import VehicleModel GearShifter = car.CarState.GearShifter @@ -79,6 +80,30 @@ class CarInterfaceBase(): def apply(self, c): raise NotImplementedError + def create_common_events(self, cs_out, extra_gears=[]): + events = [] + + if cs_out.doorOpen: + events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + if cs_out.seatbeltUnlatched: + events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + if cs_out.gearShifter != GearShifter.drive and cs_out.gearShifter not in extra_gears: + events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + if cs_out.gearShifter == GearShifter.reverse: + 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])) + + # 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 + class RadarInterfaceBase(): def __init__(self, CP): self.pts = {} diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index 6f99924baa..ef0bfc9c1a 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -6,12 +6,7 @@ from selfdrive.car.subaru.values import CAR from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, gen_empty_fingerprint 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.enabled_prev = 0 @staticmethod def compute_gb(accel, speed): @@ -65,17 +60,13 @@ class CarInterface(CarInterfaceBase): buttonEvents = [] be = car.CarState.ButtonEvent.new_message() - be.type = ButtonType.accelCruise + be.type = car.CarState.ButtonEvent.Type.accelCruise buttonEvents.append(be) - events = [] - if ret.seatbeltUnlatched: - events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - - if ret.doorOpen: - events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + # TODO: add gearShifter to carState + events = self.create_common_events(ret, extra_gears=[car.CarState.GearShifter.unknown]) - if ret.cruiseState.enabled and not self.enabled_prev: + if ret.cruiseState.enabled and not self.cruise_enabled_prev: events.append(create_event('pcmEnable', [ET.ENABLE])) if not ret.cruiseState.enabled: events.append(create_event('pcmDisable', [ET.USER_DISABLE])) @@ -90,7 +81,7 @@ class CarInterface(CarInterfaceBase): ret.events = events self.gas_pressed_prev = ret.gasPressed - self.enabled_prev = ret.cruiseState.enabled + self.cruise_enabled_prev = ret.cruiseState.enabled self.CS.out = ret.as_reader() return self.CS.out diff --git a/selfdrive/car/toyota/carstate.py b/selfdrive/car/toyota/carstate.py index f489005d3b..0dd5603a6d 100644 --- a/selfdrive/car/toyota/carstate.py +++ b/selfdrive/car/toyota/carstate.py @@ -89,7 +89,7 @@ class CarState(CarStateBase): self.esp_disabled = cp.vl["ESP_CONTROL"]['TC_DISABLED'] # 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_error = cp.vl["EPS_STATUS"]['LKA_STATE'] not in [1, 5] + self.steer_warning = cp.vl["EPS_STATUS"]['LKA_STATE'] not in [1, 5] self.ipas_active = cp.vl['EPS_STATUS']['IPAS_STATE'] == 3 return ret diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 73747ad16d..e600fb3039 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -7,9 +7,6 @@ from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, from selfdrive.swaglog import cloudlog from selfdrive.car.interfaces import CarInterfaceBase -ButtonType = car.CarState.ButtonEvent.Type -GearShifter = car.CarState.GearShifter - class CarInterface(CarInterfaceBase): @staticmethod @@ -300,24 +297,10 @@ class CarInterface(CarInterfaceBase): ret.buttonEvents = [] # events - events = [] + events = self.create_common_events(ret) if self.cp_cam.can_invalid_cnt >= 200 and self.CP.enableCamera: events.append(create_event('invalidGiraffeToyota', [ET.PERMANENT])) - if not ret.gearShifter == GearShifter.drive and self.CP.openpilotLongitudinalControl: - events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.doorOpen: - events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.seatbeltUnlatched: - events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if self.CS.esp_disabled and self.CP.openpilotLongitudinalControl: - events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if not ret.cruiseState.available and self.CP.openpilotLongitudinalControl: - events.append(create_event('wrongCarMode', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gearShifter == GearShifter.reverse and self.CP.openpilotLongitudinalControl: - events.append(create_event('reverseGear', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) - if self.CS.steer_error: - events.append(create_event('steerTempUnavailable', [ET.NO_ENTRY, ET.WARNING])) if self.CS.low_speed_lockout and self.CP.openpilotLongitudinalControl: events.append(create_event('lowSpeedLockout', [ET.NO_ENTRY, ET.PERMANENT])) if ret.vEgo < self.CP.minEnableSpeed and self.CP.openpilotLongitudinalControl: diff --git a/selfdrive/car/volkswagen/carstate.py b/selfdrive/car/volkswagen/carstate.py index 333a2f3e6d..2c18c3fc2d 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.stabilityControlDisabled = pt_cp.vl["ESP_21"]['ESP_Tastung_passiv'] + self.esp_disabled = pt_cp.vl["ESP_21"]['ESP_Tastung_passiv'] return ret diff --git a/selfdrive/car/volkswagen/interface.py b/selfdrive/car/volkswagen/interface.py index 6aba56fb2d..b9b43edc22 100644 --- a/selfdrive/car/volkswagen/interface.py +++ b/selfdrive/car/volkswagen/interface.py @@ -75,7 +75,6 @@ class CarInterface(CarInterfaceBase): # returns a car.CarState def update(self, c, can_strings): canMonoTimes = [] - events = [] buttonEvents = [] params = Params() @@ -103,17 +102,9 @@ class CarInterface(CarInterfaceBase): be.pressed = self.CS.buttonStates[button] buttonEvents.append(be) + events = self.create_common_events(ret, extra_gears=[GEAR.eco, GEAR.sport]) + # Vehicle operation safety checks and events - if ret.doorOpen: - events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.seatbeltUnlatched: - events.append(create_event('seatbeltNotLatched', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if ret.gearShifter == GEAR.reverse: - events.append(create_event('reverseGear', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) - if not ret.gearShifter in [GEAR.drive, GEAR.eco, GEAR.sport]: - events.append(create_event('wrongGear', [ET.NO_ENTRY, ET.SOFT_DISABLE])) - if self.CS.stabilityControlDisabled: - events.append(create_event('espDisabled', [ET.NO_ENTRY, ET.SOFT_DISABLE])) if self.CS.parkingBrakeSet: events.append(create_event('parkBrake', [ET.NO_ENTRY, ET.USER_DISABLE])) diff --git a/selfdrive/controls/gps_plannerd.py b/selfdrive/controls/gps_plannerd.py index 9197a60e7d..7572a41879 100755 --- a/selfdrive/controls/gps_plannerd.py +++ b/selfdrive/controls/gps_plannerd.py @@ -362,7 +362,7 @@ def gps_planner_plan(): gps_planner_plan.send(m.to_bytes()) -def main(gctx=None): +def main(): cloudlog.info("Starting gps_plannerd main thread") point_thread = Thread(target=gps_planner_point_selection) diff --git a/selfdrive/controls/lib/alerts.py b/selfdrive/controls/lib/alerts.py index e6a64f1ea7..88fb8fbb03 100644 --- a/selfdrive/controls/lib/alerts.py +++ b/selfdrive/controls/lib/alerts.py @@ -3,7 +3,7 @@ from cereal import car, log # Priority class Priority: LOWEST = 0 - LOW_LOWEST = 1 + LOWER = 1 LOW = 2 MID = 3 HIGH = 4 @@ -169,28 +169,28 @@ ALERTS = [ "Be ready to take over at any time", "Always keep hands on wheel and eyes on road", AlertStatus.normal, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., 15.), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., 15.), Alert( "startupMaster", "WARNING: This branch is not tested", "Always keep hands on wheel and eyes on road", AlertStatus.userPrompt, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., 15.), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., 15.), Alert( "startupNoControl", "Dashcam mode", "Always keep hands on wheel and eyes on road", AlertStatus.normal, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., 15.), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., 15.), Alert( "startupNoCar", "Dashcam mode with unsupported car", "Always keep hands on wheel and eyes on road", AlertStatus.normal, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., 15.), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., 15.), Alert( "ethicalDilemma", @@ -693,21 +693,21 @@ ALERTS = [ "LKAS Fault: Restart the car to engage", "", AlertStatus.normal, AlertSize.small, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2), Alert( "brakeUnavailablePermanent", "Cruise Fault: Restart the car to engage", "", AlertStatus.normal, AlertSize.small, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2), Alert( "lowSpeedLockoutPermanent", "Cruise Fault: Restart the car to engage", "", AlertStatus.normal, AlertSize.small, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2), Alert( "calibrationIncompletePermanent", @@ -721,14 +721,14 @@ ALERTS = [ "Unsupported Giraffe Configuration", "Visit comma.ai/tg", AlertStatus.normal, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2), Alert( "internetConnectivityNeededPermanent", "Please connect to Internet", "An Update Check Is Required to Engage", AlertStatus.normal, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2), Alert( "communityFeatureDisallowedPermanent", @@ -742,28 +742,28 @@ ALERTS = [ "No Data from Device Sensors", "Reboot your Device", AlertStatus.normal, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2), Alert( "soundsUnavailablePermanent", "Speaker not found", "Reboot your Device", AlertStatus.normal, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2), Alert( "lowMemoryPermanent", "RAM Critically Low", "Reboot your Device", AlertStatus.normal, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2), Alert( "carUnrecognizedPermanent", "Dashcam Mode", "Car Unrecognized", AlertStatus.normal, AlertSize.mid, - Priority.LOW_LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2), + Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2), Alert( "vehicleModelInvalid", diff --git a/selfdrive/locationd/test/ubloxd.py b/selfdrive/locationd/test/ubloxd.py index e295958109..65fdfce9b5 100755 --- a/selfdrive/locationd/test/ubloxd.py +++ b/selfdrive/locationd/test/ubloxd.py @@ -276,7 +276,7 @@ def handle_msg(dev, msg, nav_frame_buffer): #if dev is not None and dev.dev is not None: # dev.close() -def main(gctx=None): +def main(): global gpsLocationExternal, ubloxGnss nav_frame_buffer = {} nav_frame_buffer[0] = {} diff --git a/selfdrive/locationd/test/ubloxd_easy.py b/selfdrive/locationd/test/ubloxd_easy.py index a2fa753e78..8f226604ec 100755 --- a/selfdrive/locationd/test/ubloxd_easy.py +++ b/selfdrive/locationd/test/ubloxd_easy.py @@ -10,7 +10,7 @@ import cereal.messaging as messaging unlogger = os.getenv("UNLOGGER") is not None # debug prints -def main(gctx=None): +def main(): poller = zmq.Poller() gpsLocationExternal = messaging.pub_sock('gpsLocationExternal') diff --git a/selfdrive/loggerd/deleter.py b/selfdrive/loggerd/deleter.py index b9ae0e8d4d..27c40e835d 100644 --- a/selfdrive/loggerd/deleter.py +++ b/selfdrive/loggerd/deleter.py @@ -35,7 +35,7 @@ def deleter_thread(exit_event): exit_event.wait(30) -def main(gctx=None): +def main(): deleter_thread(threading.Event()) diff --git a/selfdrive/loggerd/ethernetsniffer.py b/selfdrive/loggerd/ethernetsniffer.py index 1b30b9671e..969c87f932 100755 --- a/selfdrive/loggerd/ethernetsniffer.py +++ b/selfdrive/loggerd/ethernetsniffer.py @@ -4,7 +4,7 @@ import cereal.messaging as messaging from cereal.services import service_list import pcap -def main(gctx=None): +def main(): ethernetData = messaging.pub_sock('ethernetData') for ts, pkt in pcap.pcap('eth0'): diff --git a/selfdrive/loggerd/uploader.py b/selfdrive/loggerd/uploader.py index 6067f01ed6..1d9a261f0b 100644 --- a/selfdrive/loggerd/uploader.py +++ b/selfdrive/loggerd/uploader.py @@ -266,7 +266,7 @@ def uploader_fn(exit_event): backoff = min(backoff*2, 120) cloudlog.info("upload done, success=%r", success) -def main(gctx=None): +def main(): uploader_fn(threading.Event()) if __name__ == "__main__": diff --git a/selfdrive/logmessaged.py b/selfdrive/logmessaged.py index 3362b5baac..693d259a78 100755 --- a/selfdrive/logmessaged.py +++ b/selfdrive/logmessaged.py @@ -3,7 +3,7 @@ import zmq from logentries import LogentriesHandler import cereal.messaging as messaging -def main(gctx=None): +def main(): # setup logentries. we forward log messages to it le_token = "e8549616-0798-4d7e-a2ca-2513ae81fa17" le_handler = LogentriesHandler(le_token, use_tls=False, verbose=False) diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 0d8efc8d36..77ec976b3b 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -475,40 +475,29 @@ def main(): params = Params() params.manager_start() + default_params = [ + ("CommunityFeaturesToggle", "0"), + ("CompletedTrainingVersion", "0"), + ("IsMetric", "0"), + ("RecordFront", "0"), + ("HasAcceptedTerms", "0"), + ("HasCompletedSetup", "0"), + ("IsUploadRawEnabled", "1"), + ("IsLdwEnabled", "1"), + ("IsGeofenceEnabled", "-1"), + ("SpeedLimitOffset", "0"), + ("LongitudinalControl", "0"), + ("LimitSetSpeed", "0"), + ("LimitSetSpeedNeural", "0"), + ("LastUpdateTime", datetime.datetime.now().isoformat().encode('utf8')), + ("OpenpilotEnabledToggle", "1"), + ("LaneChangeEnabled", "1"), + ] + # set unset params - if params.get("CommunityFeaturesToggle") is None: - params.put("CommunityFeaturesToggle", "0") - if params.get("CompletedTrainingVersion") is None: - params.put("CompletedTrainingVersion", "0") - if params.get("IsMetric") is None: - params.put("IsMetric", "0") - if params.get("RecordFront") is None: - params.put("RecordFront", "0") - if params.get("HasAcceptedTerms") is None: - params.put("HasAcceptedTerms", "0") - if params.get("HasCompletedSetup") is None: - params.put("HasCompletedSetup", "0") - if params.get("IsUploadRawEnabled") is None: - params.put("IsUploadRawEnabled", "1") - if params.get("IsLdwEnabled") is None: - params.put("IsLdwEnabled", "1") - if params.get("IsGeofenceEnabled") is None: - params.put("IsGeofenceEnabled", "-1") - if params.get("SpeedLimitOffset") is None: - params.put("SpeedLimitOffset", "0") - if params.get("LongitudinalControl") is None: - params.put("LongitudinalControl", "0") - if params.get("LimitSetSpeed") is None: - params.put("LimitSetSpeed", "0") - if params.get("LimitSetSpeedNeural") is None: - params.put("LimitSetSpeedNeural", "0") - if params.get("LastUpdateTime") is None: - t = datetime.datetime.now().isoformat() - params.put("LastUpdateTime", t.encode('utf8')) - if params.get("OpenpilotEnabledToggle") is None: - params.put("OpenpilotEnabledToggle", "1") - if params.get("LaneChangeEnabled") is None: - params.put("LaneChangeEnabled", "1") + for k, v in default_params: + if params.get(k) is None: + params.put(k, v) # is this chffrplus? if os.getenv("PASSIVE") is not None: diff --git a/selfdrive/mapd/mapd.py b/selfdrive/mapd/mapd.py index 5bd454b1a4..0e337e45d4 100755 --- a/selfdrive/mapd/mapd.py +++ b/selfdrive/mapd/mapd.py @@ -273,7 +273,7 @@ def mapsd_thread(): map_data_sock.send(dat.to_bytes()) -def main(gctx=None): +def main(): params = Params() dongle_id = params.get("DongleId") crash.bind_user(id=dongle_id) diff --git a/selfdrive/pandad.py b/selfdrive/pandad.py index 12d6719fc6..bf747af068 100755 --- a/selfdrive/pandad.py +++ b/selfdrive/pandad.py @@ -86,7 +86,7 @@ def update_panda(): raise AssertionError -def main(gctx=None): +def main(): update_panda() os.chdir("boardd") diff --git a/selfdrive/test/longitudinal_maneuvers/test_longitudinal.py b/selfdrive/test/longitudinal_maneuvers/test_longitudinal.py index 6cd689f17a..02e4e63ca0 100755 --- a/selfdrive/test/longitudinal_maneuvers/test_longitudinal.py +++ b/selfdrive/test/longitudinal_maneuvers/test_longitudinal.py @@ -333,7 +333,6 @@ class LongitudinalControl(unittest.TestCase): params.put("OpenpilotEnabledToggle", "1") params.put("CommunityFeaturesToggle", "1") - manager.gctx = {} manager.prepare_managed_process('radard') manager.prepare_managed_process('controlsd') manager.prepare_managed_process('plannerd') diff --git a/selfdrive/test/process_replay/ref_commit b/selfdrive/test/process_replay/ref_commit index 1b54cbf396..9d3abf799e 100644 --- a/selfdrive/test/process_replay/ref_commit +++ b/selfdrive/test/process_replay/ref_commit @@ -1 +1 @@ -8e94b45bbadf4355135e13905f3e8219ff122f7f \ No newline at end of file +0491cad238025a44b7fc636cf03efc27d80dcdae diff --git a/selfdrive/thermald.py b/selfdrive/thermald.py index c516acc779..6c4f298fd4 100755 --- a/selfdrive/thermald.py +++ b/selfdrive/thermald.py @@ -393,7 +393,7 @@ def thermald_thread(): count += 1 -def main(gctx=None): +def main(): thermald_thread() if __name__ == "__main__": diff --git a/selfdrive/tombstoned.py b/selfdrive/tombstoned.py index 292ec0408b..55a09233a3 100644 --- a/selfdrive/tombstoned.py +++ b/selfdrive/tombstoned.py @@ -101,7 +101,7 @@ def report_tombstone(fn, client): cloudlog.error({'tombstone': message}) -def main(gctx=None): +def main(): initial_tombstones = set(get_tombstones()) client = Client('https://d3b175702f62402c91ade04d1c547e68:b20d68c813c74f63a7cdf9c4039d8f56@sentry.io/157615', diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index 5dbf8016dd..44ce4e332d 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -1,7 +1,7 @@ Import('env', 'arch', 'common', 'messaging', 'gpucommon', 'visionipc', 'cereal') src = ['ui.cc', 'paint.cc', '#phonelibs/nanovg/nanovg.c'] -libs = [common, 'zmq', 'czmq', 'capnp', 'capnp_c', 'm', cereal, 'json', messaging, gpucommon, visionipc] +libs = [common, 'zmq', 'czmq', 'capnp', 'capnp_c', 'm', cereal, messaging, gpucommon, visionipc] if arch == "aarch64": src += ['sound.cc', 'slplay.c'] @@ -11,7 +11,7 @@ else: src += ['linux.cc'] libs += ['pthread', 'glfw'] linkflags = [] - + env.Program('_ui', src, LINKFLAGS=linkflags, LIBS=libs) diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index f1fee9f32d..da566a1e8a 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -6,7 +6,6 @@ #include #include -#include #include #include "common/util.h" diff --git a/selfdrive/updated.py b/selfdrive/updated.py index 29847fdb8b..acc4603f9c 100755 --- a/selfdrive/updated.py +++ b/selfdrive/updated.py @@ -292,7 +292,7 @@ def attempt_update(): set_update_available_params(new_version=new_version) -def main(gctx=None): +def main(): update_failed_count = 0 overlay_init_done = False wait_helper = WaitTimeHelper()