Gridded UI

From comma wiki
Jump to: navigation, search

Some people would like a gridded UI to make NEO/EON alignment to the horizon, etc. easier.

For those that prefer to learn via Video:

Manual steps (Helpful to understand, even if you follow a video above):

SSH into NEOS, then...

cd /data/openpilot/selfdrive/ui
cp ui.c ui.c.bak
vim ui.c

Find the right section... Hit the forward slash '/', type static void ui_draw_vision_header, then hit <ENTER>.

Add this line before the closing brace...


[For vim novices, hit 'i' to go into INSERT MODE, paste the text, then <ESCAPE> to leave INSERT MODE.]

Before that ui_draw_vision_header section, add this new section, bearing in mind that using :set paste turns off vim's auto-indent, making pasting cleaner...

static void ui_draw_vision_grid(UIState *s) {
  const UIScene *scene = &s->scene;
  bool is_cruise_set = (s->scene.v_cruise != 0 && s->scene.v_cruise != 255);
  if (!is_cruise_set) {
    const int grid_spacing = 30;

    int ui_viz_rx = scene->ui_viz_rx;
    int ui_viz_rw = scene->ui_viz_rw;


    // path coords are worked out in rgb-box space
    nvgTranslate(s->vg, 240.0f, 0.0);

    // zooom in 2x
    nvgTranslate(s->vg, -1440.0f / 2, -1080.0f / 2);
    nvgScale(s->vg, 2.0, 2.0);

    nvgScale(s->vg, 1440.0f / s->rgb_width, 1080.0f / s->rgb_height);

    nvgStrokeColor(s->vg, nvgRGBA(255,255,255,128));
    nvgStrokeWidth(s->vg, 1);

    for (int i=box_y; i < box_h; i+=grid_spacing) {
      nvgMoveTo(s->vg, ui_viz_rx, i);
      //nvgLineTo(s->vg, ui_viz_rx, i);
      nvgLineTo(s->vg, ((ui_viz_rw + ui_viz_rx) / 2)+ 10, i);

    for (int i=ui_viz_rx + 12; i <= ui_viz_rw; i+=grid_spacing) {
      nvgMoveTo(s->vg, i, 0);
      nvgLineTo(s->vg, i, 1000);

If you're still in any INSERT, PASTE, etc. mode, hit <ESCAPE>, then write (save) & quit (exit) via :wq

Compile the code... make

Reboot NEOS. As long as you don't let auto-updates overwrite the changes, the gridded UI should persist.

Test the gridded UI by driving or just run the Vision daemon directly... /data/openpilot/selfdrive/visiond/visiond