From 89073d6b88b692d343114e9adcaf54ffa4e6a699 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 16 Nov 2024 03:33:23 -0500 Subject: [PATCH] Move car-specific changes to opendbc --- opendbc_repo | 2 +- selfdrive/controls/controlsd.py | 29 +++++++++++--- sunnypilot/__init__.py | 0 sunnypilot/selfdrive/__init__.py | 0 sunnypilot/selfdrive/car/__init__.py | 0 sunnypilot/selfdrive/car/hyundai/__init__.py | 0 .../selfdrive/car/hyundai/carcontroller.py | 38 ------------------- sunnypilot/selfdrive/car/interfaces.py | 13 ------- 8 files changed, 25 insertions(+), 57 deletions(-) delete mode 100644 sunnypilot/__init__.py delete mode 100644 sunnypilot/selfdrive/__init__.py delete mode 100644 sunnypilot/selfdrive/car/__init__.py delete mode 100644 sunnypilot/selfdrive/car/hyundai/__init__.py delete mode 100644 sunnypilot/selfdrive/car/hyundai/carcontroller.py delete mode 100644 sunnypilot/selfdrive/car/interfaces.py diff --git a/opendbc_repo b/opendbc_repo index 71e45f46b2..992ef0a13c 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit 71e45f46b222e4a843fb1caf7f82106d4bd8e1fe +Subproject commit 992ef0a13c114dad09d87e94c7ab5d159f01a827 diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 4ea2ac2971..f9587856f5 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 import math from typing import SupportsFloat +import time +import threading from cereal import car, log import cereal.messaging as messaging @@ -59,6 +61,8 @@ class Controls: data_services = list(self.sm.data.keys()) + ['selfdriveStateSP'] self.sm = messaging.SubMaster(data_services, poll='selfdriveState') + self.enable_mads = self.params.get_bool("Mads") + def update(self): self.sm.update(15) if self.sm.updated["liveCalibration"]: @@ -165,6 +169,9 @@ class Controls: hudControl.leftLaneDepart = self.sm['driverAssistance'].leftLaneDeparture hudControl.rightLaneDepart = self.sm['driverAssistance'].rightLaneDeparture + sunnyLiveParams = CC.sunnyLiveParams + sunnyLiveParams.enableMads = self.enable_mads + if self.sm['selfdriveState'].active: CO = self.sm['carOutput'] if self.CP.steerControlType == car.CarParams.SteerControlType.angle: @@ -211,13 +218,25 @@ class Controls: cc_send.carControl = CC self.pm.send('carControl', cc_send) + def params_thread(self, evt): + while not evt.is_set(): + self.enable_mads = self.params.get_bool("Mads") + time.sleep(0.1) + def run(self): + e = threading.Event() + t = threading.Thread(target=self.params_thread, args=(e, )) rk = Ratekeeper(100, print_delay_threshold=None) - while True: - self.update() - CC, lac_log = self.state_control() - self.publish(CC, lac_log) - rk.monitor_time() + try: + t.start() + while True: + self.update() + CC, lac_log = self.state_control() + self.publish(CC, lac_log) + rk.monitor_time() + finally: + e.set() + t.join() def main(): config_realtime_process(4, Priority.CTRL_HIGH) diff --git a/sunnypilot/__init__.py b/sunnypilot/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/sunnypilot/selfdrive/__init__.py b/sunnypilot/selfdrive/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/sunnypilot/selfdrive/car/__init__.py b/sunnypilot/selfdrive/car/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/sunnypilot/selfdrive/car/hyundai/__init__.py b/sunnypilot/selfdrive/car/hyundai/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/sunnypilot/selfdrive/car/hyundai/carcontroller.py b/sunnypilot/selfdrive/car/hyundai/carcontroller.py deleted file mode 100644 index 3191a3ad02..0000000000 --- a/sunnypilot/selfdrive/car/hyundai/carcontroller.py +++ /dev/null @@ -1,38 +0,0 @@ -from abc import abstractmethod -from collections import namedtuple - -from opendbc.car import DT_CTRL, structs -from opendbc.car.can_definitions import CanData -from opendbc.car.interfaces import CarStateBase, CarControllerBase - -MadsDataSP = namedtuple("MadsDataSP", - ["enabled_toggle", "lat_active", "disengaging", "paused"]) - - -class CarControllerSP(CarControllerBase): - def __init__(self, dbc_name: str, CP: structs.CarParams): - super().__init__(dbc_name, CP) - self.lat_disengage_blink = 0 - self.lat_disengage_init = False - self.prev_lat_active = False - - # display LFA "white_wheel" and LKAS "White car + lanes" when not CC.latActive - def mads_status_update(self, CS: CarStateBase, CC: structs.CarControl) -> MadsDataSP: - if CC.latActive: - self.lat_disengage_init = False - elif self.prev_lat_active: - self.lat_disengage_init = True - - if not self.lat_disengage_init: - self.lat_disengage_blink = self.frame - - paused = CC.madsActive and not CC.latActive - disengaging = (self.frame - self.lat_disengage_blink) * DT_CTRL < 1.0 if self.lat_disengage_init else False - - self.prev_lat_active = CC.latActive - - return MadsDataSP(CS.mads_enabled_toggle, CC.latActive, disengaging, paused) - - @abstractmethod - def update(self, CC: structs.CarControl, CS: CarStateBase, now_nanos: int) -> tuple[structs.CarControl.Actuators, list[CanData]]: - pass diff --git a/sunnypilot/selfdrive/car/interfaces.py b/sunnypilot/selfdrive/car/interfaces.py deleted file mode 100644 index d143460dcb..0000000000 --- a/sunnypilot/selfdrive/car/interfaces.py +++ /dev/null @@ -1,13 +0,0 @@ -from abc import ABC - -from opendbc.car import structs - -from openpilot.sunnypilot.mads.mads import MadsParams - - -class CarStateBaseSP(ABC): - def __init__(self, CP: structs.CarParams): - self.alt_button = 0 - self.mads_enabled_toggle = MadsParams().read_param("Mads") - - self.main_cruise_enabled = False