Skip to content

Commit

Permalink
Simplify cancellation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
carleeno committed Aug 6, 2024
1 parent 342fafc commit 674528a
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions selfdrive/car/tesla/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ def __init__(self, dbc_name, CP, VM):
self.pt_packer = CANPacker(DBC[CP.carFingerprint]['pt'])
self.tesla_can = TeslaCAN(self.packer, self.pt_packer)
self.pcm_cancel_cmd = False # Must be latching because of frame rate
self.acc_mismatch_start_nanos = None

def update(self, CC, CS, now_nanos):
actuators = CC.actuators
self.pcm_cancel_cmd = CC.cruiseControl.cancel or self.pcm_cancel_cmd

can_sends = []

Expand All @@ -40,19 +38,12 @@ def update(self, CC, CS, now_nanos):
use_lka_mode = CS.params_list.enable_mads
can_sends.append(self.tesla_can.create_steering_control(apply_angle, lkas_enabled, (self.frame // 2) % 16, use_lka_mode))


self.pcm_cancel_cmd = CC.cruiseControl.cancel or not CS.accEnabled or self.pcm_cancel_cmd

if hands_on_fault and not CS.params_list.enable_mads:
self.pcm_cancel_cmd = True

# Cancel ACC if MADS is enabled and ACC is not supposed to be enabled
if CS.params_list.enable_mads and not CS.accEnabled and CS.acc_enabled:
# ACC mismatch must persist for a while before cancelling because of race condition
if self.acc_mismatch_start_nanos is None:
self.acc_mismatch_start_nanos = now_nanos
elif now_nanos - self.acc_mismatch_start_nanos > 200e6: # 200ms
self.pcm_cancel_cmd = True
else:
self.acc_mismatch_start_nanos = None

# Unlatch cancel command only when ACC is actually disabled
if not CS.acc_enabled:
self.pcm_cancel_cmd = False
Expand Down

0 comments on commit 674528a

Please sign in to comment.