mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-15 19:42:04 +08:00
simplify
This commit is contained in:
+9
@@ -1,4 +1,5 @@
|
||||
from cereal import car
|
||||
from openpilot.common.conversions import Conversions as CV
|
||||
from openpilot.selfdrive.car import DT_CTRL
|
||||
from openpilot.selfdrive.car.hyundai import hyundaicanfd, hyundaican
|
||||
from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, Buttons, CANFD_CAR, LEGACY_SAFETY_MODE_CAR
|
||||
@@ -8,11 +9,19 @@ from openpilot.selfdrive.controls.lib.sunnypilot.custom_stock_longitudinal_contr
|
||||
ButtonType = car.CarState.ButtonEvent.Type
|
||||
SET_SPEED_BUTTONS = (ButtonType.accelCruise, ButtonType.decelCruise)
|
||||
|
||||
HYUNDAI_V_CRUISE_MIN = {
|
||||
True: 30,
|
||||
False: int(20 * CV.MPH_TO_KPH),
|
||||
}
|
||||
|
||||
|
||||
class CustomStockLongitudinalController(CustomStockLongitudinalControllerBase):
|
||||
def __init__(self, car_controller, CP):
|
||||
super().__init__(car_controller, CP)
|
||||
|
||||
def get_set_point(self, is_metric: bool) -> float:
|
||||
return HYUNDAI_V_CRUISE_MIN[is_metric]
|
||||
|
||||
def get_set_speed_buttons(self, CS: car.CarState) -> bool:
|
||||
return any(be.type in SET_SPEED_BUTTONS for be in CS.out.buttonEvents)
|
||||
|
||||
|
||||
+5
-4
@@ -6,7 +6,6 @@ import cereal.messaging as messaging
|
||||
from openpilot.common.conversions import Conversions as CV
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.selfdrive.car import DT_CTRL
|
||||
from openpilot.selfdrive.controls.lib.sunnypilot.custom_stock_longitudinal_controller.definitions import MinimumSetPoint
|
||||
|
||||
SendCan = tuple[int, bytes, int]
|
||||
|
||||
@@ -28,8 +27,6 @@ class CustomStockLongitudinalControllerBase(ABC):
|
||||
else:
|
||||
self.car_controller.sm = messaging.SubMaster([self.long_plan_sp])
|
||||
|
||||
self.min_set_point = MinimumSetPoint(CP)
|
||||
|
||||
self.params = Params()
|
||||
self.last_speed_limit_sign_tap_prev = False
|
||||
self.speed_limit = 0.
|
||||
@@ -195,6 +192,10 @@ class CustomStockLongitudinalControllerBase(ABC):
|
||||
def create_mock_button_messages(self, CS: car.CarState, CC: car.CarControl) -> list[SendCan]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_set_point(self, is_metric: bool) -> float:
|
||||
pass
|
||||
|
||||
def update(self, CS: car.CarState) -> None:
|
||||
self.car_controller.sm.update(0)
|
||||
|
||||
@@ -207,7 +208,7 @@ class CustomStockLongitudinalControllerBase(ABC):
|
||||
self.v_tsc = self.car_controller.sm[self.long_plan_sp].visionTurnSpeed
|
||||
self.m_tsc = self.car_controller.sm[self.long_plan_sp].turnSpeed
|
||||
|
||||
self.v_cruise_min = self.min_set_point.get_set_point(CS.params_list.is_metric)
|
||||
self.v_cruise_min = self.get_set_point(CS.params_list.is_metric)
|
||||
|
||||
if not self.last_speed_limit_sign_tap_prev and CS.params_list.last_speed_limit_sign_tap:
|
||||
self.sl_force_active_timer = self.car_controller.frame
|
||||
|
||||
@@ -8,10 +8,6 @@ HONDA_V_CRUISE_MIN = {
|
||||
True: 40,
|
||||
False: int(25 * CV.MPH_TO_KPH),
|
||||
}
|
||||
HYUNDAI_V_CRUISE_MIN = {
|
||||
True: 30,
|
||||
False: int(20 * CV.MPH_TO_KPH),
|
||||
}
|
||||
MAZDA_V_CRUISE_MIN = {
|
||||
True: 30,
|
||||
False: int(20 * CV.MPH_TO_KPH),
|
||||
@@ -33,8 +29,6 @@ class MinimumSetPoint:
|
||||
if is_metric != self.is_metric_prev:
|
||||
if self.CP.carName == "honda":
|
||||
self.set_point = HONDA_V_CRUISE_MIN[is_metric]
|
||||
elif self.CP.carName == "hyundai":
|
||||
self.set_point = HYUNDAI_V_CRUISE_MIN[is_metric]
|
||||
elif self.CP.carName == "chrysler":
|
||||
self.set_point = FCA_V_CRUISE_MIN[is_metric]
|
||||
elif self.CP.carName == "mazda":
|
||||
|
||||
Reference in New Issue
Block a user