From c6e4fb646d96c90a74c478f9da13649cf0e58576 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 7 Sep 2022 20:38:04 -0700 Subject: [PATCH] split out experimental long toggle (#25698) * split out experimental long toggle * clean up * update translations old-commit-hash: 3ef37fe2e848689dd3ef1e28b6cf14213c9fe069 --- .../controls/lib/longitudinal_planner.py | 3 +- selfdrive/ui/qt/offroad/settings.cc | 60 ++++++++----------- selfdrive/ui/qt/widgets/controls.h | 9 ++- selfdrive/ui/translations/main_ja.ts | 20 +++++-- selfdrive/ui/translations/main_ko.ts | 20 +++++-- selfdrive/ui/translations/main_pt-BR.ts | 20 +++++-- selfdrive/ui/translations/main_zh-CHS.ts | 20 +++++-- selfdrive/ui/translations/main_zh-CHT.ts | 20 +++++-- 8 files changed, 109 insertions(+), 63 deletions(-) diff --git a/selfdrive/controls/lib/longitudinal_planner.py b/selfdrive/controls/lib/longitudinal_planner.py index 8162d10071..b9b16e34fc 100755 --- a/selfdrive/controls/lib/longitudinal_planner.py +++ b/selfdrive/controls/lib/longitudinal_planner.py @@ -66,7 +66,8 @@ class LongitudinalPlanner: self.solverExecutionTime = 0.0 def read_param(self): - self.mpc.mode = 'blended' if self.params.get_bool('EndToEndLong') else 'acc' + e2e = self.params.get_bool('EndToEndLong') and self.CP.openpilotLongitudinalControl + self.mpc.mode = 'blended' if e2e else 'acc' def parse_model(self, model_msg): if (len(model_msg.position.x) == 33 and diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 33b16b1051..e5e5634545 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) { "", "../assets/offroad/icon_road.png", }, + { + "ExperimentalLongitudinalEnabled", + tr("Experimental openpilot longitudinal control"), + tr("WARNING: openpilot longitudinal control is experimental for this car and will disable AEB."), + "../assets/offroad/icon_speed_limit.png", + }, #ifdef ENABLE_MAPS { "NavSettingTime24h", @@ -92,23 +98,7 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { toggles[param.toStdString()] = toggle; } - QObject::connect(toggles["EndToEndLong"], &ParamControl::toggleFlipped, [=](bool state) { - auto cp_bytes = params.get("CarParamsPersistent"); - if (!cp_bytes.empty()) { - AlignedBuffer aligned_buf; - capnp::FlatArrayMessageReader cmsg(aligned_buf.align(cp_bytes.data(), cp_bytes.size())); - cereal::CarParams::Reader CP = cmsg.getRoot(); - if (CP.getExperimentalLongitudinalAvailable()) { - params.putBool("ExperimentalLongitudinalEnabled", state); - } else { - params.remove("ExperimentalLongitudinalEnabled"); - } - } else { - params.remove("ExperimentalLongitudinalEnabled"); - } - }); - - connect(uiState(), &UIState::offroadTransition, [=]() { + connect(toggles["ExperimentalLongitudinalEnabled"], &ToggleControl::toggleFlipped, [=]() { updateToggles(); }); } @@ -118,8 +108,8 @@ void TogglesPanel::showEvent(QShowEvent *event) { } void TogglesPanel::updateToggles() { - // update e2e toggle - auto toggle = toggles["EndToEndLong"]; + auto e2e_toggle = toggles["EndToEndLong"]; + auto op_long_toggle = toggles["ExperimentalLongitudinalEnabled"]; const QString e2e_description = tr("Let the driving model control the gas and brakes. openpilot will drive as it thinks a human would. Super experimental."); auto cp_bytes = params.get("CarParamsPersistent"); @@ -128,29 +118,31 @@ void TogglesPanel::updateToggles() { capnp::FlatArrayMessageReader cmsg(aligned_buf.align(cp_bytes.data(), cp_bytes.size())); cereal::CarParams::Reader CP = cmsg.getRoot(); - const bool exp_long = CP.getExperimentalLongitudinalAvailable(); - const bool op_long = CP.getOpenpilotLongitudinalControl() && !CP.getExperimentalLongitudinalAvailable(); + if (!CP.getExperimentalLongitudinalAvailable()) { + params.remove("ExperimentalLongitudinalEnabled"); + } + op_long_toggle->setVisible(CP.getExperimentalLongitudinalAvailable()); - if (op_long) { + const bool op_long = CP.getOpenpilotLongitudinalControl() && !CP.getExperimentalLongitudinalAvailable(); + const bool exp_long_enabled = CP.getExperimentalLongitudinalAvailable() && params.getBool("ExperimentalLongitudinalEnabled"); + if (op_long || exp_long_enabled) { // normal description and toggle - params.remove("ExperimentalLongitudinalEnabled"); - toggle->setDescription(e2e_description); - } else if (exp_long) { - toggle->setDescription("WARNING: openpilot longitudinal control is experimental for this car and will disable AEB.

" + e2e_description); - if (params.getBool("EndToEndLong") && !params.getBool("ExperimentalLongitudinalEnabled")) { - params.remove("EndToEndLong"); - } + e2e_toggle->setEnabled(true); + e2e_toggle->setDescription(e2e_description); } else { // no long for now + e2e_toggle->setEnabled(false); params.remove("EndToEndLong"); - params.remove("ExperimentalLongitudinalEnabled"); - toggle->setDescription("openpilot longitudinal control is not currently available for this car.

" + e2e_description); + + const QString no_long = "openpilot longitudinal control is not currently available for this car."; + const QString exp_long = "Enable experimental longitudinal control to enable this."; + e2e_toggle->setDescription("" + (CP.getExperimentalLongitudinalAvailable() ? exp_long : no_long) + "

" + e2e_description); } - toggle->refresh(); - toggle->setEnabled(op_long || (exp_long && !uiState()->scene.started)); + e2e_toggle->refresh(); } else { - toggle->setDescription(e2e_description); + e2e_toggle->setDescription(e2e_description); + op_long_toggle->setVisible(false); } } diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index 183fbff04d..1ab7df717f 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -164,9 +164,12 @@ private: QPainter p(this); p.setPen(Qt::gray); for (int i = 0; i < inner_layout.count() - 1; ++i) { - QRect r = inner_layout.itemAt(i)->geometry(); - int bottom = r.bottom() + inner_layout.spacing() / 2; - p.drawLine(r.left() + 40, bottom, r.right() - 40, bottom); + QWidget *widget = inner_layout.itemAt(i)->widget(); + if (widget->isVisible()) { + QRect r = inner_layout.itemAt(i)->geometry(); + int bottom = r.bottom() + inner_layout.spacing() / 2; + p.drawLine(r.left() + 40, bottom, r.right() - 40, bottom); + } } } QVBoxLayout outer_layout; diff --git a/selfdrive/ui/translations/main_ja.ts b/selfdrive/ui/translations/main_ja.ts index 4ce5b7b8d6..d6bd9e74ed 100644 --- a/selfdrive/ui/translations/main_ja.ts +++ b/selfdrive/ui/translations/main_ja.ts @@ -108,7 +108,7 @@ DevicePanel - + Dongle ID ドングル番号 (Dongle ID) @@ -1153,7 +1153,7 @@ location set TogglesPanel - + Enable openpilot openpilot を有効化 @@ -1198,12 +1198,22 @@ location set - + + Experimental openpilot longitudinal control + + + + + <b>WARNING: openpilot longitudinal control is experimental for this car and will disable AEB.</b> + + + + Let the driving model control the gas and brakes. openpilot will drive as it thinks a human would. Super experimental. - + Disengage On Accelerator Pedal アクセル踏むと openpilot をキャンセル @@ -1213,7 +1223,7 @@ location set 有効な場合は、アクセルを踏むと openpilot をキャンセルします。 - + Show ETA in 24h Format 24時間表示 diff --git a/selfdrive/ui/translations/main_ko.ts b/selfdrive/ui/translations/main_ko.ts index a38cfaf946..cc60ba7c89 100644 --- a/selfdrive/ui/translations/main_ko.ts +++ b/selfdrive/ui/translations/main_ko.ts @@ -108,7 +108,7 @@ DevicePanel - + Dongle ID Dongle ID @@ -1153,7 +1153,7 @@ location set TogglesPanel - + Enable openpilot openpilot 사용 @@ -1198,12 +1198,22 @@ location set 🌮 e2e long 사용 (매우 실험적) 🌮 - + + Experimental openpilot longitudinal control + + + + + <b>WARNING: openpilot longitudinal control is experimental for this car and will disable AEB.</b> + + + + Let the driving model control the gas and brakes. openpilot will drive as it thinks a human would. Super experimental. - + Disengage On Accelerator Pedal 가속페달 조작시 해제 @@ -1213,7 +1223,7 @@ location set 활성화된 경우 가속 페달을 누르면 openpilot이 해제됩니다. - + Show ETA in 24h Format 24시간 형식으로 도착예정시간 표시 diff --git a/selfdrive/ui/translations/main_pt-BR.ts b/selfdrive/ui/translations/main_pt-BR.ts index 9f3bd59824..2b3acb369f 100644 --- a/selfdrive/ui/translations/main_pt-BR.ts +++ b/selfdrive/ui/translations/main_pt-BR.ts @@ -108,7 +108,7 @@ DevicePanel - + Dongle ID Dongle ID @@ -1157,7 +1157,7 @@ trabalho definido TogglesPanel - + Enable openpilot Ativar openpilot @@ -1202,12 +1202,22 @@ trabalho definido 🌮 End-to-end longitudinal (experimental) 🌮 - + + Experimental openpilot longitudinal control + + + + + <b>WARNING: openpilot longitudinal control is experimental for this car and will disable AEB.</b> + + + + Let the driving model control the gas and brakes. openpilot will drive as it thinks a human would. Super experimental. - + Disengage On Accelerator Pedal Desacionar Com Pedal Do Acelerador @@ -1217,7 +1227,7 @@ trabalho definido Quando ativado, pressionar o pedal do acelerador desacionará o openpilot. - + Show ETA in 24h Format Mostrar ETA em formato 24h diff --git a/selfdrive/ui/translations/main_zh-CHS.ts b/selfdrive/ui/translations/main_zh-CHS.ts index 94ed832113..a00bf28303 100644 --- a/selfdrive/ui/translations/main_zh-CHS.ts +++ b/selfdrive/ui/translations/main_zh-CHS.ts @@ -108,7 +108,7 @@ DevicePanel - + Dongle ID 设备ID(Dongle ID) @@ -1151,7 +1151,7 @@ location set TogglesPanel - + Enable openpilot 启用openpilot @@ -1196,12 +1196,22 @@ location set - + + Experimental openpilot longitudinal control + + + + + <b>WARNING: openpilot longitudinal control is experimental for this car and will disable AEB.</b> + + + + Let the driving model control the gas and brakes. openpilot will drive as it thinks a human would. Super experimental. - + Disengage On Accelerator Pedal 踩油门时取消控制 @@ -1211,7 +1221,7 @@ location set 启用后,踩下油门踏板将取消openpilot。 - + Show ETA in 24h Format 以24小时格式显示预计到达时间 diff --git a/selfdrive/ui/translations/main_zh-CHT.ts b/selfdrive/ui/translations/main_zh-CHT.ts index 754d41bbda..52bd301364 100644 --- a/selfdrive/ui/translations/main_zh-CHT.ts +++ b/selfdrive/ui/translations/main_zh-CHT.ts @@ -108,7 +108,7 @@ DevicePanel - + Dongle ID Dongle ID @@ -1153,7 +1153,7 @@ location set TogglesPanel - + Enable openpilot 啟用 openpilot @@ -1198,12 +1198,22 @@ location set - + + Experimental openpilot longitudinal control + + + + + <b>WARNING: openpilot longitudinal control is experimental for this car and will disable AEB.</b> + + + + Let the driving model control the gas and brakes. openpilot will drive as it thinks a human would. Super experimental. - + Disengage On Accelerator Pedal 油門取消控車 @@ -1213,7 +1223,7 @@ location set 啟用後,踩踏油門將會取消 openpilot 控制。 - + Show ETA in 24h Format 預計到達時間單位改用 24 小時制