Skip to content

Commit

Permalink
reduce chances of causing 30-frame fault
Browse files Browse the repository at this point in the history
Fix clu11

drive down cancel times
  • Loading branch information
sshane committed Apr 6, 2022
1 parent c19334e commit 0f54c05
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion selfdrive/car/hyundai/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def __init__(self, dbc_name, CP, VM):
self.params = CarControllerParams(CP)
self.packer = CANPacker(dbc_name)
self.frame = 0
self.cancel_frames = 0

self.prev_cancel = False
self.cancel_duration = 0

self.apply_steer_last = 0
self.car_fingerprint = CP.carFingerprint
Expand Down Expand Up @@ -78,15 +82,29 @@ def update(self, CC, CS):
left_lane_warning, right_lane_warning))

if not self.CP.openpilotLongitudinalControl:
if pcm_cancel_cmd and not self.prev_cancel:
self.cancel_duration = 0

if pcm_cancel_cmd:
can_sends.append(create_clu11(self.packer, self.frame, CS.clu11, Buttons.CANCEL))
self.cancel_duration += 1
if 0 < self.cancel_frames < 5:
print('Sending cancel!')
can_sends.extend([create_clu11(self.packer, self.frame, CS.clu11, Buttons.CANCEL)] * 1)
elif self.cancel_frames >= 5:
self.cancel_frames = -5
self.cancel_frames += 1
elif CS.out.cruiseState.standstill:
# send resume at a max freq of 10Hz
if (self.frame - self.last_resume_frame) * DT_CTRL > 0.1:
# send 25 messages at a time to increases the likelihood of resume being accepted
can_sends.extend([create_clu11(self.packer, self.frame, CS.clu11, Buttons.RES_ACCEL)] * 25)
self.last_resume_frame = self.frame

if not pcm_cancel_cmd and self.prev_cancel:
print('Took {} frames to cancel!'.format(self.cancel_duration))

self.prev_cancel = pcm_cancel_cmd

if self.frame % 2 == 0 and self.CP.openpilotLongitudinalControl:
lead_visible = False
accel = actuators.accel if CC.longActive else 0
Expand Down

0 comments on commit 0f54c05

Please sign in to comment.