From 06216d43bbd0926cfd89c91c43cfc0cf9247c324 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Mon, 5 Aug 2024 17:27:28 -0700 Subject: [PATCH] remove more car import exceptions (#33193) * remove another exception (remove mention of events from car stack) * guess this should've been here all along * reorganize exceptions * fix --- .importlinter | 10 ++++------ selfdrive/car/car_helpers.py | 20 -------------------- selfdrive/car/ford/carcontroller.py | 3 +-- selfdrive/car/interfaces.py | 2 +- selfdrive/controls/controlsd.py | 4 ++-- selfdrive/controls/lib/drive_helpers.py | 20 ++++++++++++++++++++ 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/.importlinter b/.importlinter index c979095b7f..e884230a76 100644 --- a/.importlinter +++ b/.importlinter @@ -19,21 +19,19 @@ forbidden_modules = openpilot.tinygrad ignore_imports = # remove these + openpilot.selfdrive.car.interfaces -> openpilot.selfdrive.controls.lib.events + + # these are okay + openpilot.selfdrive.car.card -> openpilot.common.swaglog openpilot.selfdrive.car.card -> openpilot.common.realtime openpilot.selfdrive.car.card -> openpilot.selfdrive.controls.lib.events - openpilot.selfdrive.car.interfaces -> openpilot.selfdrive.controls.lib.events openpilot.selfdrive.car.tests.test_models -> openpilot.tools.lib.logreader openpilot.selfdrive.car.tests.test_models -> openpilot.selfdrive.car.card openpilot.selfdrive.car.tests.test_models -> openpilot.tools.lib.route openpilot.selfdrive.car.tests.test_models -> openpilot.system.hardware.hw openpilot.selfdrive.car.tests.test_models -> openpilot.selfdrive.test.helpers - openpilot.selfdrive.car.car_helpers -> openpilot.system.version - openpilot.selfdrive.car.interfaces -> openpilot.selfdrive.controls.lib.drive_helpers openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_angle openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.longcontrol openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_torque openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_pid - - # these are okay - openpilot.selfdrive.car.card -> openpilot.common.swaglog unmatched_ignore_imports_alerting = warn diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 4fdcc1f90c..38f994ecb7 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -12,29 +12,9 @@ from openpilot.selfdrive.car.fw_versions import get_fw_versions_ordered, get_pre from openpilot.selfdrive.car.mock.values import CAR as MOCK import cereal.messaging as messaging from openpilot.selfdrive.car import gen_empty_fingerprint -from openpilot.system.version import get_build_metadata FRAME_FINGERPRINT = 100 # 1s -EventName = car.CarEvent.EventName - - -def get_startup_event(car_recognized, controller_available, fw_seen): - build_metadata = get_build_metadata() - if build_metadata.openpilot.comma_remote and build_metadata.tested_channel: - event = EventName.startup - else: - event = EventName.startupMaster - - if not car_recognized: - if fw_seen: - event = EventName.startupNoCar - else: - event = EventName.startupNoFw - elif car_recognized and not controller_available: - event = EventName.startupNoControl - return event - def get_one_can(logcan): while True: diff --git a/selfdrive/car/ford/carcontroller.py b/selfdrive/car/ford/carcontroller.py index d090adf694..b63b741ee7 100644 --- a/selfdrive/car/ford/carcontroller.py +++ b/selfdrive/car/ford/carcontroller.py @@ -4,11 +4,10 @@ from openpilot.common.numpy_fast import clip from openpilot.selfdrive.car import apply_std_steer_angle_limits from openpilot.selfdrive.car.ford import fordcan from openpilot.selfdrive.car.ford.values import CarControllerParams, FordFlags -from openpilot.selfdrive.car.interfaces import CarControllerBase +from openpilot.selfdrive.car.interfaces import CarControllerBase, V_CRUISE_MAX LongCtrlState = car.CarControl.Actuators.LongControlState VisualAlert = car.CarControl.HUDControl.VisualAlert -V_CRUISE_MAX = 145 def apply_ford_curvature_limits(apply_curvature, apply_curvature_last, current_curvature, v_ego_raw): diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 2121f433b7..f8d71ad341 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -15,7 +15,6 @@ from openpilot.common.simple_kalman import KF1D, get_kalman_gain from openpilot.common.numpy_fast import clip from openpilot.selfdrive.car import DT_CTRL, apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness, get_friction, STD_CARGO_KG from openpilot.selfdrive.car.values import PLATFORMS -from openpilot.selfdrive.controls.lib.drive_helpers import V_CRUISE_MAX from openpilot.selfdrive.controls.lib.events import Events from openpilot.selfdrive.controls.lib.vehicle_model import VehicleModel from openpilot.selfdrive.pandad import can_capnp_to_list @@ -24,6 +23,7 @@ ButtonType = car.CarState.ButtonEvent.Type GearShifter = car.CarState.GearShifter EventName = car.CarEvent.EventName +V_CRUISE_MAX = 145 MAX_CTRL_SPEED = (V_CRUISE_MAX + 4) * CV.KPH_TO_MS ACCEL_MAX = 2.0 ACCEL_MIN = -3.5 diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 583cbaea1f..4dd60faa06 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -18,9 +18,9 @@ from openpilot.common.params import Params from openpilot.common.realtime import config_realtime_process, Priority, Ratekeeper, DT_CTRL from openpilot.common.swaglog import cloudlog -from openpilot.selfdrive.car.car_helpers import get_car_interface, get_startup_event +from openpilot.selfdrive.car.car_helpers import get_car_interface from openpilot.selfdrive.controls.lib.alertmanager import AlertManager, set_offroad_alert -from openpilot.selfdrive.controls.lib.drive_helpers import VCruiseHelper, clip_curvature +from openpilot.selfdrive.controls.lib.drive_helpers import VCruiseHelper, clip_curvature, get_startup_event from openpilot.selfdrive.controls.lib.events import Events, ET from openpilot.selfdrive.controls.lib.latcontrol import LatControl, MIN_LATERAL_CONTROL_SPEED from openpilot.selfdrive.controls.lib.latcontrol_pid import LatControlPID diff --git a/selfdrive/controls/lib/drive_helpers.py b/selfdrive/controls/lib/drive_helpers.py index 4c111a4fd1..51758f8607 100644 --- a/selfdrive/controls/lib/drive_helpers.py +++ b/selfdrive/controls/lib/drive_helpers.py @@ -4,6 +4,9 @@ from cereal import car, log from openpilot.common.conversions import Conversions as CV from openpilot.common.numpy_fast import clip from openpilot.common.realtime import DT_CTRL +from openpilot.system.version import get_build_metadata + +EventName = car.CarEvent.EventName # WARNING: this value was determined based on the model's training distribution, # model predictions above this speed can be unpredictable @@ -157,3 +160,20 @@ def get_speed_error(modelV2: log.ModelDataV2, v_ego: float) -> float: vel_err = clip(modelV2.temporalPose.trans[0] - v_ego, -MAX_VEL_ERR, MAX_VEL_ERR) return float(vel_err) return 0.0 + + +def get_startup_event(car_recognized, controller_available, fw_seen): + build_metadata = get_build_metadata() + if build_metadata.openpilot.comma_remote and build_metadata.tested_channel: + event = EventName.startup + else: + event = EventName.startupMaster + + if not car_recognized: + if fw_seen: + event = EventName.startupNoCar + else: + event = EventName.startupNoFw + elif car_recognized and not controller_available: + event = EventName.startupNoControl + return event