Fix some car typing (#33256)

* ??

* fix these

* more typing and some fixes

* fix

* rm this for now

* fix
old-commit-hash: 2dab8b31f2
This commit is contained in:
Shane Smiskol 2024-08-11 21:12:46 -05:00 committed by GitHub
parent ac9370addc
commit b014b1cc90
4 changed files with 20 additions and 18 deletions

View File

@ -4,6 +4,7 @@ from openpilot.selfdrive.car import DT_CTRL, apply_driver_steer_torque_limits, c
from openpilot.selfdrive.car.conversions import Conversions as CV
from openpilot.selfdrive.car.helpers import clip
from openpilot.selfdrive.car.hyundai import hyundaicanfd, hyundaican
from openpilot.selfdrive.car.hyundai.carstate import CarState
from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus
from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, Buttons, CarControllerParams, CANFD_CAR, CAR
from openpilot.selfdrive.car.interfaces import CarControllerBase
@ -169,7 +170,7 @@ class CarController(CarControllerBase):
self.frame += 1
return new_actuators, can_sends
def create_button_messages(self, CC: car.CarControl, CS: car.CarState, use_clu11: bool):
def create_button_messages(self, CC: car.CarControl, CS: CarState, use_clu11: bool):
can_sends = []
if use_clu11:
if CC.cruiseControl.cancel:

View File

@ -87,7 +87,7 @@ def get_torque_params():
# generic car and radar interfaces
class CarInterfaceBase(ABC):
def __init__(self, CP, CarController, CarState):
def __init__(self, CP: car.CarParams, CarController, CarState):
self.CP = CP
self.frame = 0
@ -97,7 +97,7 @@ class CarInterfaceBase(ABC):
self.silent_steer_warning = True
self.v_ego_cluster_seen = False
self.CS = CarState(CP)
self.CS: CarStateBase = CarState(CP)
self.cp = self.CS.get_can_parser(CP)
self.cp_cam = self.CS.get_cam_can_parser(CP)
self.cp_adas = self.CS.get_adas_can_parser(CP)
@ -116,7 +116,7 @@ class CarInterfaceBase(ABC):
return ACCEL_MIN, ACCEL_MAX
@classmethod
def get_non_essential_params(cls, candidate: str):
def get_non_essential_params(cls, candidate: str) -> car.CarParams:
"""
Parameters essential to controlling the car may be incomplete or wrong without FW versions or fingerprints.
"""
@ -151,7 +151,7 @@ class CarInterfaceBase(ABC):
@staticmethod
@abstractmethod
def _get_params(ret: car.CarParams, candidate, fingerprint: dict[int, dict[int, int]],
car_fw: list[car.CarParams.CarFw], experimental_long: bool, docs: bool):
car_fw: list[car.CarParams.CarFw], experimental_long: bool, docs: bool) -> car.CarParams:
raise NotImplementedError
@staticmethod
@ -211,7 +211,7 @@ class CarInterfaceBase(ABC):
return ret
@staticmethod
def configure_torque_tune(candidate, tune, steering_angle_deadzone_deg=0.0, use_steering_angle=True):
def configure_torque_tune(candidate: str, tune: car.CarParams.LateralTuning, steering_angle_deadzone_deg: float = 0.0, use_steering_angle: bool = True):
params = get_torque_params()[candidate]
tune.init('torque')
@ -342,10 +342,10 @@ class CarInterfaceBase(ABC):
class RadarInterfaceBase(ABC):
def __init__(self, CP):
def __init__(self, CP: car.CarParams):
self.CP = CP
self.rcp = None
self.pts = {}
self.pts: dict[int, car.RadarData.RadarPoint] = {}
self.delay = 0
self.radar_ts = CP.radarTimeStep
self.frame = 0
@ -358,7 +358,7 @@ class RadarInterfaceBase(ABC):
class CarStateBase(ABC):
def __init__(self, CP):
def __init__(self, CP: car.CarParams):
self.CP = CP
self.car_fingerprint = CP.carFingerprint
self.out = car.CarState.new_message()
@ -380,6 +380,10 @@ class CarStateBase(ABC):
K = get_kalman_gain(DT_CTRL, np.array(A), np.array(C), np.array(Q), R)
self.v_ego_kf = KF1D(x0=x0, A=A, C=C[0], K=K)
@abstractmethod
def update(self, *args) -> car.CarState:
pass
def update_speed_kf(self, v_ego_raw):
if abs(v_ego_raw - self.v_ego_kf.x[0][0]) > 2.0: # Prevent large accelerations when car starts at non zero speed
self.v_ego_kf.set_x([[v_ego_raw], [0.0]])
@ -462,12 +466,12 @@ class CarStateBase(ABC):
class CarControllerBase(ABC):
def __init__(self, dbc_name: str, CP):
def __init__(self, dbc_name: str, CP: car.CarParams):
self.CP = CP
self.frame = 0
@abstractmethod
def update(self, CC: car.CarControl.Actuators, CS: car.CarState, now_nanos: int) -> tuple[car.CarControl.Actuators, list[CanData]]:
def update(self, CC: car.CarControl, CS: CarStateBase, now_nanos: int) -> tuple[car.CarControl.Actuators, list[CanData]]:
pass

View File

@ -1,4 +1,7 @@
from cereal import car
from openpilot.selfdrive.car.interfaces import CarStateBase
class CarState(CarStateBase):
pass
def update(self, *args) -> car.CarState:
pass

View File

@ -1,10 +1,5 @@
from cereal import car
from openpilot.selfdrive.car.subaru.fingerprints import FW_VERSIONS
Ecu = car.CarParams.Ecu
ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()}
class TestSubaruFingerprint:
def test_fw_version_format(self):
@ -13,4 +8,3 @@ class TestSubaruFingerprint:
fw_size = len(fws[0])
for fw in fws:
assert len(fw) == fw_size, f"{platform} {ecu}: {len(fw)} {fw_size}"