Skip to content

Commit d6f91df

Browse files
sshanebudney
authored andcommitted
Move gas/brake pedal event logic to controlsd (commaai#23850)
* 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> # Conflicts: # selfdrive/car/interfaces.py
1 parent 3ab9746 commit d6f91df

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

selfdrive/car/interfaces.py

-7
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def get_steer_feedforward_function(cls):
7474
def get_std_params(candidate, fingerprint):
7575
ret = car.CarParams.new_message()
7676
ret.carFingerprint = candidate
77-
ret.unsafeMode = 1 # see panda/board/safety_declarations.h for allowed values
7877

7978
# standard ALC params
8079
ret.steerControlType = car.CarParams.SteerControlType.torque
@@ -144,7 +143,6 @@ def create_common_events(self, cs_out, extra_gears=None, pcm_enable=True):
144143
if cs_out.parkingBrake:
145144
events.add(EventName.parkBrake)
146145

147-
148146
# Handle permanent and temporary steering faults
149147
self.steering_unpressed = 0 if cs_out.steeringPressed else self.steering_unpressed + 1
150148
if cs_out.steerFaultTemporary:
@@ -159,11 +157,6 @@ def create_common_events(self, cs_out, extra_gears=None, pcm_enable=True):
159157
if cs_out.steerFaultPermanent:
160158
events.add(EventName.steerUnavailable)
161159

162-
# Disable on rising edge of gas or brake. Also disable on brake when speed > 0.
163-
if (cs_out.gasPressed and not self.CS.out.gasPressed and self.disengage_on_gas) or \
164-
(cs_out.brakePressed and (not self.CS.out.brakePressed or not cs_out.standstill)):
165-
events.add(EventName.pedalPressed)
166-
167160
# we engage when pcm is active (rising edge)
168161
if pcm_enable:
169162
if cs_out.cruiseState.enabled and not self.CS.out.cruiseState.enabled:

selfdrive/controls/controlsd.py

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def __init__(self, sm=None, pm=None, can_sock=None):
9494
get_one_can(self.can_sock)
9595

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

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

121122
self.CC = car.CarControl.new_message()
123+
self.CS_prev = car.CarState.new_message()
122124
self.AM = AlertManager()
123125
self.events = Events()
124126

@@ -192,6 +194,11 @@ def update_events(self, CS):
192194
self.events.add(EventName.controlsInitializing)
193195
return
194196

197+
# Disable on rising edge of gas or brake. Also disable on brake when speed > 0
198+
if (CS.gasPressed and not self.CS_prev.gasPressed) or \
199+
(CS.brakePressed and (not self.CS_prev.brakePressed or not CS.standstill)):
200+
self.events.add(EventName.pedalPressed)
201+
195202
self.events.add_from_msg(CS.events)
196203
self.events.add_from_msg(self.sm['driverMonitoringState'].events)
197204

@@ -733,6 +740,7 @@ def step(self):
733740
self.prof.checkpoint("Sent")
734741

735742
self.update_button_timers(CS.buttonEvents)
743+
self.CS_prev = CS
736744

737745
def controlsd_thread(self):
738746
while True:
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6b5f707e5c58b0162044b2d5a07a35ec00296504
1+
927918307b45657df0a4ac0255c3e8e3dc62d7cd

0 commit comments

Comments
 (0)