From 5fe00fb7738358c19b7db907047353d8785b5f20 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 15 Mar 2022 20:51:07 -0700 Subject: [PATCH] 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 * Revert "Update selfdrive/controls/controlsd.py" This reverts commit 10bb51a0f0ee0d8e2a27c746a0638280a5eaea8a. * Update refs Co-authored-by: Adeeb Shihadeh --- selfdrive/car/interfaces.py | 7 ------- selfdrive/controls/controlsd.py | 8 ++++++++ selfdrive/test/process_replay/ref_commit | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index ab8a179bf5..04098413ad 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -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: diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index fcb1a4974a..1a911ef985 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -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: diff --git a/selfdrive/test/process_replay/ref_commit b/selfdrive/test/process_replay/ref_commit index 419d1adab2..f9edf2f887 100644 --- a/selfdrive/test/process_replay/ref_commit +++ b/selfdrive/test/process_replay/ref_commit @@ -1 +1 @@ -6b5f707e5c58b0162044b2d5a07a35ec00296504 \ No newline at end of file +927918307b45657df0a4ac0255c3e8e3dc62d7cd \ No newline at end of file