Skip to content

Commit

Permalink
No actuation while in pre-enabled state (#23658)
Browse files Browse the repository at this point in the history
* No actuation while in pre-enabled state

* update refs
  • Loading branch information
adeebshihadeh authored Jan 29, 2022
1 parent 8eb6a6a commit 72e00a0
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 24 deletions.
6 changes: 3 additions & 3 deletions selfdrive/car/gm/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, dbc_name, CP, VM):
self.packer_obj = CANPacker(DBC[CP.carFingerprint]['radar'])
self.packer_ch = CANPacker(DBC[CP.carFingerprint]['chassis'])

def update(self, enabled, CS, frame, actuators,
def update(self, c, enabled, CS, frame, actuators,
hud_v_cruise, hud_show_lanes, hud_show_car, hud_alert):

P = self.params
Expand All @@ -41,7 +41,7 @@ def update(self, enabled, CS, frame, actuators,
if CS.lka_steering_cmd_counter != self.lka_steering_cmd_counter_last:
self.lka_steering_cmd_counter_last = CS.lka_steering_cmd_counter
elif (frame % P.STEER_STEP) == 0:
lkas_enabled = enabled and not (CS.out.steerWarning or CS.out.steerError) and CS.out.vEgo > P.MIN_STEER_SPEED
lkas_enabled = c.active and not (CS.out.steerWarning or CS.out.steerError) and CS.out.vEgo > P.MIN_STEER_SPEED
if lkas_enabled:
new_steer = int(round(actuators.steer * P.STEER_MAX))
apply_steer = apply_std_steer_torque_limits(new_steer, self.apply_steer_last, CS.out.steeringTorque, P)
Expand All @@ -58,7 +58,7 @@ def update(self, enabled, CS, frame, actuators,

# Gas/regen and brakes - all at 25Hz
if (frame % 4) == 0:
if not enabled:
if not c.active:
# Stock ECU sends max regen when not enabled.
self.apply_gas = P.MAX_ACC_REGEN
self.apply_brake = 0
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def apply(self, c):
# In GM, PCM faults out if ACC command overlaps user gas.
enabled = c.enabled and not self.CS.out.gasPressed

ret = self.CC.update(enabled, self.CS, self.frame,
ret = self.CC.update(c, enabled, self.CS, self.frame,
c.actuators,
hud_v_cruise, hud_control.lanesVisible,
hud_control.leadVisible, hud_control.visualAlert)
Expand Down
6 changes: 3 additions & 3 deletions selfdrive/car/hyundai/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def __init__(self, dbc_name, CP, VM):
self.last_resume_frame = 0
self.accel = 0

def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, hud_speed,
def update(self, c, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, hud_speed,
left_lane, right_lane, left_lane_depart, right_lane_depart):
# Steering Torque
new_steer = int(round(actuators.steer * self.p.STEER_MAX))
apply_steer = apply_std_steer_torque_limits(new_steer, self.apply_steer_last, CS.out.steeringTorque, self.p)
self.steer_rate_limited = new_steer != apply_steer

# disable when temp fault is active, or below LKA minimum speed
lkas_active = enabled and not CS.out.steerWarning and CS.out.vEgo >= CS.CP.minSteerSpeed
lkas_active = c.active and not CS.out.steerWarning and CS.out.vEgo >= CS.CP.minSteerSpeed

if not lkas_active:
apply_steer = 0
Expand Down Expand Up @@ -89,7 +89,7 @@ def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, hu

if frame % 2 == 0 and CS.CP.openpilotLongitudinalControl:
lead_visible = False
accel = actuators.accel if enabled else 0
accel = actuators.accel if c.active else 0

jerk = clip(2.0 * (accel - CS.out.aEgo), -12.7, 12.7)

Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def update(self, c, can_strings):

def apply(self, c):
hud_control = c.hudControl
ret = self.CC.update(c.enabled, self.CS, self.frame, c.actuators,
ret = self.CC.update(c, c.enabled, self.CS, self.frame, c.actuators,
c.cruiseControl.cancel, hud_control.visualAlert, hud_control.setSpeed, hud_control.leftLaneVisible,
hud_control.rightLaneVisible, hud_control.leftLaneDepart, hud_control.rightLaneDepart)
self.frame += 1
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/mazda/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def update(self, c, CS, frame):
apply_steer = 0
self.steer_rate_limited = False

if c.enabled:
if c.active:
# calculate steer and also set limits due to driver torque
new_steer = int(round(c.actuators.steer * CarControllerParams.STEER_MAX))
apply_steer = apply_std_steer_torque_limits(new_steer, self.apply_steer_last,
Expand Down
8 changes: 3 additions & 5 deletions selfdrive/car/nissan/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@ def __init__(self, dbc_name, CP, VM):

self.packer = CANPacker(dbc_name)

def update(self, enabled, CS, frame, actuators, cruise_cancel, hud_alert,
def update(self, c, enabled, CS, frame, actuators, cruise_cancel, hud_alert,
left_line, right_line, left_lane_depart, right_lane_depart):
""" Controls thread """

# Send CAN commands.
can_sends = []

### STEER ###
acc_active = bool(CS.out.cruiseState.enabled)
acc_active = CS.out.cruiseState.enabled
lkas_hud_msg = CS.lkas_hud_msg
lkas_hud_info_msg = CS.lkas_hud_info_msg
apply_angle = actuators.steeringAngleDeg

steer_hud_alert = 1 if hud_alert in (VisualAlert.steerRequired, VisualAlert.ldw) else 0

if enabled:
if c.active:
# # windup slower
if self.last_angle * apply_angle > 0. and abs(apply_angle) > abs(self.last_angle):
angle_rate_lim = interp(CS.out.vEgo, CarControllerParams.ANGLE_DELTA_BP, CarControllerParams.ANGLE_DELTA_V)
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/nissan/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def update(self, c, can_strings):

def apply(self, c):
hud_control = c.hudControl
ret = self.CC.update(c.enabled, self.CS, self.frame, c.actuators,
ret = self.CC.update(c, c.enabled, self.CS, self.frame, c.actuators,
c.cruiseControl.cancel, hud_control.visualAlert,
hud_control.leftLaneVisible, hud_control.rightLaneVisible,
hud_control.leftLaneDepart, hud_control.rightLaneDepart)
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/subaru/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, dbc_name, CP, VM):
self.p = CarControllerParams(CP)
self.packer = CANPacker(DBC[CP.carFingerprint]['pt'])

def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, left_line, right_line, left_lane_depart, right_lane_depart):
def update(self, c, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, left_line, right_line, left_lane_depart, right_lane_depart):

can_sends = []

Expand All @@ -30,7 +30,7 @@ def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, le
apply_steer = apply_std_steer_torque_limits(new_steer, self.apply_steer_last, CS.out.steeringTorque, self.p)
self.steer_rate_limited = new_steer != apply_steer

if not enabled:
if not c.active:
apply_steer = 0

if CS.CP.carFingerprint in PREGLOBAL_CARS:
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/subaru/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def update(self, c, can_strings):

def apply(self, c):
hud_control = c.hudControl
ret = self.CC.update(c.enabled, self.CS, self.frame, c.actuators,
ret = self.CC.update(c, c.enabled, self.CS, self.frame, c.actuators,
c.cruiseControl.cancel, hud_control.visualAlert,
hud_control.leftLaneVisible, hud_control.rightLaneVisible, hud_control.leftLaneDepart, hud_control.rightLaneDepart)
self.frame += 1
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/tesla/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def __init__(self, dbc_name, CP, VM):
self.pt_packer = CANPacker(DBC[CP.carFingerprint]['pt'])
self.tesla_can = TeslaCAN(self.packer, self.pt_packer)

def update(self, enabled, CS, frame, actuators, cruise_cancel):
def update(self, c, enabled, CS, frame, actuators, cruise_cancel):
can_sends = []

# Temp disable steering on a hands_on_fault, and allow for user override
hands_on_fault = (CS.steer_warning == "EAC_ERROR_HANDS_ON" and CS.hands_on_level >= 3)
lkas_enabled = enabled and (not hands_on_fault)
lkas_enabled = c.active and (not hands_on_fault)

if lkas_enabled:
apply_angle = actuators.steeringAngleDeg
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/tesla/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ def update(self, c, can_strings):
return self.CS.out

def apply(self, c):
ret = self.CC.update(c.enabled, self.CS, self.frame, c.actuators, c.cruiseControl.cancel)
ret = self.CC.update(c, c.enabled, self.CS, self.frame, c.actuators, c.cruiseControl.cancel)
self.frame += 1
return ret
4 changes: 2 additions & 2 deletions selfdrive/car/toyota/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def update(self, enabled, active, CS, frame, actuators, pcm_cancel_cmd, hud_aler
left_line, right_line, lead, left_lane_depart, right_lane_depart):

# gas and brake
if CS.CP.enableGasInterceptor and enabled:
if CS.CP.enableGasInterceptor and active:
MAX_INTERCEPTOR_GAS = 0.5
# RAV4 has very sensitive gas pedal
if CS.CP.carFingerprint in (CAR.RAV4, CAR.RAV4H, CAR.HIGHLANDER, CAR.HIGHLANDERH):
Expand All @@ -49,7 +49,7 @@ def update(self, enabled, active, CS, frame, actuators, pcm_cancel_cmd, hud_aler
self.steer_rate_limited = new_steer != apply_steer

# Cut steering while we're in a known fault state (2s)
if not enabled or CS.steer_state in (9, 25):
if not active or CS.steer_state in (9, 25):
apply_steer = 0
apply_steer_req = 0
else:
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/test/process_replay/ref_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f0d37f9fec3d36fef37df15f3865c3da068253c8
d2ea206bf832dbc0625756d56820895e52d3029e

0 comments on commit 72e00a0

Please sign in to comment.