openpilot icon indicating copy to clipboard operation
openpilot copied to clipboard

ui/map: roundabout icon fix

Open jakethesnake420 opened this issue 2 years ago • 10 comments

Should now show the correct roundabout/rotary entry/exit icon. This uses the existing rhd logic to mirror the icons. This is not a great solution if someone is driving a lhd car in rhd traffic and vise versa. In this case it would not display the icon.

Also its possible to have a 0 degree roundabout which requires another icon like this: image

For now I have just used the existing 'direction_roundabout.png' icon renamed to 'direction_roundabout_right_0.png'.

resolves: https://github.com/commaai/openpilot/issues/25480

Also this needs to be tested better. I just tried a simulated lhd 90 and a rhd 270.

jakethesnake420 avatar Aug 30 '23 02:08 jakethesnake420

I've created a new icon for 0 degrees which matches the current style

direction_roundabout_right_0

incognitojam avatar Aug 30 '23 14:08 incognitojam

Can you open a PR for the cereal addition too?

incognitojam avatar Aug 30 '23 15:08 incognitojam

Can you open a PR for the cereal addition too?

done https://github.com/commaai/cereal/pull/526

jakethesnake420 avatar Aug 30 '23 17:08 jakethesnake420

I don't think it can get much better than what I have here with 5 lines of easy to read code

jakethesnake420 avatar Aug 31 '23 04:08 jakethesnake420

Gonna bump this since this is still a problem. I really don't see how my solution would interfere with the model since I am not affecting it at all. This is only adjusting how the manuevers are displayed which is all that needs to be done. Doing it in navd is the wrong way to do it for many reasons.

jakethesnake420 avatar Nov 20 '23 09:11 jakethesnake420

This PR has had no activity for 30 days. It will be automatically closed in 7 days if there is no activity.

github-actions[bot] avatar Dec 21 '23 01:12 github-actions[bot]

So this PR is mostly blocked by a lack of a good way to test this. Can you come up with a good way to test this and other related changes?

adeebshihadeh avatar Dec 21 '23 04:12 adeebshihadeh

@adeebshihadeh might be good to make a general UI state controller. Would also be useful for the UI screenshot compare CI tool.

The way I tested it before was replaying a route that had a roundabout which is inconvenient.

jakethesnake420 avatar Dec 21 '23 22:12 jakethesnake420

All i am really willing to do at this point is prove that changing the degrees modifier displays the correct icon as the mapbox API specifies here: image Making a proper test is kind of a big job and considering it's been broken since nav icons were added... whatever. I made a little test script to set the modifier and took some screenshots with left and right hand drive. Note that I used mapbox api responses copied from the API playground and used the parse_banner_instructions function just like navd.py does. I then overwrote the degrees value and sent the modified instruction to the UI.

LHD Screenshots

Screenshot from 2023-12-23 02-17-29 Screenshot from 2023-12-23 02-17-34 Screenshot from 2023-12-23 02-17-39 Screenshot from 2023-12-23 02-17-47 Screenshot from 2023-12-23 02-17-51 Screenshot from 2023-12-23 02-17-55 Screenshot from 2023-12-23 02-17-58 Screenshot from 2023-12-23 02-18-02 Screenshot from 2023-12-23 02-18-07

RHD Screenshots

RHD:

Screenshot from 2023-12-23 02-14-12 Screenshot from 2023-12-23 02-14-19 Screenshot from 2023-12-23 02-14-22 Screenshot from 2023-12-23 02-14-25 Screenshot from 2023-12-23 02-14-28 Screenshot from 2023-12-23 02-14-33 Screenshot from 2023-12-23 02-14-36 Screenshot from 2023-12-23 02-14-41 Screenshot from 2023-12-23 02-14-45

Test Script I had to modify the UI code to actually get it to show the map all the time. Also had to remove some UI code for llk math. if you want to run it, make sure the first banner instruction is a roundabout or modify the script to search for roundabouts. I spent as little time as possible to make it work for my testing.
from openpilot.common.api import Api
import cereal.messaging as messaging
import time
from openpilot.selfdrive.navd.tests.test_map_renderer import LOCATION1, LOCATION2, gen_llk
from openpilot.selfdrive.navd.helpers import parse_banner_instructions, coordinate_from_param
import json
from common.params import Params
import copy

resp = json.loads(LHD)
resp = json.loads(RHD)
instructions = []
for i, step_i in enumerate(resp['routes'][0]['legs'][0]['steps']):
    if 'bannerInstructions' in step_i:
        banners = parse_banner_instructions(step_i['bannerInstructions'], 100)
        instructions.append(banners)
        break # get one only and fake the rest

def simulate_instructions():
    for i in range(0,36):
        new = copy.copy(instructions[0])
        new['maneuverDegrees'] = 10*i
        instructions.append(new)

class NavigationIconTest():
    def __init__(self) -> None:
        self.params = Params()
        pm = messaging.PubMaster(['pandaStates', 'deviceState', 'navInstruction', 'navRoute', 'modelV2', 'controlsState', 'liveLocationKalman', 'managerState'])
        pandaStates = messaging.new_message('pandaStates',size=1)
        pandaStates.pandaStates[0] = {"pandaType": "tres",
                                      "ignitionLine": True}
        manager = messaging.new_message('managerState', valid=True)
        manager.managerState.processes = [{'name': "ui",
                                'pid': 1,
                                'running': True,
                                }]
        
        llk = messaging.new_message('liveLocationKalman', valid=True)
        llk.liveLocationKalman.positionGeodetic = {'value': [*LOCATION1, 0], 'std': [0., 0., 0.], 'valid': True}
        llk.liveLocationKalman.calibratedOrientationNED = {'value': [0., 0., 0.], 'std': [0., 0., 0.], 'valid': True}
        llk.liveLocationKalman.status = 'valid'
        device_dat = messaging.new_message('deviceState', valid=True)
        self.instruction_dat = messaging.new_message('navInstruction', valid=True)
        route_dat = messaging.new_message('navRoute', valid=True)
        cs = messaging.new_message('controlsState', valid=True)
        cs.controlsState.enabled = True
        model_dat = messaging.new_message('modelV2', valid=True)
        model_dat.modelV2.navEnabled = True
        device_dat.deviceState.started = True
        simulate_instructions()
        self.params.put_bool("IsRhdDetected", False)
        for i in self.banner_gen():
            pm.send('managerState', manager)
            pm.send('pandaStates', pandaStates)
            pm.send('deviceState', device_dat)
            pm.send('navRoute', route_dat)
            pm.send('navInstruction', self.instruction_dat)
            pm.send('modelV2', model_dat)
            pm.send('controlsState', cs)
            pm.send("liveLocationKalman",llk)
            time.sleep(.1)
    
    def banner_gen(self):
        for banner in instructions:
            if banner is not None:
                for k,v in banner.items():
                    setattr(self.instruction_dat.navInstruction, k, v)
                yield
                    
    
if __name__ == "__main__":
    NavigationIconTest()

jakethesnake420 avatar Dec 22 '23 08:12 jakethesnake420

This PR has had no activity for 30 days. It will be automatically closed in 7 days if there is no activity.

github-actions[bot] avatar Jan 24 '24 01:01 github-actions[bot]