Preview End to End Slowdown Before Engagement

This commit is contained in:
firestar5683
2026-11-28 23:35:38 -06:00
parent 65bf82f608
commit e05759f8f5
4 changed files with 73 additions and 2 deletions
@@ -316,6 +316,16 @@ class MiciSidebarWidgets:
self._stop_icon(center)
elif (preview is not None and preview.curve_curvature is not None and state.alert.size != AlertSize.FULL) or curve_controlling(state):
self._curve_icon(center)
elif state.e2e_preview_slowdown is not None and state.alert.size != AlertSize.FULL:
match state.e2e_preview_slowdown:
case 'Stopping':
self._stop_icon(center)
case 'Lead vehicle':
self._lead_icon(center)
case 'Curve':
self._curve_icon(center)
case _:
self._slowdown_icon(center)
elif conditional is not None and self.fonts is not None:
family, _, color = conditional
reason = conditional_reason(state)
@@ -379,6 +389,12 @@ class MiciSidebarWidgets:
def _lead_icon(self, rect: rl.Rectangle) -> None:
draw_lead_icon(rect)
def _slowdown_icon(self, rect: rl.Rectangle) -> None:
cx, cy = rect.x + rect.width / 2, rect.y + rect.height / 2
blue = rl.Color(112, 192, 216, 255)
_line(cx - 12, cy - 5, cx, cy + 7, blue, 4)
_line(cx, cy + 7, cx + 12, cy - 5, blue, 4)
def _stop_icon(self, rect: rl.Rectangle) -> None:
draw_stop_light_icon(rect)
+1
View File
@@ -185,6 +185,7 @@ class OnroadState:
experimental_available: bool = False
experimental_enabled: bool = False
e2e_slowdown: str | None = None
e2e_preview_slowdown: str | None = None
torque_utilization: float = 0.0
personality: int = 1
lead_detected: bool = False
+21 -2
View File
@@ -801,8 +801,27 @@ class RuntimeSnapshotAdapter:
drive_mode_source, display_car, cp=cp, drive_frame=after,
event_ns=int(sm.logMonoTime['starpilotCarState']) if drive_mode_source is not None else 0, now_ns=now_ns,
native_alert=alert, traffic_active=bool(traffic is not None and traffic.state == 'active'))
e2e_mode = observed_experimental and self._conditional_choice in (None, ModeChoice.STOCK)
e2e_preview_slowdown = None
if e2e_mode and not display_long_active and ui.has_longitudinal_control and display_car_valid:
model_action = getattr(display_model, 'action', None)
if getattr(model_action, 'shouldStop', False):
e2e_preview_slowdown = "Stopping"
else:
paired_plan = (display_plan is not None and display_model is not None and
getattr(display_plan, 'modelMonoTime', None) == sm.logMonoTime['modelV2'])
plan_target = getattr(display_plan, 'aTarget', 0.0) if paired_plan else 0.0
source = getattr(display_plan, 'longitudinalPlanSource', None) if paired_plan else None
model_target = getattr(model_action, 'desiredAcceleration', 0.0)
if math.isfinite(plan_target) and plan_target < -0.15 and source in ('lead0', 'lead1') and getattr(display_plan, 'hasLead', False):
e2e_preview_slowdown = "Lead vehicle"
elif (math.isfinite(plan_target) and plan_target < -0.15 and source == 'cruise' and
curve is not None and curve.applied and curve.controlling):
e2e_preview_slowdown = "Curve"
elif math.isfinite(model_target) and model_target < -0.15:
e2e_preview_slowdown = "Slowing"
e2e_slowdown = None
if (observed_experimental and self._conditional_choice in (None, ModeChoice.STOCK) and
if (e2e_mode and
display_long_active and not longitudinal_overridden and display_plan is not None):
target = getattr(display_plan, 'aTarget', None)
if bool(getattr(display_plan, 'shouldStop', False)):
@@ -833,7 +852,7 @@ class RuntimeSnapshotAdapter:
appearance=self._appearance_value, customization=self._customization_value,
alert=alert, metric=bool(ui.is_metric), slc_offset_schedule=self._slc_offset_schedule,
experimental_available=bool(ui.has_longitudinal_control),
experimental_enabled=observed_experimental, e2e_slowdown=e2e_slowdown,
experimental_enabled=observed_experimental, e2e_slowdown=e2e_slowdown, e2e_preview_slowdown=e2e_preview_slowdown,
personality=list(Personality).index(persona),
lead_detected=bool(display_plan is not None and display_plan.hasLead),
gas_pressed_override=bool(display_events is not None and any(
@@ -383,6 +383,41 @@ class TestOnroadAxes(unittest.TestCase):
companion.sourcePlanMonoTime -= 1
self.assertEqual(self.state(True, True).e2e_slowdown, 'Slowing')
def test_end_to_end_sidebar_previews_slowdown_without_longitudinal_engagement(self):
self.ui.params.put('ConditionalModeConfig', json.loads(encode_preferences(SavedPreferences(mode=ModeChoice.STOCK))), block=True)
sm = self.ui.sm
sm['selfdriveState'].experimentalMode = True
sm['selfdriveState'].enabled = False
sidebar = MiciSidebarWidgets(Mock())
center = rl.Rectangle(476, 80, 60, 80)
for stop, target, source, plan_stamp, expected in (
(True, -0.12, 'cruise', NOW, '_stop_icon'),
(False, -0.25, 'e2e', NOW, '_slowdown_icon'),
(False, -0.12, 'lead0', NOW, '_lead_icon'),
(False, -0.12, 'lead0', NOW - 1, '_chill_icon'),
(False, -0.12, 'cruise', NOW, '_chill_icon'),
):
with self.subTest(stop=stop, target=target, source=source, plan_stamp=plan_stamp):
sm.put('modelV2', NS(action=NS(shouldStop=stop, desiredAcceleration=target)))
sm.put('longitudinalPlan', NS(aTarget=-0.8, hasLead=source == 'lead0', shouldStop=False,
longitudinalPlanSource=source, modelMonoTime=plan_stamp))
for lateral in (True, False):
state = self.state(lateral, False)
self.assertFalse(state.longitudinal_active)
self.assertIsNone(state.e2e_slowdown)
self.assertEqual(rgba(axis_status_color(state)), (10, 186, 181, 255) if lateral else (18, 40, 57, 255))
with patch.multiple(sidebar, **{name: Mock() for name in ('_stop_icon', '_slowdown_icon', '_lead_icon',
'_curve_icon', '_chill_icon', '_speed_icon')}):
sidebar._conditional(center, state)
getattr(sidebar, expected).assert_called_once()
sidebar._speed_icon.assert_not_called()
sm.put('modelV2', NS(action=NS(shouldStop=True, desiredAcceleration=-0.5)))
sm.valid['modelV2'] = False
self.assertIsNone(self.state(True, False).e2e_preview_slowdown)
sm.valid['modelV2'] = True
sm['selfdriveState'].experimentalMode = False
self.assertIsNone(self.state(True, False).e2e_preview_slowdown)
def test_end_to_end_sidebar_uses_a_moon_until_the_planner_reports_a_specific_reason(self):
self.ui.params.put('ConditionalModeConfig', json.loads(encode_preferences(SavedPreferences(mode=ModeChoice.STOCK))), block=True)
self.ui.sm['selfdriveState'].experimentalMode = True