mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-28 00:53:45 +08:00
Clarify radar projection types without changing behavior
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
from collections import OrderedDict
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import threading
|
||||
from typing import TypedDict
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -9,11 +10,19 @@ from openpilot.cereal import log
|
||||
from openpilot.starpilot.longitudinal import toyota_output_policy as policy
|
||||
|
||||
|
||||
class ProjectionArguments(TypedDict):
|
||||
message_ns: int
|
||||
receipt_ns: int
|
||||
now_ns: int
|
||||
drive_id: int
|
||||
valid: bool
|
||||
|
||||
|
||||
class TestRadarLeadProjectionCache(unittest.TestCase):
|
||||
def setUp(self):
|
||||
with policy._RADAR_LEAD_LOCK:
|
||||
policy._RADAR_LEAD_ROWS.clear()
|
||||
self.kwargs = {'message_ns': 1_000_000_000, 'receipt_ns': 1_001_000_000,
|
||||
self.kwargs: ProjectionArguments = {'message_ns': 1_000_000_000, 'receipt_ns': 1_001_000_000,
|
||||
'now_ns': 1_002_000_000, 'drive_id': 900_000_000, 'valid': True}
|
||||
|
||||
def tearDown(self):
|
||||
@@ -80,6 +89,7 @@ class TestRadarLeadProjectionCache(unittest.TestCase):
|
||||
for _ in range(5):
|
||||
leads = policy.leads_from_radar(radar, **self.kwargs)
|
||||
self.assertIsNotNone(leads)
|
||||
assert leads is not None
|
||||
self.assertEqual(leads[0], policy.Lead(True, worker + 1., 0., 0., 0.))
|
||||
return True
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ source authority is lost. It does not select a planner profile or grant control.
|
||||
|
||||
from collections import OrderedDict
|
||||
from dataclasses import dataclass
|
||||
from typing import cast
|
||||
|
||||
import capnp
|
||||
import math
|
||||
@@ -60,7 +61,7 @@ def leads_from_radar(radar, *, message_ns: int, receipt_ns: int, now_ns: int,
|
||||
now_ns - message_ns > RADAR_MAX_AGE_NS or now_ns - receipt_ns > RADAR_MAX_AGE_NS):
|
||||
return None
|
||||
rows = _radar_lead_rows(radar)
|
||||
return tuple(Lead(*row) for row in rows) if rows is not None else None
|
||||
return cast(tuple[Lead, Lead], tuple(Lead(*row) for row in rows)) if rows is not None else None
|
||||
|
||||
|
||||
# Only immutable pure projection values are retained, never transport authority.
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "e1dcbcb17d8c48b0e4c07784d7872ba43d45f067e7043b019f61db708457124d", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "4303ba5948f7926d28d165289350db695927a393280d474174ee563a81c5a5a0", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user