Move gas/brake pedal event logic to controlsd (#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 10bb51a0f0.

* Update refs

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
pull/23976/head
Shane Smiskol 2022-03-15 20:51:07 -07:00 committed by GitHub
parent 7482a6fc4b
commit 5fe00fb773
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View File

@ -72,7 +72,6 @@ class CarInterfaceBase(ABC):
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
@ -142,7 +141,6 @@ class CarInterfaceBase(ABC):
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:
@ -157,11 +155,6 @@ class CarInterfaceBase(ABC):
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:

View File

@ -94,6 +94,7 @@ class Controls:
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")
@ -119,6 +120,7 @@ class Controls:
put_nonblocking("CarParamsCache", cp_bytes)
self.CC = car.CarControl.new_message()
self.CS_prev = car.CarState.new_message()
self.AM = AlertManager()
self.events = Events()
@ -192,6 +194,11 @@ class Controls:
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)
@ -733,6 +740,7 @@ class Controls:
self.prof.checkpoint("Sent")
self.update_button_timers(CS.buttonEvents)
self.CS_prev = CS
def controlsd_thread(self):
while True:

View File

@ -1 +1 @@
6b5f707e5c58b0162044b2d5a07a35ec00296504
927918307b45657df0a4ac0255c3e8e3dc62d7cd