mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-07-14 01:12:06 +08:00
cars: introduce "platformconfig" to be a configuration for all relevant car information (#31542)
* this is decent * make sure the docs don't change for now * hackery * these can live here
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
# functions common among cars
|
||||
from collections import namedtuple
|
||||
from typing import Dict, List, Optional
|
||||
from dataclasses import dataclass
|
||||
from enum import ReprEnum
|
||||
from typing import Dict, List, Optional, Union
|
||||
|
||||
import capnp
|
||||
|
||||
from cereal import car
|
||||
from openpilot.common.numpy_fast import clip, interp
|
||||
from openpilot.selfdrive.car.docs_definitions import CarInfo
|
||||
|
||||
|
||||
# kg of standard extra cargo to count for drive, gas, etc...
|
||||
@@ -73,7 +76,9 @@ def scale_tire_stiffness(mass, wheelbase, center_to_front, tire_stiffness_factor
|
||||
return tire_stiffness_front, tire_stiffness_rear
|
||||
|
||||
|
||||
def dbc_dict(pt_dbc, radar_dbc, chassis_dbc=None, body_dbc=None) -> Dict[str, str]:
|
||||
DbcDict = Dict[str, str]
|
||||
|
||||
def dbc_dict(pt_dbc, radar_dbc, chassis_dbc=None, body_dbc=None) -> DbcDict:
|
||||
return {'pt': pt_dbc, 'radar': radar_dbc, 'chassis': chassis_dbc, 'body': body_dbc}
|
||||
|
||||
|
||||
@@ -236,3 +241,33 @@ class CanSignalRateCalculator:
|
||||
self.previous_value = current_value
|
||||
|
||||
return self.rate
|
||||
|
||||
|
||||
CarInfos = Union[CarInfo, List[CarInfo]]
|
||||
|
||||
@dataclass(order=True)
|
||||
class PlatformConfig:
|
||||
platform_str: str
|
||||
car_info: CarInfos
|
||||
dbc_dict: DbcDict
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(self.platform_str)
|
||||
|
||||
|
||||
class Platforms(str, ReprEnum):
|
||||
config: PlatformConfig
|
||||
|
||||
def __new__(cls, platform_config: PlatformConfig):
|
||||
member = str.__new__(cls, platform_config.platform_str)
|
||||
member.config = platform_config
|
||||
member._value_ = platform_config.platform_str
|
||||
return member
|
||||
|
||||
@classmethod
|
||||
def create_dbc_map(cls) -> Dict[str, DbcDict]:
|
||||
return {p.config.platform_str: p.config.dbc_dict for p in cls}
|
||||
|
||||
@classmethod
|
||||
def create_carinfo_map(cls) -> Dict[str, CarInfos]:
|
||||
return {p.config.platform_str: p.config.car_info for p in cls}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
from enum import StrEnum
|
||||
from typing import Dict
|
||||
|
||||
from cereal import car
|
||||
from openpilot.selfdrive.car import dbc_dict
|
||||
from openpilot.selfdrive.car import PlatformConfig, Platforms, dbc_dict
|
||||
from openpilot.selfdrive.car.docs_definitions import CarInfo
|
||||
from openpilot.selfdrive.car.fw_query_definitions import FwQueryConfig, Request, StdQueries
|
||||
|
||||
@@ -22,13 +19,12 @@ class CarControllerParams:
|
||||
pass
|
||||
|
||||
|
||||
class CAR(StrEnum):
|
||||
BODY = "COMMA BODY"
|
||||
|
||||
|
||||
CAR_INFO: Dict[str, CarInfo] = {
|
||||
CAR.BODY: CarInfo("comma body", package="All"),
|
||||
}
|
||||
class CAR(Platforms):
|
||||
BODY = PlatformConfig(
|
||||
"COMMA BODY",
|
||||
CarInfo("comma body", package="All"),
|
||||
dbc_dict('comma_body', None),
|
||||
)
|
||||
|
||||
|
||||
FW_QUERY_CONFIG = FwQueryConfig(
|
||||
@@ -41,7 +37,5 @@ FW_QUERY_CONFIG = FwQueryConfig(
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
DBC = {
|
||||
CAR.BODY: dbc_dict('comma_body', None),
|
||||
}
|
||||
CAR_INFO = CAR.create_carinfo_map()
|
||||
DBC = CAR.create_dbc_map()
|
||||
|
||||
Reference in New Issue
Block a user