wip
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum, IntFlag, StrEnum
|
||||
from typing import Dict, List, Union
|
||||
from enum import Enum, IntFlag
|
||||
|
||||
from cereal import car
|
||||
from panda.python import uds
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.selfdrive.car import dbc_dict
|
||||
from openpilot.selfdrive.car.docs_definitions import CarFootnote, CarHarness, CarInfo, CarParts, Tool, Column
|
||||
from openpilot.selfdrive.car import CarSpecs, DbcDict, PlatformConfig, Platforms, dbc_dict
|
||||
from openpilot.selfdrive.car.docs_definitions import CarFootnote, CarHarness, CarDocs, CarParts, Tool, Column
|
||||
from openpilot.selfdrive.car.fw_query_definitions import FwQueryConfig, Request, StdQueries, p16
|
||||
|
||||
Ecu = car.CarParams.Ecu
|
||||
@@ -21,7 +20,7 @@ class CarControllerParams:
|
||||
self.STEER_DRIVER_MULTIPLIER = 50 # weight driver torque heavily
|
||||
self.STEER_DRIVER_FACTOR = 1 # from dbc
|
||||
|
||||
if CP.carFingerprint in GLOBAL_GEN2:
|
||||
if CP.flags & SubaruFlags.GLOBAL_GEN2:
|
||||
self.STEER_MAX = 1000
|
||||
self.STEER_DELTA_UP = 40
|
||||
self.STEER_DELTA_DOWN = 40
|
||||
@@ -57,9 +56,20 @@ class CarControllerParams:
|
||||
|
||||
|
||||
class SubaruFlags(IntFlag):
|
||||
# Detected flags
|
||||
SEND_INFOTAINMENT = 1
|
||||
DISABLE_EYESIGHT = 2
|
||||
|
||||
# Static flags
|
||||
GLOBAL_GEN2 = 4
|
||||
|
||||
# Cars that temporarily fault when steering angle rate is greater than some threshold.
|
||||
# Appears to be all torque-based cars produced around 2019 - present
|
||||
STEER_RATE_LIMITED = 8
|
||||
PREGLOBAL = 16
|
||||
HYBRID = 32
|
||||
LKAS_ANGLE = 64
|
||||
|
||||
|
||||
GLOBAL_ES_ADDR = 0x787
|
||||
GEN2_ES_BUTTONS_DID = b'\x11\x30'
|
||||
@@ -71,27 +81,6 @@ class CanBus:
|
||||
camera = 2
|
||||
|
||||
|
||||
class CAR(StrEnum):
|
||||
# Global platform
|
||||
ASCENT = "SUBARU ASCENT LIMITED 2019"
|
||||
ASCENT_2023 = "SUBARU ASCENT 2023"
|
||||
IMPREZA = "SUBARU IMPREZA LIMITED 2019"
|
||||
IMPREZA_2020 = "SUBARU IMPREZA SPORT 2020"
|
||||
FORESTER = "SUBARU FORESTER 2019"
|
||||
OUTBACK = "SUBARU OUTBACK 6TH GEN"
|
||||
CROSSTREK_HYBRID = "SUBARU CROSSTREK HYBRID 2020"
|
||||
FORESTER_HYBRID = "SUBARU FORESTER HYBRID 2020"
|
||||
LEGACY = "SUBARU LEGACY 7TH GEN"
|
||||
FORESTER_2022 = "SUBARU FORESTER 2022"
|
||||
OUTBACK_2023 = "SUBARU OUTBACK 7TH GEN"
|
||||
|
||||
# Pre-global
|
||||
FORESTER_PREGLOBAL = "SUBARU FORESTER 2017 - 2018"
|
||||
LEGACY_PREGLOBAL = "SUBARU LEGACY 2015 - 2018"
|
||||
OUTBACK_PREGLOBAL = "SUBARU OUTBACK 2015 - 2017"
|
||||
OUTBACK_PREGLOBAL_2018 = "SUBARU OUTBACK 2018 - 2019"
|
||||
|
||||
|
||||
class Footnote(Enum):
|
||||
GLOBAL = CarFootnote(
|
||||
"In the non-US market, openpilot requires the car to come equipped with EyeSight with Lane Keep Assistance.",
|
||||
@@ -102,10 +91,10 @@ class Footnote(Enum):
|
||||
|
||||
|
||||
@dataclass
|
||||
class SubaruCarInfo(CarInfo):
|
||||
class SubaruCarDocs(CarDocs):
|
||||
package: str = "EyeSight Driver Assistance"
|
||||
car_parts: CarParts = field(default_factory=CarParts.common([CarHarness.subaru_a]))
|
||||
footnotes: List[Enum] = field(default_factory=lambda: [Footnote.GLOBAL])
|
||||
footnotes: list[Enum] = field(default_factory=lambda: [Footnote.GLOBAL])
|
||||
|
||||
def init_make(self, CP: car.CarParams):
|
||||
self.car_parts.parts.extend([Tool.socket_8mm_deep, Tool.pry_tool])
|
||||
@@ -113,68 +102,180 @@ class SubaruCarInfo(CarInfo):
|
||||
if CP.experimentalLongitudinalAvailable:
|
||||
self.footnotes.append(Footnote.EXP_LONG)
|
||||
|
||||
CAR_INFO: Dict[str, Union[SubaruCarInfo, List[SubaruCarInfo]]] = {
|
||||
CAR.ASCENT: SubaruCarInfo("Subaru Ascent 2019-21", "All"),
|
||||
CAR.OUTBACK: SubaruCarInfo("Subaru Outback 2020-22", "All", car_parts=CarParts.common([CarHarness.subaru_b])),
|
||||
CAR.LEGACY: SubaruCarInfo("Subaru Legacy 2020-22", "All", car_parts=CarParts.common([CarHarness.subaru_b])),
|
||||
CAR.IMPREZA: [
|
||||
SubaruCarInfo("Subaru Impreza 2017-19"),
|
||||
SubaruCarInfo("Subaru Crosstrek 2018-19", video_link="https://youtu.be/Agww7oE1k-s?t=26"),
|
||||
SubaruCarInfo("Subaru XV 2018-19", video_link="https://youtu.be/Agww7oE1k-s?t=26"),
|
||||
],
|
||||
CAR.IMPREZA_2020: [
|
||||
SubaruCarInfo("Subaru Impreza 2020-22"),
|
||||
SubaruCarInfo("Subaru Crosstrek 2020-23"),
|
||||
SubaruCarInfo("Subaru XV 2020-21"),
|
||||
],
|
||||
|
||||
@dataclass
|
||||
class SubaruPlatformConfig(PlatformConfig):
|
||||
dbc_dict: DbcDict = field(default_factory=lambda: dbc_dict('subaru_global_2017_generated', None))
|
||||
|
||||
def init(self):
|
||||
if self.flags & SubaruFlags.HYBRID:
|
||||
self.dbc_dict = dbc_dict('subaru_global_2020_hybrid_generated', None)
|
||||
|
||||
|
||||
@dataclass
|
||||
class SubaruGen2PlatformConfig(SubaruPlatformConfig):
|
||||
def init(self):
|
||||
super().init()
|
||||
self.flags |= SubaruFlags.GLOBAL_GEN2
|
||||
if not (self.flags & SubaruFlags.LKAS_ANGLE):
|
||||
self.flags |= SubaruFlags.STEER_RATE_LIMITED
|
||||
|
||||
|
||||
class CAR(Platforms):
|
||||
# Global platform
|
||||
ASCENT = SubaruPlatformConfig(
|
||||
"SUBARU ASCENT LIMITED 2019",
|
||||
[SubaruCarDocs("Subaru Ascent 2019-21", "All")],
|
||||
CarSpecs(mass=2031, wheelbase=2.89, steerRatio=13.5),
|
||||
)
|
||||
OUTBACK = SubaruGen2PlatformConfig(
|
||||
"SUBARU OUTBACK 6TH GEN",
|
||||
[SubaruCarDocs("Subaru Outback 2020-22", "All", car_parts=CarParts.common([CarHarness.subaru_b]))],
|
||||
CarSpecs(mass=1568, wheelbase=2.67, steerRatio=17),
|
||||
)
|
||||
LEGACY = SubaruGen2PlatformConfig(
|
||||
"SUBARU LEGACY 7TH GEN",
|
||||
[SubaruCarDocs("Subaru Legacy 2020-22", "All", car_parts=CarParts.common([CarHarness.subaru_b]))],
|
||||
OUTBACK.specs,
|
||||
)
|
||||
IMPREZA = SubaruPlatformConfig(
|
||||
"SUBARU IMPREZA LIMITED 2019",
|
||||
[
|
||||
SubaruCarDocs("Subaru Impreza 2017-19"),
|
||||
SubaruCarDocs("Subaru Crosstrek 2018-19", video_link="https://youtu.be/Agww7oE1k-s?t=26"),
|
||||
SubaruCarDocs("Subaru XV 2018-19", video_link="https://youtu.be/Agww7oE1k-s?t=26"),
|
||||
],
|
||||
CarSpecs(mass=1568, wheelbase=2.67, steerRatio=15),
|
||||
)
|
||||
IMPREZA_2020 = SubaruPlatformConfig(
|
||||
"SUBARU IMPREZA SPORT 2020",
|
||||
[
|
||||
SubaruCarDocs("Subaru Impreza 2020-22"),
|
||||
SubaruCarDocs("Subaru Crosstrek 2020-23"),
|
||||
SubaruCarDocs("Subaru XV 2020-21"),
|
||||
],
|
||||
CarSpecs(mass=1480, wheelbase=2.67, steerRatio=17),
|
||||
flags=SubaruFlags.STEER_RATE_LIMITED,
|
||||
)
|
||||
# TODO: is there an XV and Impreza too?
|
||||
CAR.CROSSTREK_HYBRID: SubaruCarInfo("Subaru Crosstrek Hybrid 2020", car_parts=CarParts.common([CarHarness.subaru_b])),
|
||||
CAR.FORESTER_HYBRID: SubaruCarInfo("Subaru Forester Hybrid 2020"),
|
||||
CAR.FORESTER: SubaruCarInfo("Subaru Forester 2019-21", "All"),
|
||||
CAR.FORESTER_PREGLOBAL: SubaruCarInfo("Subaru Forester 2017-18"),
|
||||
CAR.LEGACY_PREGLOBAL: SubaruCarInfo("Subaru Legacy 2015-18"),
|
||||
CAR.OUTBACK_PREGLOBAL: SubaruCarInfo("Subaru Outback 2015-17"),
|
||||
CAR.OUTBACK_PREGLOBAL_2018: SubaruCarInfo("Subaru Outback 2018-19"),
|
||||
CAR.FORESTER_2022: SubaruCarInfo("Subaru Forester 2022-24", "All", car_parts=CarParts.common([CarHarness.subaru_c])),
|
||||
CAR.OUTBACK_2023: SubaruCarInfo("Subaru Outback 2023", "All", car_parts=CarParts.common([CarHarness.subaru_d])),
|
||||
CAR.ASCENT_2023: SubaruCarInfo("Subaru Ascent 2023", "All", car_parts=CarParts.common([CarHarness.subaru_d])),
|
||||
}
|
||||
CROSSTREK_HYBRID = SubaruPlatformConfig(
|
||||
"SUBARU CROSSTREK HYBRID 2020",
|
||||
[SubaruCarDocs("Subaru Crosstrek Hybrid 2020", car_parts=CarParts.common([CarHarness.subaru_b]))],
|
||||
CarSpecs(mass=1668, wheelbase=2.67, steerRatio=17),
|
||||
flags=SubaruFlags.HYBRID,
|
||||
)
|
||||
FORESTER = SubaruPlatformConfig(
|
||||
"SUBARU FORESTER 2019",
|
||||
[SubaruCarDocs("Subaru Forester 2019-21", "All")],
|
||||
CarSpecs(mass=1568, wheelbase=2.67, steerRatio=17),
|
||||
flags=SubaruFlags.STEER_RATE_LIMITED,
|
||||
)
|
||||
FORESTER_HYBRID = SubaruPlatformConfig(
|
||||
"SUBARU FORESTER HYBRID 2020",
|
||||
[SubaruCarDocs("Subaru Forester Hybrid 2020")],
|
||||
FORESTER.specs,
|
||||
flags=SubaruFlags.HYBRID,
|
||||
)
|
||||
# Pre-global
|
||||
FORESTER_PREGLOBAL = SubaruPlatformConfig(
|
||||
"SUBARU FORESTER 2017 - 2018",
|
||||
[SubaruCarDocs("Subaru Forester 2017-18")],
|
||||
CarSpecs(mass=1568, wheelbase=2.67, steerRatio=20),
|
||||
dbc_dict('subaru_forester_2017_generated', None),
|
||||
flags=SubaruFlags.PREGLOBAL,
|
||||
)
|
||||
LEGACY_PREGLOBAL = SubaruPlatformConfig(
|
||||
"SUBARU LEGACY 2015 - 2018",
|
||||
[SubaruCarDocs("Subaru Legacy 2015-18")],
|
||||
CarSpecs(mass=1568, wheelbase=2.67, steerRatio=12.5),
|
||||
dbc_dict('subaru_outback_2015_generated', None),
|
||||
flags=SubaruFlags.PREGLOBAL,
|
||||
)
|
||||
OUTBACK_PREGLOBAL = SubaruPlatformConfig(
|
||||
"SUBARU OUTBACK 2015 - 2017",
|
||||
[SubaruCarDocs("Subaru Outback 2015-17")],
|
||||
FORESTER_PREGLOBAL.specs,
|
||||
dbc_dict('subaru_outback_2015_generated', None),
|
||||
flags=SubaruFlags.PREGLOBAL,
|
||||
)
|
||||
OUTBACK_PREGLOBAL_2018 = SubaruPlatformConfig(
|
||||
"SUBARU OUTBACK 2018 - 2019",
|
||||
[SubaruCarDocs("Subaru Outback 2018-19")],
|
||||
FORESTER_PREGLOBAL.specs,
|
||||
dbc_dict('subaru_outback_2019_generated', None),
|
||||
flags=SubaruFlags.PREGLOBAL,
|
||||
)
|
||||
# Angle LKAS
|
||||
FORESTER_2022 = SubaruPlatformConfig(
|
||||
"SUBARU FORESTER 2022",
|
||||
[SubaruCarDocs("Subaru Forester 2022-24", "All", car_parts=CarParts.common([CarHarness.subaru_c]))],
|
||||
FORESTER.specs,
|
||||
flags=SubaruFlags.LKAS_ANGLE,
|
||||
)
|
||||
OUTBACK_2023 = SubaruGen2PlatformConfig(
|
||||
"SUBARU OUTBACK 7TH GEN",
|
||||
[SubaruCarDocs("Subaru Outback 2023", "All", car_parts=CarParts.common([CarHarness.subaru_d]))],
|
||||
OUTBACK.specs,
|
||||
flags=SubaruFlags.LKAS_ANGLE,
|
||||
)
|
||||
ASCENT_2023 = SubaruGen2PlatformConfig(
|
||||
"SUBARU ASCENT 2023",
|
||||
[SubaruCarDocs("Subaru Ascent 2023", "All", car_parts=CarParts.common([CarHarness.subaru_d]))],
|
||||
ASCENT.specs,
|
||||
flags=SubaruFlags.LKAS_ANGLE,
|
||||
)
|
||||
|
||||
LKAS_ANGLE = {CAR.FORESTER_2022, CAR.OUTBACK_2023, CAR.ASCENT_2023}
|
||||
GLOBAL_GEN2 = {CAR.OUTBACK, CAR.LEGACY, CAR.OUTBACK_2023, CAR.ASCENT_2023}
|
||||
PREGLOBAL_CARS = {CAR.FORESTER_PREGLOBAL, CAR.LEGACY_PREGLOBAL, CAR.OUTBACK_PREGLOBAL, CAR.OUTBACK_PREGLOBAL_2018}
|
||||
HYBRID_CARS = {CAR.CROSSTREK_HYBRID, CAR.FORESTER_HYBRID}
|
||||
|
||||
# Cars that temporarily fault when steering angle rate is greater than some threshold.
|
||||
# Appears to be all torque-based cars produced around 2019 - present
|
||||
STEER_RATE_LIMITED = GLOBAL_GEN2 | {CAR.IMPREZA_2020, CAR.FORESTER}
|
||||
|
||||
SUBARU_VERSION_REQUEST = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + \
|
||||
p16(uds.DATA_IDENTIFIER_TYPE.APPLICATION_DATA_IDENTIFICATION)
|
||||
SUBARU_VERSION_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x40]) + \
|
||||
p16(uds.DATA_IDENTIFIER_TYPE.APPLICATION_DATA_IDENTIFICATION)
|
||||
|
||||
# The EyeSight ECU takes 10s to respond to SUBARU_VERSION_REQUEST properly,
|
||||
# log this alternate manufacturer-specific query
|
||||
SUBARU_ALT_VERSION_REQUEST = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + \
|
||||
p16(0xf100)
|
||||
SUBARU_ALT_VERSION_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x40]) + \
|
||||
p16(0xf100)
|
||||
|
||||
FW_QUERY_CONFIG = FwQueryConfig(
|
||||
requests=[
|
||||
Request(
|
||||
[StdQueries.TESTER_PRESENT_REQUEST, SUBARU_VERSION_REQUEST],
|
||||
[StdQueries.TESTER_PRESENT_RESPONSE, SUBARU_VERSION_RESPONSE],
|
||||
whitelist_ecus=[Ecu.abs, Ecu.eps, Ecu.fwdCamera, Ecu.engine, Ecu.transmission],
|
||||
logging=True,
|
||||
),
|
||||
# Non-OBD requests
|
||||
# Some Eyesight modules fail on TESTER_PRESENT_REQUEST
|
||||
# TODO: check if this resolves the fingerprinting issue for the 2023 Ascent and other new Subaru cars
|
||||
Request(
|
||||
[SUBARU_VERSION_REQUEST],
|
||||
[SUBARU_VERSION_RESPONSE],
|
||||
whitelist_ecus=[Ecu.fwdCamera],
|
||||
bus=0,
|
||||
),
|
||||
Request(
|
||||
[SUBARU_ALT_VERSION_REQUEST],
|
||||
[SUBARU_ALT_VERSION_RESPONSE],
|
||||
whitelist_ecus=[Ecu.fwdCamera],
|
||||
bus=0,
|
||||
logging=True,
|
||||
),
|
||||
Request(
|
||||
[StdQueries.DEFAULT_DIAGNOSTIC_REQUEST, StdQueries.TESTER_PRESENT_REQUEST, SUBARU_VERSION_REQUEST],
|
||||
[StdQueries.DEFAULT_DIAGNOSTIC_RESPONSE, StdQueries.TESTER_PRESENT_RESPONSE, SUBARU_VERSION_RESPONSE],
|
||||
whitelist_ecus=[Ecu.fwdCamera],
|
||||
bus=0,
|
||||
logging=True,
|
||||
),
|
||||
# Non-OBD requests
|
||||
Request(
|
||||
[StdQueries.TESTER_PRESENT_REQUEST, SUBARU_VERSION_REQUEST],
|
||||
[StdQueries.TESTER_PRESENT_RESPONSE, SUBARU_VERSION_RESPONSE],
|
||||
whitelist_ecus=[Ecu.abs, Ecu.eps, Ecu.fwdCamera, Ecu.engine, Ecu.transmission],
|
||||
bus=0,
|
||||
),
|
||||
# GEN2 powertrain bus query
|
||||
Request(
|
||||
[StdQueries.TESTER_PRESENT_REQUEST, SUBARU_VERSION_REQUEST],
|
||||
[StdQueries.TESTER_PRESENT_RESPONSE, SUBARU_VERSION_RESPONSE],
|
||||
@@ -185,24 +286,11 @@ FW_QUERY_CONFIG = FwQueryConfig(
|
||||
],
|
||||
# We don't get the EPS from non-OBD queries on GEN2 cars. Note that we still attempt to match when it exists
|
||||
non_essential_ecus={
|
||||
Ecu.eps: list(GLOBAL_GEN2),
|
||||
Ecu.eps: list(CAR.with_flags(SubaruFlags.GLOBAL_GEN2)),
|
||||
}
|
||||
)
|
||||
|
||||
DBC = {
|
||||
CAR.ASCENT: dbc_dict('subaru_global_2017_generated', None),
|
||||
CAR.ASCENT_2023: dbc_dict('subaru_global_2017_generated', None),
|
||||
CAR.IMPREZA: dbc_dict('subaru_global_2017_generated', None),
|
||||
CAR.IMPREZA_2020: dbc_dict('subaru_global_2017_generated', None),
|
||||
CAR.FORESTER: dbc_dict('subaru_global_2017_generated', None),
|
||||
CAR.FORESTER_2022: dbc_dict('subaru_global_2017_generated', None),
|
||||
CAR.OUTBACK: dbc_dict('subaru_global_2017_generated', None),
|
||||
CAR.FORESTER_HYBRID: dbc_dict('subaru_global_2020_hybrid_generated', None),
|
||||
CAR.CROSSTREK_HYBRID: dbc_dict('subaru_global_2020_hybrid_generated', None),
|
||||
CAR.OUTBACK_2023: dbc_dict('subaru_global_2017_generated', None),
|
||||
CAR.LEGACY: dbc_dict('subaru_global_2017_generated', None),
|
||||
CAR.FORESTER_PREGLOBAL: dbc_dict('subaru_forester_2017_generated', None),
|
||||
CAR.LEGACY_PREGLOBAL: dbc_dict('subaru_outback_2015_generated', None),
|
||||
CAR.OUTBACK_PREGLOBAL: dbc_dict('subaru_outback_2015_generated', None),
|
||||
CAR.OUTBACK_PREGLOBAL_2018: dbc_dict('subaru_outback_2019_generated', None),
|
||||
}
|
||||
DBC = CAR.create_dbc_map()
|
||||
|
||||
if __name__ == "__main__":
|
||||
CAR.print_debug(SubaruFlags)
|
||||
|
||||
Reference in New Issue
Block a user