Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move car-specific panda flags into opendbc #1589

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions opendbc/car/chrysler/interface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
from panda import Panda
from opendbc.car import get_safety_config, structs
from opendbc.car.chrysler.values import CAR, RAM_HD, RAM_DT, RAM_CARS, ChryslerFlags
from opendbc.car.chrysler.values import CAR, RAM_HD, RAM_DT, RAM_CARS, ChryslerFlags, ChryslerPandaFlags
from opendbc.car.interfaces import CarInterfaceBase


Expand All @@ -19,9 +18,9 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
# safety config
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.chrysler)]
if candidate in RAM_HD:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_CHRYSLER_RAM_HD
ret.safetyConfigs[0].safetyParam |= ChryslerPandaFlags.FLAG_CHRYSLER_RAM_HD.value
elif candidate in RAM_DT:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_CHRYSLER_RAM_DT
ret.safetyConfigs[0].safetyParam |= ChryslerPandaFlags.FLAG_CHRYSLER_RAM_DT.value

CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
if candidate not in RAM_CARS:
Expand Down
5 changes: 5 additions & 0 deletions opendbc/car/chrysler/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
Ecu = CarParams.Ecu


class ChryslerPandaFlags(IntFlag):
FLAG_CHRYSLER_RAM_DT = 1
FLAG_CHRYSLER_RAM_HD = 2


class ChryslerFlags(IntFlag):
# Detected flags
HIGHER_MIN_STEERING_SPEED = 1
Expand Down
7 changes: 3 additions & 4 deletions opendbc/car/ford/interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from panda import Panda
from opendbc.car.common.numpy_fast import interp
from opendbc.car import Bus, get_safety_config, structs
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.ford.fordcan import CanBus
from opendbc.car.ford.values import CarControllerParams, DBC, Ecu, FordFlags, RADAR
from opendbc.car.ford.values import CarControllerParams, DBC, Ecu, FordFlags, RADAR, FordPandaFlags
from opendbc.car.interfaces import CarInterfaceBase

TransmissionType = structs.CarParams.TransmissionType
Expand Down Expand Up @@ -45,11 +44,11 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
# TODO: verify stock AEB compatibility and longitudinal limit safety before shipping to release
ret.experimentalLongitudinalAvailable = ret.radarUnavailable
if experimental_long or not ret.radarUnavailable:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_FORD_LONG_CONTROL
ret.safetyConfigs[-1].safetyParam |= FordPandaFlags.FLAG_FORD_LONG_CONTROL.value
ret.openpilotLongitudinalControl = True

if ret.flags & FordFlags.CANFD:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_FORD_CANFD
ret.safetyConfigs[-1].safetyParam |= FordPandaFlags.FLAG_FORD_CANFD.value
else:
# Lock out if the car does not have needed lateral and longitudinal control APIs.
# Note that we also check CAN for adaptive cruise, but no known signal for LCA exists
Expand Down
5 changes: 5 additions & 0 deletions opendbc/car/ford/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def __init__(self, CP):
pass


class FordPandaFlags(IntFlag):
FLAG_FORD_LONG_CONTROL = 1
FLAG_FORD_CANFD = 2


class FordFlags(IntFlag):
# Static flags
CANFD = 1
Expand Down
7 changes: 3 additions & 4 deletions opendbc/car/gm/interface.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python3
import os
from math import fabs, exp
from panda import Panda

from opendbc.car import get_safety_config, get_friction, structs
from opendbc.car.common.basedir import BASEDIR
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.gm.radar_interface import RADAR_HEADER_MSG
from opendbc.car.gm.values import CAR, CarControllerParams, EV_CAR, CAMERA_ACC_CAR, SDGM_CAR, ALT_ACCS, CanBus
from opendbc.car.gm.values import CAR, CarControllerParams, EV_CAR, CAMERA_ACC_CAR, SDGM_CAR, ALT_ACCS, CanBus, GMPandaFlags
from opendbc.car.interfaces import CarInterfaceBase, TorqueFromLateralAccelCallbackType, FRICTION_THRESHOLD, LatControlInputs, NanoFFModel

TransmissionType = structs.CarParams.TransmissionType
Expand Down Expand Up @@ -98,7 +97,7 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
ret.networkLocation = NetworkLocation.fwdCamera
ret.radarUnavailable = True # no radar
ret.pcmCruise = True
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_GM_HW_CAM
ret.safetyConfigs[0].safetyParam |= GMPandaFlags.FLAG_GM_HW_CAM.value
ret.minEnableSpeed = -1 if candidate in SDGM_CAR else 5 * CV.KPH_TO_MS
ret.minSteerSpeed = 10 * CV.KPH_TO_MS

Expand All @@ -111,7 +110,7 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
if experimental_long:
ret.pcmCruise = False
ret.openpilotLongitudinalControl = True
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_GM_HW_CAM_LONG
ret.safetyConfigs[0].safetyParam |= GMPandaFlags.FLAG_GM_HW_CAM_LONG.value

if candidate in ALT_ACCS:
ret.experimentalLongitudinalAvailable = False
Expand Down
6 changes: 6 additions & 0 deletions opendbc/car/gm/values.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass, field
from enum import IntFlag

from opendbc.car import Bus, PlatformConfig, DbcDict, Platforms, CarSpecs
from opendbc.car.structs import CarParams
Expand Down Expand Up @@ -59,6 +60,11 @@ def __init__(self, CP):
self.BRAKE_LOOKUP_V = [self.MAX_BRAKE, 0.]


class GMPandaFlags(IntFlag):
FLAG_GM_HW_CAM = 1
FLAG_GM_HW_CAM_LONG = 2


@dataclass
class GMCarDocs(CarDocs):
package: str = "Adaptive Cruise Control (ACC)"
Expand Down
11 changes: 5 additions & 6 deletions opendbc/car/honda/interface.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python3
from panda import Panda
from opendbc.car import get_safety_config, structs
from opendbc.car.common.conversions import Conversions as CV
from opendbc.car.common.numpy_fast import interp
from opendbc.car.honda.hondacan import CanBus
from opendbc.car.honda.values import CarControllerParams, HondaFlags, CAR, HONDA_BOSCH, \
HONDA_NIDEC_ALT_SCM_MESSAGES, HONDA_BOSCH_RADARLESS
HONDA_NIDEC_ALT_SCM_MESSAGES, HONDA_BOSCH_RADARLESS, HondaPandaFlags
from opendbc.car.interfaces import CarInterfaceBase
from opendbc.car.disable_ecu import disable_ecu

Expand Down Expand Up @@ -186,17 +185,17 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
ret.flags |= HondaFlags.BOSCH_ALT_BRAKE.value

if ret.flags & HondaFlags.BOSCH_ALT_BRAKE:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HONDA_ALT_BRAKE
ret.safetyConfigs[0].safetyParam |= HondaPandaFlags.FLAG_HONDA_ALT_BRAKE.value

# These cars use alternate SCM messages (SCM_FEEDBACK AND SCM_BUTTON)
if candidate in HONDA_NIDEC_ALT_SCM_MESSAGES:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HONDA_NIDEC_ALT
ret.safetyConfigs[0].safetyParam |= HondaPandaFlags.FLAG_HONDA_NIDEC_ALT.value

if ret.openpilotLongitudinalControl and candidate in HONDA_BOSCH:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HONDA_BOSCH_LONG
ret.safetyConfigs[0].safetyParam |= HondaPandaFlags.FLAG_HONDA_BOSCH_LONG.value

if candidate in HONDA_BOSCH_RADARLESS:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HONDA_RADARLESS
ret.safetyConfigs[0].safetyParam |= HondaPandaFlags.FLAG_HONDA_RADARLESS.value

# min speed to enable ACC. if car can do stop and go, then set enabling speed
# to a negative value, so it won't matter. Otherwise, add 0.5 mph margin to not
Expand Down
7 changes: 7 additions & 0 deletions opendbc/car/honda/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def __init__(self, CP):
self.STEER_LOOKUP_V = [v * -1 for v in CP.lateralParams.torqueV][1:][::-1] + list(CP.lateralParams.torqueV)


class HondaPandaFlags(IntFlag):
FLAG_HONDA_ALT_BRAKE = 1
FLAG_HONDA_BOSCH_LONG = 2
FLAG_HONDA_NIDEC_ALT = 4
FLAG_HONDA_RADARLESS = 8


class HondaFlags(IntFlag):
# Detected flags
# Bosch models with alternate set of LKAS_HUD messages
Expand Down
21 changes: 10 additions & 11 deletions opendbc/car/hyundai/interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from panda import Panda
from opendbc.car import Bus, get_safety_config, structs
from opendbc.car.hyundai.hyundaicanfd import CanBus
from opendbc.car.hyundai.values import HyundaiFlags, CAR, DBC, CANFD_RADAR_SCC_CAR, \
CANFD_UNSUPPORTED_LONGITUDINAL_CAR, \
UNSUPPORTED_LONGITUDINAL_CAR
UNSUPPORTED_LONGITUDINAL_CAR, HyundaiPandaFlags
from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR
from opendbc.car.interfaces import CarInterfaceBase
from opendbc.car.disable_ecu import disable_ecu
Expand Down Expand Up @@ -58,13 +57,13 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
ret.safetyConfigs = cfgs

if ret.flags & HyundaiFlags.CANFD_HDA2:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_CANFD_HDA2
ret.safetyConfigs[-1].safetyParam |= HyundaiPandaFlags.FLAG_HYUNDAI_CANFD_HDA2.value
if ret.flags & HyundaiFlags.CANFD_HDA2_ALT_STEERING:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_CANFD_HDA2_ALT_STEERING
ret.safetyConfigs[-1].safetyParam |= HyundaiPandaFlags.FLAG_HYUNDAI_CANFD_HDA2_ALT_STEERING.value
if ret.flags & HyundaiFlags.CANFD_ALT_BUTTONS:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_CANFD_ALT_BUTTONS
ret.safetyConfigs[-1].safetyParam |= HyundaiPandaFlags.FLAG_HYUNDAI_CANFD_ALT_BUTTONS.value
if ret.flags & HyundaiFlags.CANFD_CAMERA_SCC:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_CAMERA_SCC
ret.safetyConfigs[-1].safetyParam |= HyundaiPandaFlags.FLAG_HYUNDAI_CAMERA_SCC.value

else:
# Shared configuration for non CAN-FD cars
Expand All @@ -86,7 +85,7 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.hyundai, 0)]

if ret.flags & HyundaiFlags.CAMERA_SCC:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HYUNDAI_CAMERA_SCC
ret.safetyConfigs[0].safetyParam |= HyundaiPandaFlags.FLAG_HYUNDAI_CAMERA_SCC.value

# Common lateral control setup

Expand All @@ -96,7 +95,7 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)

if ret.flags & HyundaiFlags.ALT_LIMITS:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_ALT_LIMITS
ret.safetyConfigs[-1].safetyParam |= HyundaiPandaFlags.FLAG_HYUNDAI_ALT_LIMITS.value

# Common longitudinal control setup

Expand All @@ -109,11 +108,11 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime
ret.longitudinalActuatorDelay = 0.5

if ret.openpilotLongitudinalControl:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_LONG
ret.safetyConfigs[-1].safetyParam |= HyundaiPandaFlags.FLAG_HYUNDAI_LONG.value
if ret.flags & HyundaiFlags.HYBRID:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_HYBRID_GAS
ret.safetyConfigs[-1].safetyParam |= HyundaiPandaFlags.FLAG_HYUNDAI_HYBRID_GAS.value
elif ret.flags & HyundaiFlags.EV:
ret.safetyConfigs[-1].safetyParam |= Panda.FLAG_HYUNDAI_EV_GAS
ret.safetyConfigs[-1].safetyParam |= HyundaiPandaFlags.FLAG_HYUNDAI_EV_GAS.value

# Car specific configuration overrides

Expand Down
5 changes: 2 additions & 3 deletions opendbc/car/hyundai/tests/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest

from panda import Panda
from opendbc.car import gen_empty_fingerprint
from opendbc.car.structs import CarParams
from opendbc.car.fw_versions import build_fw_dict
Expand All @@ -12,7 +11,7 @@
from opendbc.car.hyundai.values import CAMERA_SCC_CAR, CANFD_CAR, CAN_GEARS, CAR, CHECKSUM, DATE_FW_ECUS, \
HYBRID_CAR, EV_CAR, FW_QUERY_CONFIG, LEGACY_SAFETY_MODE_CAR, CANFD_FUZZY_WHITELIST, \
UNSUPPORTED_LONGITUDINAL_CAR, PLATFORM_CODE_ECUS, HYUNDAI_VERSION_REQUEST_LONG, \
HyundaiFlags, get_platform_codes
HyundaiFlags, get_platform_codes, HyundaiPandaFlags
from opendbc.car.hyundai.fingerprints import FW_VERSIONS

Ecu = CarParams.Ecu
Expand Down Expand Up @@ -67,7 +66,7 @@ def test_alternate_limits(self):
fingerprint = gen_empty_fingerprint()
for car_model in CAR:
CP = CarInterface.get_params(car_model, fingerprint, [], False, False)
assert bool(CP.flags & HyundaiFlags.ALT_LIMITS) == bool(CP.safetyConfigs[-1].safetyParam & Panda.FLAG_HYUNDAI_ALT_LIMITS)
assert bool(CP.flags & HyundaiFlags.ALT_LIMITS) == bool(CP.safetyConfigs[-1].safetyParam & HyundaiPandaFlags.FLAG_HYUNDAI_ALT_LIMITS)

def test_can_features(self):
# Test no EV/HEV in any gear lists (should all use ELECT_GEAR)
Expand Down
11 changes: 11 additions & 0 deletions opendbc/car/hyundai/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ def __init__(self, CP):
self.STEER_MAX = 384


class HyundaiPandaFlags(IntFlag):
FLAG_HYUNDAI_EV_GAS = 1
FLAG_HYUNDAI_HYBRID_GAS = 2
FLAG_HYUNDAI_LONG = 4
FLAG_HYUNDAI_CAMERA_SCC = 8
FLAG_HYUNDAI_CANFD_HDA2 = 16
FLAG_HYUNDAI_CANFD_ALT_BUTTONS = 32
FLAG_HYUNDAI_ALT_LIMITS = 64
FLAG_HYUNDAI_CANFD_HDA2_ALT_STEERING = 128


class HyundaiFlags(IntFlag):
# Dynamic Flags
CANFD_HDA2 = 1
Expand Down
5 changes: 2 additions & 3 deletions opendbc/car/nissan/interface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from panda import Panda
from opendbc.car import get_safety_config, structs
from opendbc.car.interfaces import CarInterfaceBase
from opendbc.car.nissan.values import CAR
from opendbc.car.nissan.values import CAR, NissanPandaFlags


class CarInterface(CarInterfaceBase):
Expand All @@ -21,6 +20,6 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime

if candidate == CAR.NISSAN_ALTIMA:
# Altima has EPS on C-CAN unlike the others that have it on V-CAN
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_NISSAN_ALT_EPS_BUS
ret.safetyConfigs[0].safetyParam |= NissanPandaFlags.FLAG_NISSAN_ALT_EPS_BUS.value

return ret
5 changes: 5 additions & 0 deletions opendbc/car/nissan/values.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass, field
from enum import IntFlag

from panda import uds
from opendbc.car import AngleRateLimit, Bus, CarSpecs, DbcDict, PlatformConfig, Platforms
Expand All @@ -23,6 +24,10 @@ def __init__(self, CP):
pass


class NissanPandaFlags(IntFlag):
FLAG_NISSAN_ALT_EPS_BUS = 1


@dataclass
class NissanCarDocs(CarDocs):
package: str = "ProPILOT Assist"
Expand Down
10 changes: 5 additions & 5 deletions opendbc/car/subaru/interface.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from panda import Panda
from opendbc.car import get_safety_config, structs
from opendbc.car.disable_ecu import disable_ecu
from opendbc.car.interfaces import CarInterfaceBase
from opendbc.car.subaru.values import CAR, GLOBAL_ES_ADDR, SubaruFlags
from opendbc.car.subaru.values import CAR, GLOBAL_ES_ADDR, SubaruFlags, SubaruPandaFlags


class CarInterface(CarInterfaceBase):
Expand All @@ -29,7 +28,7 @@ def _get_params(ret: structs.CarParams, candidate: CAR, fingerprint, car_fw, exp
ret.enableBsm = 0x228 in fingerprint[0]
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.subaru)]
if ret.flags & SubaruFlags.GLOBAL_GEN2:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_SUBARU_GEN2
ret.safetyConfigs[0].safetyParam |= SubaruPandaFlags.FLAG_SUBARU_GEN2.value

ret.steerLimitTimer = 0.4
ret.steerActuatorDelay = 0.1
Expand Down Expand Up @@ -72,7 +71,8 @@ def _get_params(ret: structs.CarParams, candidate: CAR, fingerprint, car_fw, exp
ret.steerActuatorDelay = 0.1

elif candidate in (CAR.SUBARU_FORESTER_PREGLOBAL, CAR.SUBARU_OUTBACK_PREGLOBAL_2018):
ret.safetyConfigs[0].safetyParam = Panda.FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE # Outback 2018-2019 and Forester have reversed driver torque signal
# Outback 2018-2019 and Forester have reversed driver torque signal
ret.safetyConfigs[0].safetyParam = SubaruPandaFlags.FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE.value

elif candidate == CAR.SUBARU_LEGACY_PREGLOBAL:
ret.steerActuatorDelay = 0.15
Expand All @@ -90,7 +90,7 @@ def _get_params(ret: structs.CarParams, candidate: CAR, fingerprint, car_fw, exp
ret.flags |= SubaruFlags.DISABLE_EYESIGHT.value

if ret.openpilotLongitudinalControl:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_SUBARU_LONG
ret.safetyConfigs[0].safetyParam |= SubaruPandaFlags.FLAG_SUBARU_LONG.value

return ret

Expand Down
6 changes: 6 additions & 0 deletions opendbc/car/subaru/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def __init__(self, CP):
BRAKE_LOOKUP_V = [BRAKE_MAX, BRAKE_MIN]


class SubaruPandaFlags(IntFlag):
FLAG_SUBARU_GEN2 = 1
FLAG_SUBARU_LONG = 2
FLAG_SUBARU_PREGLOBAL_REVERSED_DRIVER_TORQUE = 4


class SubaruFlags(IntFlag):
# Detected flags
SEND_INFOTAINMENT = 1
Expand Down
2 changes: 1 addition & 1 deletion opendbc/car/tesla/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experime

# Not merged yet
#ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.tesla)]
#ret.safetyConfigs[0].safetyParam |= Panda.FLAG_TESLA_LONG_CONTROL
#ret.safetyConfigs[0].safetyParam |= TeslaPandaFlags.FLAG_TESLA_LONG_CONTROL.value

ret.steerLimitTimer = 1.0
ret.steerActuatorDelay = 0.25
Expand Down
6 changes: 6 additions & 0 deletions opendbc/car/tesla/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class CarControllerParams:
JERK_LIMIT_MIN = -5


class TeslaPandaFlags(IntFlag):
FLAG_TESLA_POWERTRAIN = 1
FLAG_TESLA_LONG_CONTROL = 2
FLAG_TESLA_RAVEN = 4


class TeslaFlags(IntFlag):
FLAG_TESLA_LONG_CONTROL = 1

Expand Down
Loading
Loading