Skip to content

Commit

Permalink
Move gas/brake pedal event logic to controlsd (commaai#23850)
Browse files Browse the repository at this point in the history
* move some state machine logic to controlsd

move some state machine logic to controlsd

* same order

same order

* move unsafeMode up

* disable at standstill

* save last CS

save last CS

* do we need to copy at all?

* don't copy

* rename

* Update selfdrive/controls/controlsd.py

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* Revert "Update selfdrive/controls/controlsd.py"

This reverts commit 10bb51a.

* Update refs

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
  • Loading branch information
sshane and adeebshihadeh committed Mar 16, 2022
1 parent 7482a6f commit 5fe00fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 0 additions & 7 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def get_steer_feedforward_function(cls):
def get_std_params(candidate, fingerprint):
ret = car.CarParams.new_message()
ret.carFingerprint = candidate
ret.unsafeMode = 0 # see panda/board/safety_declarations.h for allowed values

# standard ALC params
ret.steerControlType = car.CarParams.SteerControlType.torque
Expand Down Expand Up @@ -142,7 +141,6 @@ def create_common_events(self, cs_out, extra_gears=None, pcm_enable=True):
if cs_out.parkingBrake:
events.add(EventName.parkBrake)


# Handle permanent and temporary steering faults
self.steering_unpressed = 0 if cs_out.steeringPressed else self.steering_unpressed + 1
if cs_out.steerFaultTemporary:
Expand All @@ -157,11 +155,6 @@ def create_common_events(self, cs_out, extra_gears=None, pcm_enable=True):
if cs_out.steerFaultPermanent:
events.add(EventName.steerUnavailable)

# Disable on rising edge of gas or brake. Also disable on brake when speed > 0.
if (cs_out.gasPressed and not self.CS.out.gasPressed) or \
(cs_out.brakePressed and (not self.CS.out.brakePressed or not cs_out.standstill)):
events.add(EventName.pedalPressed)

# we engage when pcm is active (rising edge)
if pcm_enable:
if cs_out.cruiseState.enabled and not self.CS.out.cruiseState.enabled:
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def __init__(self, sm=None, pm=None, can_sock=None):
get_one_can(self.can_sock)

self.CI, self.CP = get_car(self.can_sock, self.pm.sock['sendcan'])
self.CP.unsafeMode = 0 # see panda/board/safety_declarations.h for allowed values

# read params
self.is_metric = params.get_bool("IsMetric")
Expand All @@ -119,6 +120,7 @@ def __init__(self, sm=None, pm=None, can_sock=None):
put_nonblocking("CarParamsCache", cp_bytes)

self.CC = car.CarControl.new_message()
self.CS_prev = car.CarState.new_message()
self.AM = AlertManager()
self.events = Events()

Expand Down Expand Up @@ -192,6 +194,11 @@ def update_events(self, CS):
self.events.add(EventName.controlsInitializing)
return

# Disable on rising edge of gas or brake. Also disable on brake when speed > 0
if (CS.gasPressed and not self.CS_prev.gasPressed) or \
(CS.brakePressed and (not self.CS_prev.brakePressed or not CS.standstill)):
self.events.add(EventName.pedalPressed)

self.events.add_from_msg(CS.events)
self.events.add_from_msg(self.sm['driverMonitoringState'].events)

Expand Down Expand Up @@ -733,6 +740,7 @@ def step(self):
self.prof.checkpoint("Sent")

self.update_button_timers(CS.buttonEvents)
self.CS_prev = CS

def controlsd_thread(self):
while True:
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 @@
6b5f707e5c58b0162044b2d5a07a35ec00296504
927918307b45657df0a4ac0255c3e8e3dc62d7cd

0 comments on commit 5fe00fb

Please sign in to comment.