From d2cdd7706c4cbc03f991edd35642973f28d39d1a Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 27 Aug 2020 11:57:31 -0700 Subject: [PATCH] UI cleanup (#2091) * remove unused UI code * these params aren't used anymore * this is cleaner * remove one more timeout * read that from carParams * only android needs pm * fix that * fix that Co-authored-by: Comma Device old-commit-hash: 43e3ec1bc1ee0d7b8044c5cabbe4022c5ddc9783 --- selfdrive/manager.py | 1 - selfdrive/ui/android_ui.cc | 31 ++++------- selfdrive/ui/paint.cc | 106 ++++--------------------------------- selfdrive/ui/qt/ui.cc | 3 +- selfdrive/ui/ui.cc | 31 +++-------- selfdrive/ui/ui.hpp | 15 +----- 6 files changed, 29 insertions(+), 158 deletions(-) diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 0113aa1afe..b7df78dc12 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -571,7 +571,6 @@ def main(): ("IsUploadRawEnabled", "1"), ("IsLdwEnabled", "1"), ("IsGeofenceEnabled", "-1"), - ("SpeedLimitOffset", "0"), ("LongitudinalControl", "0"), ("LimitSetSpeed", "0"), ("LimitSetSpeedNeural", "0"), diff --git a/selfdrive/ui/android_ui.cc b/selfdrive/ui/android_ui.cc index 983d817e79..ff44740ec7 100644 --- a/selfdrive/ui/android_ui.cc +++ b/selfdrive/ui/android_ui.cc @@ -143,7 +143,7 @@ static void handle_sidebar_touch(UIState *s, int touch_x, int touch_y) { } } -static void update_offroad_layout_state(UIState *s) { +static void update_offroad_layout_state(UIState *s, PubMaster *pm) { static int timeout = 0; static bool prev_collapsed = false; static cereal::UiLayoutState::App prev_app = cereal::UiLayoutState::App::NONE; @@ -157,7 +157,7 @@ static void update_offroad_layout_state(UIState *s) { auto layout = event.initUiLayoutState(); layout.setActiveApp(s->active_app); layout.setSidebarCollapsed(s->scene.uilayout_sidebarcollapsed); - s->pm->send("offroadLayout", msg); + pm->send("offroadLayout", msg); LOGD("setting active app to %d with sidebar %d", (int)s->active_app, s->scene.uilayout_sidebarcollapsed); prev_collapsed = s->scene.uilayout_sidebarcollapsed; prev_app = s->active_app; @@ -176,9 +176,10 @@ int main(int argc, char* argv[]) { UIState *s = &uistate; ui_init(s); set_awake(s, true); - enable_event_processing(true); + PubMaster *pm = new PubMaster({"offroadLayout"}); + pthread_t connect_thread_handle; err = pthread_create(&connect_thread_handle, NULL, vision_connect_thread, s); @@ -196,11 +197,11 @@ int main(int argc, char* argv[]) { // light sensor scaling params const bool LEON = util::read_file("/proc/cmdline").find("letv") != std::string::npos; - float brightness_b, brightness_m; + float brightness_b = 0, brightness_m = 0; int result = read_param(&brightness_b, "BRIGHTNESS_B", true); result += read_param(&brightness_m, "BRIGHTNESS_M", true); - if(result != 0){ + if(result != 0) { brightness_b = LEON ? 10.0 : 5.0; brightness_m = LEON ? 2.6 : 1.3; write_param_float(brightness_b, "BRIGHTNESS_B", true); @@ -245,10 +246,6 @@ int main(int argc, char* argv[]) { if (!s->started) { // always process events offroad check_messages(s); - - if (s->started) { - s->controls_timeout = 5 * UI_FREQ; - } } else { set_awake(s, true); // Car started, fetch a new rgb image from ipc @@ -275,9 +272,7 @@ int main(int argc, char* argv[]) { } // manage hardware disconnect - if (s->hardware_timeout > 0) { - s->hardware_timeout--; - } else { + if ((s->sm->frame - s->sm->rcv_frame("health")) > 5*UI_FREQ) { s->scene.hwType = cereal::HealthData::HwType::UNKNOWN; } @@ -290,9 +285,8 @@ int main(int argc, char* argv[]) { s->sound.setVolume(fmin(MAX_VOLUME, MIN_VOLUME + s->scene.controls_state.getVEgo() / 5)); // up one notch every 5 m/s - if (s->controls_timeout > 0) { - s->controls_timeout--; - } else if (s->started && !s->scene.frontview) { + bool controls_timeout = (s->sm->frame - s->sm->rcv_frame("controlsState")) > 5*UI_FREQ; + if (s->started && !s->scene.frontview && controls_timeout) { if (!s->controls_seen) { // car is started, but controlsState hasn't been seen at all s->scene.alert_text1 = "openpilot Unavailable"; @@ -315,9 +309,6 @@ int main(int argc, char* argv[]) { } read_param_timeout(&s->is_metric, "IsMetric", &s->is_metric_timeout); - read_param_timeout(&s->longitudinal_control, "LongitudinalControl", &s->longitudinal_control_timeout); - read_param_timeout(&s->limit_set_speed, "LimitSetSpeed", &s->limit_set_speed_timeout); - read_param_timeout(&s->speed_lim_off, "SpeedLimitOffset", &s->limit_set_speed_timeout); int param_read = read_param_timeout(&s->last_athena_ping, "LastAthenaPingTime", &s->last_athena_ping_timeout); if (param_read != -1) { // Param was updated this loop if (param_read != 0) { // Failed to read param @@ -328,7 +319,7 @@ int main(int argc, char* argv[]) { s->scene.athenaStatus = NET_ERROR; } } - update_offroad_layout_state(s); + update_offroad_layout_state(s, pm); pthread_mutex_unlock(&s->lock); @@ -355,6 +346,6 @@ int main(int argc, char* argv[]) { err = pthread_join(connect_thread_handle, NULL); assert(err == 0); delete s->sm; - delete s->pm; + delete pm; return 0; } diff --git a/selfdrive/ui/paint.cc b/selfdrive/ui/paint.cc index b9475a92b1..3a08192b48 100644 --- a/selfdrive/ui/paint.cc +++ b/selfdrive/ui/paint.cc @@ -276,8 +276,8 @@ static void draw_frame(UIState *s) { static inline bool valid_frame_pt(UIState *s, float x, float y) { return x >= 0 && x <= s->rgb_width && y >= 0 && y <= s->rgb_height; - } + static void update_lane_line_data(UIState *s, const float *points, float off, model_path_vertices_data *pvd, float valid_len) { pvd->cnt = 0; int rcount = fmin(MODEL_PATH_MAX_VERTICES_CNT / 2, valid_len); @@ -323,6 +323,7 @@ static void ui_draw_vision_lanes(UIState *s) { update_all_lane_lines_data(s, scene->model.getLeftLane(), scene->left_lane_points, pvd); update_all_lane_lines_data(s, scene->model.getRightLane(), scene->right_lane_points, pvd + MODEL_LANE_PATH_CNT); } + // Draw left lane edge ui_draw_lane( s, pvd, @@ -336,6 +337,7 @@ static void ui_draw_vision_lanes(UIState *s) { if(s->sm->updated("radarState")) { update_all_track_data(s); } + // Draw vision path ui_draw_track(s, false, &s->track_vertices[0]); if (scene->controls_state.getEnabled()) { @@ -385,25 +387,20 @@ static void ui_draw_world(UIState *s) { } static void ui_draw_vision_maxspeed(UIState *s) { - /*if (!s->longitudinal_control){ - return; - }*/ char maxspeed_str[32]; float maxspeed = s->scene.controls_state.getVCruise(); int maxspeed_calc = maxspeed * 0.6225 + 0.5; float speedlimit = s->scene.speedlimit; int speedlim_calc = speedlimit * 2.2369363 + 0.5; - int speed_lim_off = s->speed_lim_off * 2.2369363 + 0.5; if (s->is_metric) { maxspeed_calc = maxspeed + 0.5; speedlim_calc = speedlimit * 3.6 + 0.5; - speed_lim_off = s->speed_lim_off * 3.6 + 0.5; } bool is_cruise_set = (maxspeed != 0 && maxspeed != SET_SPEED_NA); bool is_speedlim_valid = s->scene.speedlimit_valid; bool is_set_over_limit = is_speedlim_valid && s->scene.controls_state.getEnabled() && - is_cruise_set && maxspeed_calc > (speedlim_calc + speed_lim_off); + is_cruise_set && maxspeed_calc > speedlim_calc; int viz_maxspeed_w = 184; int viz_maxspeed_h = 202; @@ -411,12 +408,7 @@ static void ui_draw_vision_maxspeed(UIState *s) { int viz_maxspeed_y = (box_y + (bdr_s*1.5)); int viz_maxspeed_xo = 180; -#ifdef SHOW_SPEEDLIMIT - viz_maxspeed_w += viz_maxspeed_xo; - viz_maxspeed_x += viz_maxspeed_w - (viz_maxspeed_xo * 2); -#else viz_maxspeed_xo = 0; -#endif // Draw Background ui_draw_rect(s->vg, viz_maxspeed_x, viz_maxspeed_y, viz_maxspeed_w, viz_maxspeed_h, @@ -444,65 +436,6 @@ static void ui_draw_vision_maxspeed(UIState *s) { } } -#ifdef SHOW_SPEEDLIMIT -static void ui_draw_vision_speedlimit(UIState *s) { - char speedlim_str[32]; - float speedlimit = s->scene.speedlimit; - int speedlim_calc = speedlimit * 2.2369363 + 0.5; - if (s->is_metric) { - speedlim_calc = speedlimit * 3.6 + 0.5; - } - - bool is_speedlim_valid = s->scene.speedlimit_valid; - float hysteresis_offset = 0.5; - if (s->is_ego_over_limit) { - hysteresis_offset = 0.0; - } - s->is_ego_over_limit = is_speedlim_valid && s->scene.controls_state.getVEgo() > (speedlimit + s->speed_lim_off + hysteresis_offset); - - int viz_speedlim_w = 180; - int viz_speedlim_h = 202; - int viz_speedlim_x = (s->scene.ui_viz_rx + (bdr_s*2)); - int viz_speedlim_y = (box_y + (bdr_s*1.5)); - if (!is_speedlim_valid) { - viz_speedlim_w -= 5; - viz_speedlim_h -= 10; - viz_speedlim_x += 9; - viz_speedlim_y += 5; - } - // Draw Background - NVGcolor color = COLOR_WHITE_ALPHA(100); - if (is_speedlim_valid && s->is_ego_over_limit) { - color = nvgRGBA(218, 111, 37, 180); - } else if (is_speedlim_valid) { - color = COLOR_WHITE; - } - ui_draw_rect(s->vg, viz_speedlim_x, viz_speedlim_y, viz_speedlim_w, viz_speedlim_h, color, is_speedlim_valid ? 30 : 15); - - // Draw Border - if (is_speedlim_valid) { - ui_draw_rect(s->vg, viz_speedlim_x, viz_speedlim_y, viz_speedlim_w, viz_speedlim_h, - s->is_ego_over_limit ? COLOR_OCHRE : COLOR_WHITE, 20, 10); - } - const float text_x = viz_speedlim_x + viz_speedlim_w / 2; - const float text_y = viz_speedlim_y + (is_speedlim_valid ? 50 : 45); - // Draw "Speed Limit" Text - nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); - color = is_speedlim_valid && s->is_ego_over_limit ? COLOR_WHITE : COLOR_BLACK; - ui_draw_text(s->vg, text_x + (is_speedlim_valid ? 6 : 0), text_y, "SMART", 50, color, s->font_sans_semibold); - ui_draw_text(s->vg, text_x + (is_speedlim_valid ? 6 : 0), text_y + 40, "SPEED", 50, color, s->font_sans_semibold); - - // Draw Speed Text - color = s->is_ego_over_limit ? COLOR_WHITE : COLOR_BLACK; - if (is_speedlim_valid) { - snprintf(speedlim_str, sizeof(speedlim_str), "%d", speedlim_calc); - ui_draw_text(s->vg, text_x, viz_speedlim_y + (is_speedlim_valid ? 170 : 165), speedlim_str, 48*2.5, color, s->font_sans_bold); - } else { - ui_draw_text(s->vg, text_x, viz_speedlim_y + (is_speedlim_valid ? 170 : 165), "N/A", 42*2.5, color, s->font_sans_semibold); - } -} -#endif - static void ui_draw_vision_speed(UIState *s) { const UIScene *scene = &s->scene; float v_ego = s->scene.controls_state.getVEgo(); @@ -551,15 +484,6 @@ static void ui_draw_vision_event(UIState *s) { } } -#ifdef SHOW_SPEEDLIMIT -static void ui_draw_vision_map(UIState *s) { - const int map_size = 96; - const int map_x = (s->scene.ui_viz_rx + (map_size * 3) + (bdr_s * 3)); - const int map_y = (footer_y + ((footer_h - map_size) / 2)); - ui_draw_circle_image(s->vg, map_x, map_y, map_size, s->img_map, s->scene.map_valid); -} -#endif - static void ui_draw_vision_face(UIState *s) { const int face_size = 96; const int face_x = (s->scene.ui_viz_rx + face_size + (bdr_s * 2)); @@ -629,20 +553,12 @@ static void ui_draw_vision_header(UIState *s) { ui_draw_vision_maxspeed(s); -#ifdef SHOW_SPEEDLIMIT - ui_draw_vision_speedlimit(s); -#endif ui_draw_vision_speed(s); ui_draw_vision_event(s); } static void ui_draw_vision_footer(UIState *s) { - ui_draw_vision_face(s); - -#ifdef SHOW_SPEEDLIMIT - // ui_draw_vision_map(s); -#endif } void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size, int va_color, @@ -654,15 +570,13 @@ void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size, {cereal::ControlsState::AlertSize::FULL, vwp_h}}; const UIScene *scene = &s->scene; - const bool hasSidebar = !scene->uilayout_sidebarcollapsed; - const bool mapEnabled = scene->uilayout_mapenabled; bool longAlert1 = strlen(va_text1) > 15; const uint8_t *color = alert_colors[va_color]; int alr_s = alert_size_map[va_size]; - const int alr_x = scene->ui_viz_rx-(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)-bdr_s; - const int alr_w = scene->ui_viz_rw+(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)+(bdr_s*2); + const int alr_x = scene->ui_viz_rx- bdr_s; + const int alr_w = scene->ui_viz_rw + (bdr_s*2); const int alr_h = alr_s+(va_size==cereal::ControlsState::AlertSize::NONE?0:bdr_s); const int alr_y = vwp_h-alr_h; @@ -719,9 +633,9 @@ static void ui_draw_vision(UIState *s) { if (scene->alert_size != cereal::ControlsState::AlertSize::NONE) { // Controls Alerts ui_draw_vision_alert(s, scene->alert_size, s->status, - scene->alert_text1.c_str(), scene->alert_text2.c_str()); - } else { - if (!scene->frontview){ui_draw_vision_footer(s);} + scene->alert_text1.c_str(), scene->alert_text2.c_str()); + } else if (!scene->frontview) { + ui_draw_vision_footer(s); } } @@ -864,8 +778,6 @@ void ui_nvg_init(UIState *s) { assert(s->img_turn != 0); s->img_face = nvgCreateImage(s->vg, "../assets/img_driver_face.png", 1); assert(s->img_face != 0); - s->img_map = nvgCreateImage(s->vg, "../assets/img_map.png", 1); - assert(s->img_map != 0); s->img_button_settings = nvgCreateImage(s->vg, "../assets/images/button_settings.png", 1); assert(s->img_button_settings != 0); s->img_button_home = nvgCreateImage(s->vg, "../assets/images/button_home.png", 1); diff --git a/selfdrive/ui/qt/ui.cc b/selfdrive/ui/qt/ui.cc index 2948a805a1..9319227d4d 100644 --- a/selfdrive/ui/qt/ui.cc +++ b/selfdrive/ui/qt/ui.cc @@ -2,8 +2,7 @@ #include "window.hpp" -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { QSurfaceFormat fmt; #ifdef __APPLE__ fmt.setVersion(3, 2); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 5269beaab2..8fa9e8e316 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -25,12 +25,8 @@ int write_param_float(float param, const char* param_name, bool persistent_param void ui_init(UIState *s) { pthread_mutex_init(&s->lock, NULL); s->sm = new SubMaster({"model", "controlsState", "uiLayoutState", "liveCalibration", "radarState", "thermal", - "health", "ubloxGnss", "driverState", "dMonitoringState" -#ifdef SHOW_SPEEDLIMIT - , "liveMapData" -#endif + "health", "carParams", "ubloxGnss", "driverState", "dMonitoringState" }); - s->pm = new PubMaster({"offroadLayout"}); s->ipc_fd = -1; s->scene.satelliteCount = -1; @@ -70,15 +66,9 @@ static void ui_init_vision(UIState *s, const VisionStreamBufs back_bufs, s->rgb_front_stride = front_bufs.stride; s->rgb_front_buf_len = front_bufs.buf_len; - read_param(&s->speed_lim_off, "SpeedLimitOffset"); read_param(&s->is_metric, "IsMetric"); read_param(&s->longitudinal_control, "LongitudinalControl"); - read_param(&s->limit_set_speed, "LimitSetSpeed"); - - // Set offsets so params don't get read at the same time - s->longitudinal_control_timeout = UI_FREQ / 3; - s->is_metric_timeout = UI_FREQ / 2; - s->limit_set_speed_timeout = UI_FREQ; + s->is_metric_timeout = UI_FREQ; } void update_status(UIState *s, int status) { @@ -96,10 +86,9 @@ static inline void fill_path_points(const cereal::ModelData::PathData::Reader &p void handle_message(UIState *s, SubMaster &sm) { UIScene &scene = s->scene; - if (s->started && sm.updated("controlsState")) { + if (sm.updated("controlsState")) { auto event = sm["controlsState"]; scene.controls_state = event.getControlsState(); - s->controls_timeout = 1 * UI_FREQ; s->controls_seen = true; auto alert_sound = scene.controls_state.getAlertSound(); @@ -174,11 +163,6 @@ void handle_message(UIState *s, SubMaster &sm) { s->active_app = data.getActiveApp(); scene.uilayout_sidebarcollapsed = data.getSidebarCollapsed(); } -#ifdef SHOW_SPEEDLIMIT - if (sm.updated("liveMapData")) { - scene.map_valid = sm["liveMapData"].getLiveMapData().getMapValid(); - } -#endif if (sm.updated("thermal")) { scene.thermal = sm["thermal"].getThermal(); } @@ -190,7 +174,9 @@ void handle_message(UIState *s, SubMaster &sm) { } if (sm.updated("health")) { scene.hwType = sm["health"].getHealth().getHwType(); - s->hardware_timeout = 5*UI_FREQ; // 5 seconds + } + if (sm.updated("carParams")) { + s->longitudinal_control = sm["carParams"].getCarParams().getOpenpilotLongitudinalControl(); } if (sm.updated("driverState")) { scene.driver_state = sm["driverState"].getDriverState(); @@ -199,10 +185,7 @@ void handle_message(UIState *s, SubMaster &sm) { scene.dmonitoring_state = sm["dMonitoringState"].getDMonitoringState(); scene.is_rhd = scene.dmonitoring_state.getIsRHD(); scene.frontview = scene.dmonitoring_state.getIsPreview(); - } - - // timeout on frontview - if ((sm.frame - sm.rcv_frame("dMonitoringState")) > 1*UI_FREQ) { + } else if ((sm.frame - sm.rcv_frame("dMonitoringState")) > 1*UI_FREQ) { scene.frontview = false; } diff --git a/selfdrive/ui/ui.hpp b/selfdrive/ui/ui.hpp index 7db7f6f0a8..544b95a792 100644 --- a/selfdrive/ui/ui.hpp +++ b/selfdrive/ui/ui.hpp @@ -50,8 +50,6 @@ #endif #define UI_BUF_COUNT 4 -//#define SHOW_SPEEDLIMIT 1 -//#define DEBUG_TURN // TODO: Detect dynamically #ifdef QCOM2 @@ -114,9 +112,7 @@ typedef struct UIScene { bool speedlimit_valid; bool is_rhd; - bool map_valid; bool uilayout_sidebarcollapsed; - bool uilayout_mapenabled; // responsive layout int ui_viz_rx; int ui_viz_rw; @@ -144,7 +140,7 @@ typedef struct UIScene { typedef struct { float x, y; -}vertex_data; +} vertex_data; typedef struct { vertex_data v[MODEL_PATH_MAX_VERTICES_CNT]; @@ -174,7 +170,6 @@ typedef struct UIState { int img_wheel; int img_turn; int img_face; - int img_map; int img_button_settings; int img_button_home; int img_battery; @@ -183,7 +178,6 @@ typedef struct UIState { // sockets SubMaster *sm; - PubMaster *pm; cereal::UiLayoutState::App active_app; @@ -219,12 +213,7 @@ typedef struct UIState { // timeouts int awake_timeout; - int controls_timeout; - int speed_lim_off_timeout; int is_metric_timeout; - int longitudinal_control_timeout; - int limit_set_speed_timeout; - int hardware_timeout; int last_athena_ping_timeout; bool controls_seen; @@ -233,8 +222,6 @@ typedef struct UIState { int status; bool is_metric; bool longitudinal_control; - bool limit_set_speed; - float speed_lim_off; bool is_ego_over_limit; float alert_blinking_alpha; bool alert_blinked;