Skip to content

Commit

Permalink
ui: controls -> selfdrive (commaai#33487)
Browse files Browse the repository at this point in the history
* ui: controls -> selfdrive

* lil more
  • Loading branch information
adeebshihadeh authored Sep 6, 2024
1 parent 922348f commit f6d5f8f
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 107 deletions.
36 changes: 18 additions & 18 deletions selfdrive/ui/qt/onroad/alerts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ void OnroadAlerts::clear() {
}

OnroadAlerts::Alert OnroadAlerts::getAlert(const SubMaster &sm, uint64_t started_frame) {
const cereal::SelfdriveState::Reader &cs = sm["selfdriveState"].getSelfdriveState();
const uint64_t controls_frame = sm.rcv_frame("selfdriveState");
const cereal::SelfdriveState::Reader &ss = sm["selfdriveState"].getSelfdriveState();
const uint64_t selfdrive_frame = sm.rcv_frame("selfdriveState");

Alert a = {};
if (controls_frame >= started_frame) { // Don't get old alert.
a = {cs.getAlertText1().cStr(), cs.getAlertText2().cStr(),
cs.getAlertType().cStr(), cs.getAlertSize(), cs.getAlertStatus()};
if (selfdrive_frame >= started_frame) { // Don't get old alert.
a = {ss.getAlertText1().cStr(), ss.getAlertText2().cStr(),
ss.getAlertType().cStr(), ss.getAlertSize(), ss.getAlertStatus()};
}

if (!sm.updated("selfdriveState") && (sm.frame - started_frame) > 5 * UI_FREQ) {
const int CONTROLS_TIMEOUT = 5;
const int controls_missing = (nanos_since_boot() - sm.rcv_time("selfdriveState")) / 1e9;
const int SELFDRIVE_STATE_TIMEOUT = 5;
const int ss_missing = (nanos_since_boot() - sm.rcv_time("selfdriveState")) / 1e9;

// Handle controls timeout
if (controls_frame < started_frame) {
// Handle selfdrive timeout
if (selfdrive_frame < started_frame) {
// car is started, but selfdriveState hasn't been seen at all
a = {tr("openpilot Unavailable"), tr("Waiting for controls to start"),
"controlsWaiting", cereal::SelfdriveState::AlertSize::MID,
a = {tr("openpilot Unavailable"), tr("Waiting to start"),
"selfdriveWaiting", cereal::SelfdriveState::AlertSize::MID,
cereal::SelfdriveState::AlertStatus::NORMAL};
} else if (controls_missing > CONTROLS_TIMEOUT && !Hardware::PC()) {
// car is started, but controls is lagging or died
if (cs.getEnabled() && (controls_missing - CONTROLS_TIMEOUT) < 10) {
a = {tr("TAKE CONTROL IMMEDIATELY"), tr("Controls Unresponsive"),
"controlsUnresponsive", cereal::SelfdriveState::AlertSize::FULL,
} else if (ss_missing > SELFDRIVE_STATE_TIMEOUT && !Hardware::PC()) {
// car is started, but selfdrive is lagging or died
if (ss.getEnabled() && (ss_missing - SELFDRIVE_STATE_TIMEOUT) < 10) {
a = {tr("TAKE CONTROL IMMEDIATELY"), tr("System Unresponsive"),
"selfdriveUnresponsive", cereal::SelfdriveState::AlertSize::FULL,
cereal::SelfdriveState::AlertStatus::CRITICAL};
} else {
a = {tr("Controls Unresponsive"), tr("Reboot Device"),
"controlsUnresponsivePermanent", cereal::SelfdriveState::AlertSize::MID,
a = {tr("System Unresponsive"), tr("Reboot Device"),
"selfdriveUnresponsivePermanent", cereal::SelfdriveState::AlertSize::MID,
cereal::SelfdriveState::AlertStatus::NORMAL};
}
}
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/ui/qt/onroad/annotated_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {
const int SET_SPEED_NA = 255;
const SubMaster &sm = *(s.sm);

const bool cs_alive = sm.alive("controlsState");
const bool cs_alive = sm.alive("carState");
const auto cs = sm["controlsState"].getControlsState();
const auto car_state = sm["carState"].getCarState();

is_metric = s.scene.is_metric;

// Handle older routes where vCruiseCluster is not set
// Handle older routes where vCruise was in controlsState
float v_cruise = car_state.getVCruiseCluster() == 0.0 ? cs.getVCruiseDEPRECATED() : car_state.getVCruiseCluster();
setSpeed = cs_alive ? v_cruise : SET_SPEED_NA;
is_cruise_set = setSpeed > 0 && (int)setSpeed != SET_SPEED_NA;
Expand Down
20 changes: 10 additions & 10 deletions selfdrive/ui/soundd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SAMPLE_BUFFER = 4096 # (approx 100ms)
MAX_VOLUME = 1.0
MIN_VOLUME = 0.1
CONTROLS_TIMEOUT = 5 # 5 seconds
SELFDRIVE_STATE_TIMEOUT = 5 # 5 seconds
FILTER_DT = 1. / (micd.SAMPLE_RATE / micd.FFT_SAMPLES)

AMBIENT_DB = 30 # DB where MIN_VOLUME is applied
Expand All @@ -40,11 +40,11 @@
AudibleAlert.warningImmediate: ("warning_immediate.wav", None, MAX_VOLUME),
}

def check_controls_timeout_alert(sm):
controls_missing = time.monotonic() - sm.recv_time['selfdriveState']
def check_selfdrive_timeout_alert(sm):
ss_missing = time.monotonic() - sm.recv_time['selfdriveState']

if controls_missing > CONTROLS_TIMEOUT:
if sm['selfdriveState'].enabled and (controls_missing - CONTROLS_TIMEOUT) < 10:
if ss_missing > SELFDRIVE_STATE_TIMEOUT:
if sm['selfdriveState'].enabled and (ss_missing - SELFDRIVE_STATE_TIMEOUT) < 10:
return True

return False
Expand All @@ -58,7 +58,7 @@ def __init__(self):
self.current_volume = MIN_VOLUME
self.current_sound_frame = 0

self.controls_timeout_alert = False
self.selfdrive_timeout_alert = False

self.spl_filter_weighted = FirstOrderFilter(0, 2.5, FILTER_DT, initialized=False)

Expand Down Expand Up @@ -114,12 +114,12 @@ def get_audible_alert(self, sm):
if sm.updated['selfdriveState']:
new_alert = sm['selfdriveState'].alertSound.raw
self.update_alert(new_alert)
elif check_controls_timeout_alert(sm):
elif check_selfdrive_timeout_alert(sm):
self.update_alert(AudibleAlert.warningImmediate)
self.controls_timeout_alert = True
elif self.controls_timeout_alert:
self.selfdrive_timeout_alert = True
elif self.selfdrive_timeout_alert:
self.update_alert(AudibleAlert.none)
self.controls_timeout_alert = False
self.selfdrive_timeout_alert = False

def calculate_volume(self, weighted_db):
volume = ((weighted_db - AMBIENT_DB) / DB_SCALE) * (MAX_VOLUME - MIN_VOLUME) + MIN_VOLUME
Expand Down
10 changes: 5 additions & 5 deletions selfdrive/ui/tests/test_soundd.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from cereal import car
from cereal import messaging
from cereal.messaging import SubMaster, PubMaster
from openpilot.selfdrive.ui.soundd import CONTROLS_TIMEOUT, check_controls_timeout_alert
from openpilot.selfdrive.ui.soundd import SELFDRIVE_STATE_TIMEOUT, check_selfdrive_timeout_alert

import time

AudibleAlert = car.CarControl.HUDControl.AudibleAlert


class TestSoundd:
def test_check_controls_timeout_alert(self):
def test_check_selfdrive_timeout_alert(self):
sm = SubMaster(['selfdriveState'])
pm = PubMaster(['selfdriveState'])

Expand All @@ -23,13 +23,13 @@ def test_check_controls_timeout_alert(self):

sm.update(0)

assert not check_controls_timeout_alert(sm)
assert not check_selfdrive_timeout_alert(sm)

for _ in range(CONTROLS_TIMEOUT * 110):
for _ in range(SELFDRIVE_STATE_TIMEOUT * 110):
sm.update(0)
time.sleep(0.01)

assert check_controls_timeout_alert(sm)
assert check_selfdrive_timeout_alert(sm)

# TODO: add test with micd for checking that soundd actually outputs sounds

16 changes: 8 additions & 8 deletions selfdrive/ui/translations/main_ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,22 +418,22 @@
<source>openpilot Unavailable</source>
<translation>openpilot غير متوفر</translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation>في انتظار بدء عناصر التحكم</translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation>تحكم على الفور</translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation>الضوابط غير مستجيبة</translation>
</message>
<message>
<source>Reboot Device</source>
<translation>إعادة التشغيل</translation>
</message>
<message>
<source>Waiting to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>System Unresponsive</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
Expand Down
8 changes: 4 additions & 4 deletions selfdrive/ui/translations/main_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,19 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<source>Waiting to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<source>System Unresponsive</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down
16 changes: 8 additions & 8 deletions selfdrive/ui/translations/main_es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,22 +414,22 @@
<source>openpilot Unavailable</source>
<translation>openpilot no disponible</translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation>Esperando que los controles inicien</translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation>TOME CONTROL INMEDIATAMENTE</translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation>Controles no responden</translation>
</message>
<message>
<source>Reboot Device</source>
<translation>Reiniciar Dispositivo</translation>
</message>
<message>
<source>Waiting to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>System Unresponsive</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
Expand Down
8 changes: 4 additions & 4 deletions selfdrive/ui/translations/main_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,19 +415,19 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<source>Waiting to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<source>System Unresponsive</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down
8 changes: 4 additions & 4 deletions selfdrive/ui/translations/main_ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,19 +413,19 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<source>Waiting to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<source>System Unresponsive</source>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down
16 changes: 8 additions & 8 deletions selfdrive/ui/translations/main_ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,22 +413,22 @@
<source>openpilot Unavailable</source>
<translation>오픈파일럿을 사용할수없습니다</translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation>프로세스가 준비중입니다</translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation>핸들을 잡아주세요</translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation>프로세스가 응답하지않습니다</translation>
</message>
<message>
<source>Reboot Device</source>
<translation>장치를 재부팅하세요</translation>
</message>
<message>
<source>Waiting to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>System Unresponsive</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
Expand Down
16 changes: 8 additions & 8 deletions selfdrive/ui/translations/main_pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,22 +414,22 @@
<source>openpilot Unavailable</source>
<translation>openpilot Indisponível</translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation>Aguardando controles para iniciar</translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation>ASSUMA IMEDIATAMENTE</translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation>Controles Não Respondem</translation>
</message>
<message>
<source>Reboot Device</source>
<translation>Reinicie o Dispositivo</translation>
</message>
<message>
<source>Waiting to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>System Unresponsive</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
Expand Down
16 changes: 8 additions & 8 deletions selfdrive/ui/translations/main_th.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,22 +413,22 @@
<source>openpilot Unavailable</source>
<translation>openpilot ไม่สามารถใช้งานได้</translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation>กำลังรอให้ controls เริ่มทำงาน</translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation>เข้าควบคุมรถเดี๋ยวนี้</translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation>Controls ไม่ตอบสนอง</translation>
</message>
<message>
<source>Reboot Device</source>
<translation>รีบูตอุปกรณ์</translation>
</message>
<message>
<source>Waiting to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>System Unresponsive</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
Expand Down
Loading

0 comments on commit f6d5f8f

Please sign in to comment.