Skip to content

Commit

Permalink
simplify and cleanup fault logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasloetkolben committed Oct 14, 2024
1 parent 3fc9bdb commit dcd00b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion opendbc/car/tesla/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def update(self, CC, CS, now_nanos):
can_sends = []

# Disengage and allow for user override
hands_on_fault = CS.steer_warning == "EAC_ERROR_HANDS_ON" and CS.hands_on_level >= 3
hands_on_fault = CS.hands_on_level >= 3
lkas_enabled = CC.latActive and not hands_on_fault

if self.frame % 2 == 0:
Expand Down
9 changes: 3 additions & 6 deletions opendbc/car/tesla/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def __init__(self, CP):
self.can_define = CANDefine(DBC[CP.carFingerprint]['pt'])

self.hands_on_level = 0
self.steer_warning = None
self.das_control = None

def update(self, cp, cp_cam, *_) -> structs.CarState:
Expand All @@ -37,22 +36,20 @@ def update(self, cp, cp_cam, *_) -> structs.CarState:
# Steering wheel
epas_status = cp.vl["EPAS3S_sysStatus"]
self.hands_on_level = epas_status["EPAS3S_handsOnLevel"]
self.steer_warning = self.can_define.dv["EPAS3S_sysStatus"]["EPAS3S_eacErrorCode"].get(int(epas_status["EPAS3S_eacErrorCode"]), None)
ret.steeringAngleDeg = -epas_status["EPAS3S_internalSAS"]
ret.steeringRateDeg = -cp_cam.vl["SCCM_steeringAngleSensor"]["SCCM_steeringAngleSpeed"]
ret.steeringTorque = -epas_status["EPAS3S_torsionBarTorque"]

ret.steeringPressed = self.hands_on_level > 0
eac_status = self.can_define.dv["EPAS3S_sysStatus"]["EPAS3S_eacStatus"].get(int(epas_status["EPAS3S_eacStatus"]), None)
ret.steerFaultPermanent = eac_status in ["EAC_FAULT"]
ret.steerFaultTemporary = self.steer_warning not in ["EAC_ERROR_IDLE", "EAC_ERROR_HANDS_ON"] and eac_status not in ["EAC_ACTIVE", "EAC_AVAILABLE"]
ret.steerFaultPermanent = eac_status == "EAC_FAULT"
ret.steerFaultTemporary = eac_status == "EAC_INHIBITED"

# Cruise state
cruise_state = self.can_define.dv["DI_state"]["DI_cruiseState"].get(int(cp.vl["DI_state"]["DI_cruiseState"]), None)
speed_units = self.can_define.dv["DI_state"]["DI_speedUnits"].get(int(cp.vl["DI_state"]["DI_speedUnits"]), None)

self.acc_enabled = cruise_state in ("ENABLED", "STANDSTILL", "OVERRIDE", "PRE_FAULT", "PRE_CANCEL")
ret.cruiseState.enabled = self.acc_enabled
ret.cruiseState.enabled = cruise_state in ("ENABLED", "STANDSTILL", "OVERRIDE", "PRE_FAULT", "PRE_CANCEL")
if speed_units == "KPH":
ret.cruiseState.speed = cp.vl["DI_state"]["DI_digitalSpeed"] * CV.KPH_TO_MS
elif speed_units == "MPH":
Expand Down

0 comments on commit dcd00b6

Please sign in to comment.