From 474ba19c818ee3b884f8f8c4e86e55bdfc6f2eb0 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Mon, 4 Apr 2022 21:59:52 -0700 Subject: [PATCH] Add Disengage on Accelerator Toggle (#23977) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Squashed commit of the following: commit 953bcf0ecf8d03f0fec9ce0d5442cc660ae2347d Merge: b4198608d efd04715e Author: Shane Smiskol Date: Fri Apr 1 19:58:06 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit b4198608dac9595bfeb9443f95cd6c5d385cd62d Merge: 24f90b2c8 0e983562d Author: Shane Smiskol Date: Fri Apr 1 14:32:54 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 24f90b2c8d6ae509c0776b6e33b743467aa08dee Author: Shane Smiskol Date: Thu Mar 31 14:07:52 2022 -0700 revert changes and get ready for override commit aa514df6b5e8431f0faa07f6b25eb5cb6c9f2749 Author: Shane Smiskol Date: Wed Mar 30 20:52:24 2022 -0700 temporary commit c874e10c2555968c683f629c4582ab22e51d431f Author: Shane Smiskol Date: Wed Mar 30 00:30:13 2022 -0700 move gasPressed to controlsd commit fe670439dff5bc6dfc5963d79ca2febe0c5920c7 Merge: 49d3b6d11 c78701e47 Author: Shane Smiskol Date: Wed Mar 30 00:15:48 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 49d3b6d1162893fa94b2294152f0718eeb4698ed Merge: 475b27e74 3e819bc5a Author: Shane Smiskol Date: Mon Mar 28 13:06:08 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 475b27e74fd6479f1d148e9ded1eca6ee476865c Author: Shane Smiskol Date: Thu Mar 24 20:24:59 2022 -0700 update SAFETY.md commit 0798eadb82749e12ecbaa86f4e57b21bd3dbc7e8 Author: Shane Smiskol Date: Thu Mar 24 17:52:06 2022 -0700 ⛽ ➡️ 🔋 bump commit d2b64b89cf8d7265bc90848b4e3a2276c9a4cb78 Author: Shane Smiskol Date: Thu Mar 24 16:19:34 2022 -0700 these changes will be in border PR these changes will be border PR commit bed31e63de2244c161729773978fef8a9246ddb5 Merge: 491417640 603e07793 Author: Shane Smiskol Date: Thu Mar 24 16:17:31 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 49141764098e3a701ff123ead52de4656b31db4d Merge: 9291e9f00 46ed8bb8e Author: Shane Smiskol Date: Wed Mar 23 19:00:26 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 9291e9f0045780669b2ffa7f08fb10373c03b070 Merge: 2aed64157 2c947f193 Author: Shane Smiskol Date: Fri Mar 18 19:03:13 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 2aed64157d6e9dc993d103a2c6abf7e643410562 Author: Shane Smiskol Date: Fri Mar 18 19:03:03 2022 -0700 Revert "send pre-enable state when gas is pressed" This reverts commit 8d82e697dc2efade307413e767d14b56b4d2d079. commit a219defe5342efa731a957b2ff4fd86292c1f239 Author: Shane Smiskol Date: Thu Mar 17 12:50:46 2022 -0700 bump cereal commit 8d82e697dc2efade307413e767d14b56b4d2d079 Author: Shane Smiskol Date: Wed Mar 16 22:40:13 2022 -0700 send pre-enable state when gas is pressed formatting and it's out forgot one allow gas press show toggle revert changes revert changes commit 5eb4d1ab1b77ac65bdd901f692ebfb848d5187ca Merge: bad1bdc74 d0ef25959 Author: Shane Smiskol Date: Wed Mar 16 22:29:43 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit bad1bdc7428c5d8a4a765b259da504f0ade84424 Author: Shane Smiskol Date: Tue Mar 15 23:03:56 2022 -0700 clean up a bit commit 7516ed9b786536a07f00a92b9c1742ca252a01d1 Author: Shane Smiskol Date: Tue Mar 15 22:55:09 2022 -0700 these are null checks right now commit 408f5f1d633521b29b08d966c9b387fa79dff0d6 Author: Shane Smiskol Date: Tue Mar 15 22:51:14 2022 -0700 should work commit be1978e29c03d8843cf073cc9ddf84020fd2b378 Author: Shane Smiskol Date: Tue Mar 15 22:36:16 2022 -0700 stash commit f0bd4c47e9d27061c6cd3b88765a7c10995f42db Author: Shane Smiskol Date: Tue Mar 15 22:26:24 2022 -0700 this was flipped commit d5b6e30389a727e8559331acd706422e1b246f60 Merge: 820b19894 c814c1383 Author: Shane Smiskol Date: Tue Mar 15 22:25:49 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 820b1989496225df1f66f39b477f1e9402db1b19 Merge: 91763f9ff 6d2483ff9 Author: Shane Smiskol Date: Mon Mar 14 23:39:34 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 91763f9ff4321986babce1a7b1272fcf64c8f753 Author: Shane Smiskol Date: Thu Feb 24 20:15:26 2022 -0800 add icon from jozef 🔥 commit 1885c9e2bacd9351c7e421b1436dcbfbde238436 Merge: 1f591736a eae207a84 Author: Shane Smiskol Date: Thu Feb 24 20:08:07 2022 -0800 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 1f591736a2767b1ed892c29ec5000cc7348f01c7 Merge: 465811f0b ebf5b27a7 Author: Jason Wen <47793918+sunnyhaibin@users.noreply.github.com> Date: Sat Feb 12 10:24:29 2022 -0500 Merge branch 'master' into disengage-on-gas commit 465811f0b4776e43a289398e4d4369362b7da58c Author: Jason Wen Date: Fri Feb 11 11:20:32 2022 -0500 Add param to process replay commit 0344363a533505435cff87eb33356b2364a4156f Merge: 700efcb3f 1175355b7 Author: Jason Wen <47793918+sunnyhaibin@users.noreply.github.com> Date: Fri Feb 11 11:07:31 2022 -0500 Merge branch 'master' into disengage-on-gas commit 700efcb3f444092f99ef10e9908f83402429d742 Author: Jason Wen Date: Fri Feb 11 11:04:39 2022 -0500 Add param to unsafeMode commit 220ce272fee1f7f5ace2a04052605a6e4f95712b Author: Jason Wen Date: Fri Feb 11 10:54:16 2022 -0500 Add param to unsafeMode commit d273bb78acbc23ee5255e461fa71b2f0400a5e03 Author: Jason Wen Date: Fri Feb 11 10:52:22 2022 -0500 Resolve conflicts commit 1a85afd60c2f0d3140dfa8e7cd574d6b88abd5e3 Author: Jason Wen Date: Fri Feb 11 10:51:50 2022 -0500 Resolve conflicts commit e3be32afc2bb2423d29e2b4f85b3cff3fe72aab9 Author: Jason Wen Date: Fri Feb 11 10:51:08 2022 -0500 Resolve conflicts commit f27203af3afe612173bf9a63e15c57118598b5b8 Author: Jason Wen Date: Wed Jan 19 00:30:09 2022 -0500 Add param to process replay commit 04c0ad1a54f4fea5efe74b3203d9bdbd693b64a6 Author: Jason Wen <47793918+sunnyhaibin@users.noreply.github.com> Date: Wed Jan 19 00:28:49 2022 -0500 Update interfaces.py Co-authored-by: Willem Melching commit 99cf13caeb4d9f2c95c25e1e78b6e353ea508cb6 Author: Jason Wen Date: Sat Jan 15 00:03:38 2022 -0500 Fix missing params lib commit 2230254ca709625d591b0c73d1a6022c450f6ef6 Author: Jason Wen Date: Fri Jan 14 23:38:46 2022 -0500 Disengage on gas toggle commit 87475e02cb63cc39c9b16edc67f303e02d17e6ef Author: Jason Wen Date: Fri Jan 14 23:24:00 2022 -0500 Disengage on gas toggle * bump * use ALTERNATIVE_EXPERIENCE * or it * de-bump * update refs * update refs! * you can just ctrl+click ALTERNATIVE_EXPERIENCE! * already have a params * update text old-commit-hash: f1f40c117a65294e27f93f953a772c43078bdceb --- docs/SAFETY.md | 2 +- .../offroad/icon_disengage_on_accelerator.svg | 3 +++ selfdrive/car/interfaces.py | 2 -- selfdrive/common/params.cc | 1 + selfdrive/controls/controlsd.py | 15 ++++++++++++--- selfdrive/controls/lib/longcontrol.py | 2 +- selfdrive/controls/lib/longitudinal_planner.py | 1 - selfdrive/manager/manager.py | 1 + selfdrive/test/process_replay/process_replay.py | 1 + selfdrive/test/process_replay/ref_commit | 2 +- selfdrive/ui/qt/offroad/settings.cc | 6 ++++++ 11 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 selfdrive/assets/offroad/icon_disengage_on_accelerator.svg diff --git a/docs/SAFETY.md b/docs/SAFETY.md index 23ee251af4..49f88df8c0 100644 --- a/docs/SAFETY.md +++ b/docs/SAFETY.md @@ -22,7 +22,7 @@ Following Hazard and Risk Analysis and FMEA, at a very high level, we have desig ensuring two main safety requirements. 1. The driver must always be capable to immediately retake manual control of the vehicle, - by stepping on either pedal or by pressing the cancel button. + by stepping on the brake pedal or by pressing the cancel button. 2. The vehicle must not alter its trajectory too quickly for the driver to safely react. This means that while the system is engaged, the actuators are constrained to operate within reasonable limits. diff --git a/selfdrive/assets/offroad/icon_disengage_on_accelerator.svg b/selfdrive/assets/offroad/icon_disengage_on_accelerator.svg new file mode 100644 index 0000000000..d5a8c87e21 --- /dev/null +++ b/selfdrive/assets/offroad/icon_disengage_on_accelerator.svg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5252412f2225c89ea7e78ad0fbd6544170aea157693ce0f9778f26a64f582ec2 +size 6821 diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index f01c8a8aa0..34ca75cd48 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -124,8 +124,6 @@ class CarInterfaceBase(ABC): events.add(EventName.wrongCarMode) if cs_out.espDisabled: events.add(EventName.espDisabled) - if cs_out.gasPressed: - events.add(EventName.pedalPressedPreEnable) if cs_out.stockFcw: events.add(EventName.stockFcw) if cs_out.stockAeb: diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index 8180ee4293..0c36511be7 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -98,6 +98,7 @@ std::unordered_map keys = { {"DisableRadar_Allow", PERSISTENT}, {"DisableRadar", PERSISTENT}, // WARNING: THIS DISABLES AEB {"DisableUpdates", PERSISTENT}, + {"DisengageOnAccelerator", PERSISTENT}, {"DongleId", PERSISTENT}, {"DoReboot", CLEAR_ON_MANAGER_START}, {"DoShutdown", CLEAR_ON_MANAGER_START}, diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 3ad8ce166f..5f2fe34721 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -10,6 +10,7 @@ from common.profiler import Profiler from common.params import Params, put_nonblocking import cereal.messaging as messaging from common.conversions import Conversions as CV +from panda import ALTERNATIVE_EXPERIENCE from selfdrive.swaglog import cloudlog from selfdrive.boardd.boardd import can_list_to_can_capnp from selfdrive.car.car_helpers import get_car, get_startup_event, get_one_can @@ -100,7 +101,11 @@ class Controls: else: self.CI, self.CP = CI, CI.CP - self.CP.alternativeExperience = 0 # see panda/board/safety_declarations.h for allowed values + # set alternative experiences from parameters + self.disengage_on_accelerator = params.get_bool("DisengageOnAccelerator") + self.CP.alternativeExperience = 0 + if not self.disengage_on_accelerator: + self.CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS # read params self.is_metric = params.get_bool("IsMetric") @@ -200,11 +205,15 @@ 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 \ + # Disable on rising edge of accelerator or brake. Also disable on brake when speed > 0 + if (CS.gasPressed and not self.CS_prev.gasPressed and self.disengage_on_accelerator) or \ (CS.brakePressed and (not self.CS_prev.brakePressed or not CS.standstill)): self.events.add(EventName.pedalPressed) + if CS.gasPressed: + self.events.add(EventName.pedalPressedPreEnable if self.disengage_on_accelerator else + EventName.gasPressedOverride) + self.events.add_from_msg(CS.events) if not self.CP.notCar: diff --git a/selfdrive/controls/lib/longcontrol.py b/selfdrive/controls/lib/longcontrol.py index 21682d8263..f91ddcf44e 100644 --- a/selfdrive/controls/lib/longcontrol.py +++ b/selfdrive/controls/lib/longcontrol.py @@ -87,7 +87,7 @@ class LongControl(): v_target, v_target_future, CS.brakePressed, CS.cruiseState.standstill) - if self.long_control_state == LongCtrlState.off or CS.gasPressed: + if self.long_control_state == LongCtrlState.off: self.reset(CS.vEgo) output_accel = 0. diff --git a/selfdrive/controls/lib/longitudinal_planner.py b/selfdrive/controls/lib/longitudinal_planner.py index 8aade9b9c4..41c41e5493 100755 --- a/selfdrive/controls/lib/longitudinal_planner.py +++ b/selfdrive/controls/lib/longitudinal_planner.py @@ -71,7 +71,6 @@ class Planner: # Reset current state when not engaged, or user is controlling the speed reset_state = long_control_state == LongCtrlState.off - reset_state = reset_state or sm['carState'].gasPressed # No change cost when user is controlling the speed, or when standstill prev_accel_constraint = not (reset_state or sm['carState'].standstill) diff --git a/selfdrive/manager/manager.py b/selfdrive/manager/manager.py index 21b8cb9657..b5fa439671 100755 --- a/selfdrive/manager/manager.py +++ b/selfdrive/manager/manager.py @@ -38,6 +38,7 @@ def manager_init() -> None: default_params: List[Tuple[str, Union[str, bytes]]] = [ ("CompletedTrainingVersion", "0"), + ("DisengageOnAccelerator", "1"), ("HasAcceptedTerms", "0"), ("OpenpilotEnabledToggle", "1"), ] diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 6e3398f9cc..9a2a161562 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -346,6 +346,7 @@ def setup_env(simulation=False): params.clear_all() params.put_bool("OpenpilotEnabledToggle", True) params.put_bool("Passive", False) + params.put_bool("DisengageOnAccelerator", True) os.environ["NO_RADAR_SLEEP"] = "1" os.environ["REPLAY"] = "1" diff --git a/selfdrive/test/process_replay/ref_commit b/selfdrive/test/process_replay/ref_commit index a0cebb0961..cd6ae5f315 100644 --- a/selfdrive/test/process_replay/ref_commit +++ b/selfdrive/test/process_replay/ref_commit @@ -1 +1 @@ -ad17c3c1d11691bc35efe3de78a7cef3daf5dbdf \ No newline at end of file +5f9efe721de4d947567eae55a8dd331f0bae4ded \ No newline at end of file diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index f3584460d6..4fde627341 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -65,6 +65,12 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { "In this mode openpilot will ignore lanelines and just drive how it thinks a human would.", "../assets/offroad/icon_road.png", }, + { + "DisengageOnAccelerator", + "Disengage On Accelerator Pedal", + "When enabled, openpilot will disengage when the accelerator pedal is pressed.", + "../assets/offroad/icon_disengage_on_accelerator.svg", + }, #ifdef ENABLE_MAPS { "NavSettingTime24h",