@ -19,7 +19,7 @@ class CarControllerParams:
self . STEER_DRIVER_MULTIPLIER = 50 # weight driver torque heavily
self . STEER_DRIVER_MULTIPLIER = 50 # weight driver torque heavily
self . STEER_DRIVER_FACTOR = 1 # from dbc
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_MAX = 1000
self . STEER_DELTA_UP = 40
self . STEER_DELTA_UP = 40
self . STEER_DELTA_DOWN = 40
self . STEER_DELTA_DOWN = 40
@ -55,6 +55,14 @@ class CarControllerParams:
class SubaruFlags ( IntFlag ) :
class SubaruFlags ( IntFlag ) :
SEND_INFOTAINMENT = 1
SEND_INFOTAINMENT = 1
DISABLE_EYESIGHT = 2
DISABLE_EYESIGHT = 2
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
GLOBAL_ES_ADDR = 0x787
@ -89,10 +97,14 @@ class SubaruCarInfo(CarInfo):
self . footnotes . append ( Footnote . EXP_LONG )
self . footnotes . append ( Footnote . EXP_LONG )
@dataclass ( frozen = True )
@dataclass
class SubaruPlatformConfig ( PlatformConfig ) :
class SubaruPlatformConfig ( PlatformConfig ) :
dbc_dict : DbcDict = field ( default_factory = lambda : dbc_dict ( ' subaru_global_2017_generated ' , None ) )
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 )
class CAR ( Platforms ) :
class CAR ( Platforms ) :
# Global platform
# Global platform
@ -105,11 +117,13 @@ class CAR(Platforms):
" SUBARU OUTBACK 6TH GEN " ,
" SUBARU OUTBACK 6TH GEN " ,
SubaruCarInfo ( " Subaru Outback 2020-22 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_b ] ) ) ,
SubaruCarInfo ( " Subaru Outback 2020-22 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_b ] ) ) ,
specs = CarSpecs ( mass = 1568 , wheelbase = 2.67 , steerRatio = 17 ) ,
specs = CarSpecs ( mass = 1568 , wheelbase = 2.67 , steerRatio = 17 ) ,
flags = SubaruFlags . GLOBAL_GEN2 | SubaruFlags . STEER_RATE_LIMITED ,
)
)
LEGACY = SubaruPlatformConfig (
LEGACY = SubaruPlatformConfig (
" SUBARU LEGACY 7TH GEN " ,
" SUBARU LEGACY 7TH GEN " ,
SubaruCarInfo ( " Subaru Legacy 2020-22 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_b ] ) ) ,
SubaruCarInfo ( " Subaru Legacy 2020-22 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_b ] ) ) ,
specs = OUTBACK . specs ,
specs = OUTBACK . specs ,
flags = SubaruFlags . GLOBAL_GEN2 | SubaruFlags . STEER_RATE_LIMITED ,
)
)
IMPREZA = SubaruPlatformConfig (
IMPREZA = SubaruPlatformConfig (
" SUBARU IMPREZA LIMITED 2019 " ,
" SUBARU IMPREZA LIMITED 2019 " ,
@ -128,24 +142,26 @@ class CAR(Platforms):
SubaruCarInfo ( " Subaru XV 2020-21 " ) ,
SubaruCarInfo ( " Subaru XV 2020-21 " ) ,
] ,
] ,
specs = CarSpecs ( mass = 1480 , wheelbase = 2.67 , steerRatio = 17 ) ,
specs = CarSpecs ( mass = 1480 , wheelbase = 2.67 , steerRatio = 17 ) ,
flags = SubaruFlags . STEER_RATE_LIMITED ,
)
)
# TODO: is there an XV and Impreza too?
# TODO: is there an XV and Impreza too?
CROSSTREK_HYBRID = SubaruPlatformConfig (
CROSSTREK_HYBRID = SubaruPlatformConfig (
" SUBARU CROSSTREK HYBRID 2020 " ,
" SUBARU CROSSTREK HYBRID 2020 " ,
SubaruCarInfo ( " Subaru Crosstrek Hybrid 2020 " , car_parts = CarParts . common ( [ CarHarness . subaru_b ] ) ) ,
SubaruCarInfo ( " Subaru Crosstrek Hybrid 2020 " , car_parts = CarParts . common ( [ CarHarness . subaru_b ] ) ) ,
dbc_dict ( ' subaru_global_2020_hybrid_generated ' , None ) ,
specs = CarSpecs ( mass = 1668 , wheelbase = 2.67 , steerRatio = 17 ) ,
specs = CarSpecs ( mass = 1668 , wheelbase = 2.67 , steerRatio = 17 ) ,
flags = SubaruFlags . HYBRID ,
)
)
FORESTER = SubaruPlatformConfig (
FORESTER = SubaruPlatformConfig (
" SUBARU FORESTER 2019 " ,
" SUBARU FORESTER 2019 " ,
SubaruCarInfo ( " Subaru Forester 2019-21 " , " All " ) ,
SubaruCarInfo ( " Subaru Forester 2019-21 " , " All " ) ,
specs = CarSpecs ( mass = 1568 , wheelbase = 2.67 , steerRatio = 17 ) ,
specs = CarSpecs ( mass = 1568 , wheelbase = 2.67 , steerRatio = 17 ) ,
flags = SubaruFlags . STEER_RATE_LIMITED ,
)
)
FORESTER_HYBRID = SubaruPlatformConfig (
FORESTER_HYBRID = SubaruPlatformConfig (
" SUBARU FORESTER HYBRID 2020 " ,
" SUBARU FORESTER HYBRID 2020 " ,
SubaruCarInfo ( " Subaru Forester Hybrid 2020 " ) ,
SubaruCarInfo ( " Subaru Forester Hybrid 2020 " ) ,
dbc_dict ( ' subaru_global_2020_hybrid_generated ' , None ) ,
specs = FORESTER . specs ,
specs = FORESTER . specs ,
flags = SubaruFlags . HYBRID ,
)
)
# Pre-global
# Pre-global
FORESTER_PREGLOBAL = SubaruPlatformConfig (
FORESTER_PREGLOBAL = SubaruPlatformConfig (
@ -153,52 +169,50 @@ class CAR(Platforms):
SubaruCarInfo ( " Subaru Forester 2017-18 " ) ,
SubaruCarInfo ( " Subaru Forester 2017-18 " ) ,
dbc_dict ( ' subaru_forester_2017_generated ' , None ) ,
dbc_dict ( ' subaru_forester_2017_generated ' , None ) ,
specs = CarSpecs ( mass = 1568 , wheelbase = 2.67 , steerRatio = 20 ) ,
specs = CarSpecs ( mass = 1568 , wheelbase = 2.67 , steerRatio = 20 ) ,
flags = SubaruFlags . PREGLOBAL ,
)
)
LEGACY_PREGLOBAL = SubaruPlatformConfig (
LEGACY_PREGLOBAL = SubaruPlatformConfig (
" SUBARU LEGACY 2015 - 2018 " ,
" SUBARU LEGACY 2015 - 2018 " ,
SubaruCarInfo ( " Subaru Legacy 2015-18 " ) ,
SubaruCarInfo ( " Subaru Legacy 2015-18 " ) ,
dbc_dict ( ' subaru_outback_2015_generated ' , None ) ,
dbc_dict ( ' subaru_outback_2015_generated ' , None ) ,
specs = CarSpecs ( mass = 1568 , wheelbase = 2.67 , steerRatio = 12.5 ) ,
specs = CarSpecs ( mass = 1568 , wheelbase = 2.67 , steerRatio = 12.5 ) ,
flags = SubaruFlags . PREGLOBAL ,
)
)
OUTBACK_PREGLOBAL = SubaruPlatformConfig (
OUTBACK_PREGLOBAL = SubaruPlatformConfig (
" SUBARU OUTBACK 2015 - 2017 " ,
" SUBARU OUTBACK 2015 - 2017 " ,
SubaruCarInfo ( " Subaru Outback 2015-17 " ) ,
SubaruCarInfo ( " Subaru Outback 2015-17 " ) ,
dbc_dict ( ' subaru_outback_2015_generated ' , None ) ,
dbc_dict ( ' subaru_outback_2015_generated ' , None ) ,
specs = FORESTER_PREGLOBAL . specs ,
specs = FORESTER_PREGLOBAL . specs ,
flags = SubaruFlags . PREGLOBAL ,
)
)
OUTBACK_PREGLOBAL_2018 = SubaruPlatformConfig (
OUTBACK_PREGLOBAL_2018 = SubaruPlatformConfig (
" SUBARU OUTBACK 2018 - 2019 " ,
" SUBARU OUTBACK 2018 - 2019 " ,
SubaruCarInfo ( " Subaru Outback 2018-19 " ) ,
SubaruCarInfo ( " Subaru Outback 2018-19 " ) ,
dbc_dict ( ' subaru_outback_2019_generated ' , None ) ,
dbc_dict ( ' subaru_outback_2019_generated ' , None ) ,
specs = FORESTER_PREGLOBAL . specs ,
specs = FORESTER_PREGLOBAL . specs ,
flags = SubaruFlags . PREGLOBAL ,
)
)
# Angle LKAS
# Angle LKAS
FORESTER_2022 = SubaruPlatformConfig (
FORESTER_2022 = SubaruPlatformConfig (
" SUBARU FORESTER 2022 " ,
" SUBARU FORESTER 2022 " ,
SubaruCarInfo ( " Subaru Forester 2022-24 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_c ] ) ) ,
SubaruCarInfo ( " Subaru Forester 2022-24 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_c ] ) ) ,
specs = FORESTER . specs ,
specs = FORESTER . specs ,
flags = SubaruFlags . LKAS_ANGLE ,
)
)
OUTBACK_2023 = SubaruPlatformConfig (
OUTBACK_2023 = SubaruPlatformConfig (
" SUBARU OUTBACK 7TH GEN " ,
" SUBARU OUTBACK 7TH GEN " ,
SubaruCarInfo ( " Subaru Outback 2023 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_d ] ) ) ,
SubaruCarInfo ( " Subaru Outback 2023 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_d ] ) ) ,
specs = OUTBACK . specs ,
specs = OUTBACK . specs ,
flags = SubaruFlags . GLOBAL_GEN2 | SubaruFlags . LKAS_ANGLE ,
)
)
ASCENT_2023 = SubaruPlatformConfig (
ASCENT_2023 = SubaruPlatformConfig (
" SUBARU ASCENT 2023 " ,
" SUBARU ASCENT 2023 " ,
SubaruCarInfo ( " Subaru Ascent 2023 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_d ] ) ) ,
SubaruCarInfo ( " Subaru Ascent 2023 " , " All " , car_parts = CarParts . common ( [ CarHarness . subaru_d ] ) ) ,
specs = ASCENT . specs ,
specs = ASCENT . specs ,
flags = SubaruFlags . GLOBAL_GEN2 | 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 ] ) + \
SUBARU_VERSION_REQUEST = bytes ( [ uds . SERVICE_TYPE . READ_DATA_BY_IDENTIFIER ] ) + \
p16 ( uds . DATA_IDENTIFIER_TYPE . APPLICATION_DATA_IDENTIFICATION )
p16 ( uds . DATA_IDENTIFIER_TYPE . APPLICATION_DATA_IDENTIFICATION )
SUBARU_VERSION_RESPONSE = bytes ( [ uds . SERVICE_TYPE . READ_DATA_BY_IDENTIFIER + 0x40 ] ) + \
SUBARU_VERSION_RESPONSE = bytes ( [ uds . SERVICE_TYPE . READ_DATA_BY_IDENTIFIER + 0x40 ] ) + \
@ -235,7 +249,7 @@ 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
# 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 = {
non_essential_ecus = {
Ecu . eps : list ( GLOBAL_GEN2 ) ,
Ecu . eps : list ( CAR . with_flags ( SubaruFlags . GLOBAL_GEN2 ) ) ,
}
}
)
)