|
|
|
@ -21,8 +21,9 @@ class CarController: |
|
|
|
|
self.apply_steer_last = 0 |
|
|
|
|
self.gra_acc_counter_last = None |
|
|
|
|
self.frame = 0 |
|
|
|
|
self.hcaSameTorqueCount = 0 |
|
|
|
|
self.hcaEnabledFrameCount = 0 |
|
|
|
|
self.eps_timer_soft_disable_alert = False |
|
|
|
|
self.hca_frame_timer_running = 0 |
|
|
|
|
self.hca_frame_same_torque = 0 |
|
|
|
|
|
|
|
|
|
def update(self, CC, CS, ext_bus, now_nanos): |
|
|
|
|
actuators = CC.actuators |
|
|
|
@ -38,36 +39,31 @@ class CarController: |
|
|
|
|
# * Don't send > 3.00 Newton-meters torque |
|
|
|
|
# * Don't send the same torque for > 6 seconds |
|
|
|
|
# * Don't send uninterrupted steering for > 360 seconds |
|
|
|
|
# One frame of HCA disabled is enough to reset the timer, without zeroing the |
|
|
|
|
# torque value. Do that anytime we happen to have 0 torque, or failing that, |
|
|
|
|
# when exceeding ~1/3 the 360 second timer. |
|
|
|
|
# MQB racks reset the uninterrupted steering timer after a single frame |
|
|
|
|
# of HCA disabled; this is done whenever output happens to be zero. |
|
|
|
|
|
|
|
|
|
if CC.latActive: |
|
|
|
|
new_steer = int(round(actuators.steer * self.CCP.STEER_MAX)) |
|
|
|
|
apply_steer = apply_driver_steer_torque_limits(new_steer, self.apply_steer_last, CS.out.steeringTorque, self.CCP) |
|
|
|
|
if apply_steer == 0: |
|
|
|
|
hcaEnabled = False |
|
|
|
|
self.hcaEnabledFrameCount = 0 |
|
|
|
|
else: |
|
|
|
|
self.hcaEnabledFrameCount += 1 |
|
|
|
|
if self.hcaEnabledFrameCount >= 118 * (100 / self.CCP.STEER_STEP): # 118s |
|
|
|
|
hcaEnabled = False |
|
|
|
|
self.hcaEnabledFrameCount = 0 |
|
|
|
|
else: |
|
|
|
|
hcaEnabled = True |
|
|
|
|
self.hca_frame_timer_running += self.CCP.STEER_STEP |
|
|
|
|
if self.apply_steer_last == apply_steer: |
|
|
|
|
self.hcaSameTorqueCount += 1 |
|
|
|
|
if self.hcaSameTorqueCount > 1.9 * (100 / self.CCP.STEER_STEP): # 1.9s |
|
|
|
|
self.hca_frame_same_torque += self.CCP.STEER_STEP |
|
|
|
|
if self.hca_frame_same_torque > self.CCP.STEER_TIME_STUCK_TORQUE / DT_CTRL: |
|
|
|
|
apply_steer -= (1, -1)[apply_steer < 0] |
|
|
|
|
self.hcaSameTorqueCount = 0 |
|
|
|
|
self.hca_frame_same_torque = 0 |
|
|
|
|
else: |
|
|
|
|
self.hcaSameTorqueCount = 0 |
|
|
|
|
self.hca_frame_same_torque = 0 |
|
|
|
|
hca_enabled = abs(apply_steer) > 0 |
|
|
|
|
else: |
|
|
|
|
hcaEnabled = False |
|
|
|
|
hca_enabled = False |
|
|
|
|
apply_steer = 0 |
|
|
|
|
|
|
|
|
|
if not hca_enabled: |
|
|
|
|
self.hca_frame_timer_running = 0 |
|
|
|
|
|
|
|
|
|
self.eps_timer_soft_disable_alert = self.hca_frame_timer_running > self.CCP.STEER_TIME_ALERT / DT_CTRL |
|
|
|
|
self.apply_steer_last = apply_steer |
|
|
|
|
can_sends.append(self.CCS.create_steering_control(self.packer_pt, CANBUS.pt, apply_steer, hcaEnabled)) |
|
|
|
|
can_sends.append(self.CCS.create_steering_control(self.packer_pt, CANBUS.pt, apply_steer, hca_enabled)) |
|
|
|
|
|
|
|
|
|
# **** Acceleration Controls ******************************************** # |
|
|
|
|
|
|
|
|
@ -110,4 +106,4 @@ class CarController: |
|
|
|
|
|
|
|
|
|
self.gra_acc_counter_last = CS.gra_stock_values["COUNTER"] |
|
|
|
|
self.frame += 1 |
|
|
|
|
return new_actuators, can_sends |
|
|
|
|
return new_actuators, can_sends, self.eps_timer_soft_disable_alert |
|
|
|
|