From 70b4cd4f487381990be066cf6cb20c534dd40740 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Thu, 9 May 2024 20:03:47 -0700 Subject: [PATCH] FrogPilot setup - Python imports --- selfdrive/car/chrysler/interface.py | 1 + selfdrive/car/ford/interface.py | 1 + selfdrive/car/gm/interface.py | 1 + selfdrive/car/honda/interface.py | 1 + selfdrive/car/hyundai/interface.py | 1 + selfdrive/car/interfaces.py | 2 +- selfdrive/car/mazda/interface.py | 1 + selfdrive/car/nissan/interface.py | 1 + selfdrive/car/subaru/interface.py | 3 ++- selfdrive/car/toyota/interface.py | 1 + selfdrive/controls/controlsd.py | 5 +++++ selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py | 2 ++ selfdrive/frogpilot/controls/frogpilot_planner.py | 3 ++- selfdrive/frogpilot/controls/lib/frogpilot_functions.py | 6 ++---- selfdrive/manager/manager.py | 3 +++ selfdrive/ui/soundd.py | 1 + 16 files changed, 26 insertions(+), 7 deletions(-) diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index de1c4d6..c27e86e 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -6,6 +6,7 @@ from openpilot.selfdrive.car.chrysler.values import CAR, RAM_HD, RAM_DT, RAM_CAR from openpilot.selfdrive.car.interfaces import CarInterfaceBase ButtonType = car.CarState.ButtonEvent.Type +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 3c52d2d..dfecadd 100644 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -9,6 +9,7 @@ from openpilot.selfdrive.car.interfaces import CarInterfaceBase ButtonType = car.CarState.ButtonEvent.Type TransmissionType = car.CarParams.TransmissionType GearShifter = car.CarState.GearShifter +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 42df06d..fc354c8 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -19,6 +19,7 @@ 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} +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type PEDAL_MSG = 0x201 CAM_MSG = 0x320 # AEBCmd diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index eb8c5fb..2876a1b 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -17,6 +17,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} +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index c25a8ce..d4cb6ac 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -15,6 +15,7 @@ EventName = car.CarEvent.EventName 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} +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index cf5cd32..a9d092e 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -15,7 +15,7 @@ from openpilot.common.numpy_fast import clip from openpilot.common.realtime import DT_CTRL from openpilot.selfdrive.car import apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness, STD_CARGO_KG from openpilot.selfdrive.car.values import PLATFORMS -from openpilot.selfdrive.controls.lib.drive_helpers import V_CRUISE_MAX, get_friction +from openpilot.selfdrive.controls.lib.drive_helpers import CRUISE_LONG_PRESS, V_CRUISE_MAX, get_friction from openpilot.selfdrive.controls.lib.events import Events from openpilot.selfdrive.controls.lib.vehicle_model import VehicleModel diff --git a/selfdrive/car/mazda/interface.py b/selfdrive/car/mazda/interface.py index 29ac400..2b7163b 100755 --- a/selfdrive/car/mazda/interface.py +++ b/selfdrive/car/mazda/interface.py @@ -7,6 +7,7 @@ from openpilot.selfdrive.car.interfaces import CarInterfaceBase ButtonType = car.CarState.ButtonEvent.Type EventName = car.CarEvent.EventName +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): diff --git a/selfdrive/car/nissan/interface.py b/selfdrive/car/nissan/interface.py index ad4a75d..98daaac 100644 --- a/selfdrive/car/nissan/interface.py +++ b/selfdrive/car/nissan/interface.py @@ -5,6 +5,7 @@ from openpilot.selfdrive.car.interfaces import CarInterfaceBase from openpilot.selfdrive.car.nissan.values import CAR ButtonType = car.CarState.ButtonEvent.Type +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index bb93abf..3f8c02f 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -1,10 +1,11 @@ from cereal import car, custom 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, SubaruFlags +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 60f790e..c50f5eb 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -10,6 +10,7 @@ from openpilot.selfdrive.car.interfaces import CarInterfaceBase ButtonType = car.CarState.ButtonEvent.Type EventName = car.CarEvent.EventName SteerControlType = car.CarParams.SteerControlType +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type class CarInterface(CarInterfaceBase): diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index cedcd8f..e14daab 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -32,6 +32,9 @@ from openpilot.selfdrive.controls.lib.vehicle_model import VehicleModel from openpilot.system.hardware import HARDWARE from openpilot.system.version import get_short_branch +from openpilot.selfdrive.frogpilot.controls.lib.frogpilot_functions import MovingAverageCalculator +from openpilot.selfdrive.frogpilot.controls.lib.frogpilot_variables import CRUISING_SPEED, PROBABILITY + SOFT_DISABLE_TIME = 3 # seconds LDW_MIN_SPEED = 31 * CV.MPH_TO_MS LANE_DEPARTURE_THRESHOLD = 0.1 @@ -50,7 +53,9 @@ LaneChangeState = log.LaneChangeState LaneChangeDirection = log.LaneChangeDirection EventName = car.CarEvent.EventName ButtonType = car.CarState.ButtonEvent.Type +GearShifter = car.CarState.GearShifter SafetyModel = car.CarParams.SafetyModel +FrogPilotButtonType = custom.FrogPilotCarState.ButtonEvent.Type IGNORED_SAFETY_MODES = (SafetyModel.silent, SafetyModel.noOutput) CSID_MAP = {"1": EventName.roadCameraError, "2": EventName.wideRoadCameraError, "0": EventName.driverCameraError} diff --git a/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py b/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py index 8b11d74..dbc93ea 100755 --- a/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py +++ b/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py @@ -17,6 +17,8 @@ else: from casadi import SX, vertcat +from openpilot.selfdrive.frogpilot.controls.lib.frogpilot_variables import CITY_SPEED_LIMIT + MODEL_NAME = 'long' LONG_MPC_DIR = os.path.dirname(os.path.abspath(__file__)) EXPORT_DIR = os.path.join(LONG_MPC_DIR, "c_generated_code") diff --git a/selfdrive/frogpilot/controls/frogpilot_planner.py b/selfdrive/frogpilot/controls/frogpilot_planner.py index 6d87018..534b8db 100644 --- a/selfdrive/frogpilot/controls/frogpilot_planner.py +++ b/selfdrive/frogpilot/controls/frogpilot_planner.py @@ -14,7 +14,8 @@ from openpilot.selfdrive.controls.lib.longitudinal_mpc_lib.long_mpc import A_CHA get_safe_obstacle_distance, get_stopped_equivalence_factor, get_T_FOLLOW from openpilot.selfdrive.controls.lib.longitudinal_planner import A_CRUISE_MIN, Lead, get_max_accel -from openpilot.selfdrive.frogpilot.controls.lib.frogpilot_functions import CITY_SPEED_LIMIT, CRUISING_SPEED, calculate_lane_width, calculate_road_curvature +from openpilot.selfdrive.frogpilot.controls.lib.frogpilot_functions import calculate_lane_width, calculate_road_curvature +from openpilot.selfdrive.frogpilot.controls.lib.frogpilot_variables import CITY_SPEED_LIMIT, CRUISING_SPEED GearShifter = car.CarState.GearShifter diff --git a/selfdrive/frogpilot/controls/lib/frogpilot_functions.py b/selfdrive/frogpilot/controls/lib/frogpilot_functions.py index d1f0272..e71de1c 100644 --- a/selfdrive/frogpilot/controls/lib/frogpilot_functions.py +++ b/selfdrive/frogpilot/controls/lib/frogpilot_functions.py @@ -13,10 +13,7 @@ from openpilot.common.params_pyx import UnknownKeyName from openpilot.system.hardware import HARDWARE from openpilot.system.version import get_short_branch, get_commit_date -CITY_SPEED_LIMIT = 25 # 55mph is typically the minimum speed for highways -CRUISING_SPEED = 5 # Roughly the speed cars go when not touching the gas while in drive -PROBABILITY = 0.6 # 60% chance of condition being true -THRESHOLD = 5 # Time threshold (0.25s) +from openpilot.selfdrive.frogpilot.controls.lib.frogpilot_variables import PROBABILITY, THRESHOLD def calculate_lane_width(lane, current_lane, road_edge): lane_x, lane_y = np.array(lane.x), np.array(lane.y) @@ -37,6 +34,7 @@ def calculate_road_curvature(modelData, v_ego): max_pred_lat_acc = np.amax(orientation_rate * velocity) return max_pred_lat_acc / (v_ego**2) + class MovingAverageCalculator: def __init__(self): self.data = [] diff --git a/selfdrive/manager/manager.py b/selfdrive/manager/manager.py index d61388b..c0fb351 100755 --- a/selfdrive/manager/manager.py +++ b/selfdrive/manager/manager.py @@ -4,6 +4,8 @@ import os import signal import subprocess import sys +import threading +import time import traceback from cereal import log @@ -11,6 +13,7 @@ import cereal.messaging as messaging import openpilot.selfdrive.sentry as sentry from openpilot.common.params import Params, ParamKeyType from openpilot.common.text_window import TextWindow +from openpilot.common.time import system_time_valid from openpilot.system.hardware import HARDWARE, PC from openpilot.selfdrive.manager.helpers import unblock_stdout, write_onroad_params, save_bootlog from openpilot.selfdrive.manager.process import ensure_running diff --git a/selfdrive/ui/soundd.py b/selfdrive/ui/soundd.py index 0550a7d..54abd09 100644 --- a/selfdrive/ui/soundd.py +++ b/selfdrive/ui/soundd.py @@ -1,5 +1,6 @@ import math import numpy as np +import os import time import wave