diff --git a/openpilot/starpilot/ui/onroad_personality.py b/openpilot/starpilot/ui/onroad_personality.py index 37cedd7f69..12072ed575 100644 --- a/openpilot/starpilot/ui/onroad_personality.py +++ b/openpilot/starpilot/ui/onroad_personality.py @@ -56,16 +56,15 @@ class PersonalityWidget: driver_feedback = profile == Profile.LARGE or state.appearance.wheel_pedal_feedback self.draw(rect, personality=state.personality, has_lead=state.lead_detected, longitudinal_active=state.cruise_active, traffic_mode=state.traffic_selected or state.traffic_mode, - gas_override=state.gas_pressed_override and driver_feedback, visible=routine, - white_disengaged=profile == Profile.COMPACT) + gas_override=state.gas_pressed_override and driver_feedback, visible=routine) def draw(self, rect: rl.Rectangle, *, personality: int, has_lead: bool, longitudinal_active: bool, - traffic_mode: bool = False, gas_override: bool = False, visible: bool = True, fit: bool = True, white_disengaged: bool = False) -> None: + traffic_mode: bool = False, gas_override: bool = False, visible: bool = True, fit: bool = True) -> None: self._prepare() assert self._lead_car is not None alpha = self._alpha_filter.update(visible) engaged_lead = has_lead and longitudinal_active - white_target = 0.0 if engaged_lead else (1.0 if has_lead or white_disengaged and not longitudinal_active else 0.35) + white_target = 0.0 if engaged_lead else (1.0 if has_lead else 0.35) white_f, green_f = self._lead_car_filters if not longitudinal_active: white_f.x, green_f.x = white_target, 0.0 diff --git a/openpilot/starpilot/ui/tests/test_long_indicator.py b/openpilot/starpilot/ui/tests/test_long_indicator.py index bb46691aac..c57dacc0d1 100644 --- a/openpilot/starpilot/ui/tests/test_long_indicator.py +++ b/openpilot/starpilot/ui/tests/test_long_indicator.py @@ -44,10 +44,23 @@ def test_same_selected_bars_and_lead_on_both_profiles(display, profile, personal draws = settle(display, road(personality=personality)) assert draws[1].args[3] > .999 assert all(draws[2 + 2*i].args[3] == pytest.approx(.9 if i <= personality else .35, abs=.001) for i in range(3)) - for has_lead, active, white, green in ((False, True, .35, 0), (True, False, 1, 0), (True, True, 0, 1)): - draws = settle(display, road(lead_detected=has_lead, longitudinal_active=active)) - assert draws[0].args[3] == pytest.approx(white, abs=.001) - assert draws[1].args[3] == pytest.approx(green, abs=.001) + + +@pytest.mark.parametrize('profile', list(Profile)) +@pytest.mark.parametrize(('lateral', 'longitudinal', 'has_lead', 'white', 'green'), ( + pytest.param(False, False, False, .35, 0., id='disengaged-no-lead'), + pytest.param(False, False, True, 1., 0., id='disengaged-lead'), + pytest.param(True, False, False, .35, 0., id='aol-no-lead'), + pytest.param(True, False, True, 1., 0., id='aol-lead'), + pytest.param(True, True, False, .35, 0., id='longitudinal-no-lead'), + pytest.param(True, True, True, 0., 1., id='longitudinal-lead'), +)) +def test_lead_feedback_tracks_detection_and_longitudinal_engagement(display, profile, lateral, longitudinal, has_lead, white, green): + display.fonts.profile = profile + draws = settle(display, road(engaged=lateral or longitudinal, lateral_active=lateral, + longitudinal_active=longitudinal, lead_detected=has_lead)) + assert draws[0].args[3] == pytest.approx(white, abs=.001) + assert draws[1].args[3] == pytest.approx(green, abs=.001) @pytest.mark.parametrize('traffic', (False, True)) @@ -235,7 +248,7 @@ def test_default_compact_lead_and_distance_feedback(display, monkeypatch): settle(display, state) assert display._draw_centered.call_args_list[-8].args[3] == pytest.approx(.35) settle(display, replace(state, longitudinal_active=False)) - assert display._draw_centered.call_args_list[-8].args[3] == pytest.approx(1.) + assert display._draw_centered.call_args_list[-8].args[3] == pytest.approx(.35) settle(display, replace(state, lead_detected=True)) assert display._draw_centered.call_args_list[-7].args[3] == pytest.approx(1., abs=.001)