mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-27 18:03:48 +08:00
1a8dd310ae
* Add support for TinyGrad model runner processing Introduced a new function `is_tinygrad_model` to detect TinyGrad as an active model runner. Updated the `is_stock_model` logic to account for TinyGrad models and added a new process entry for TinyGrad in the model manager. This enables handling TinyGrad models alongside existing configurations. adding modeld back Add support for `modeld_v2` and update paths for consistency Updated `SConscript` files to integrate `modeld_v2` alongside `modeld` and adjusted script paths for correct metadata handling. Adjusted various configurations and scripts, such as `labeler.yaml` and `build_release.sh`, to include `modeld_v2` and ensure cohesive project structure. Refactor imports to use updated `modeld_v2` paths. Replaced outdated `modeld` references with their `modeld_v2` counterparts for consistency and clarity across the codebase. Also updated `.gitignore` to accommodate new directory structure. This change ensures better maintainability and alignment with the new directory schema. Refactor and reorganize modeld to sunnypilot/modeld_v2 structure. Moved and renamed `modeld` components to the new `sunnypilot/modeld_v2` directory for better organization and modularity. Updated imports and file references to align with the new structure, ensuring compatibility and functionality. Streamlined project structure to improve maintainability and future development. * typo * Use `stock` model runner and refactor model checks. Replaces outdated model detection logic with unified `stock` runner integration, simplifying the decision flow for model selection. Includes `stock` as a new enum in the `Runner` type and updates affected references accordingly. * Handle missing 'sim_pose' in model outputs gracefully. Added conditional checks to ensure the code handles cases where 'sim_pose' is absent in the model outputs. Fallback behaviors use 'plan' data when 'sim_pose' is unavailable, preventing potential errors and enhancing robustness.
103 lines
3.4 KiB
Python
103 lines
3.4 KiB
Python
import numpy as np
|
|
import random
|
|
|
|
import cereal.messaging as messaging
|
|
from msgq.visionipc import VisionIpcServer, VisionStreamType
|
|
from opendbc.car.car_helpers import get_demo_car_params
|
|
from openpilot.common.params import Params
|
|
from openpilot.common.transformations.camera import DEVICE_CAMERAS
|
|
from openpilot.common.realtime import DT_MDL
|
|
from openpilot.system.manager.process_config import managed_processes
|
|
from openpilot.selfdrive.test.process_replay.vision_meta import meta_from_camera_state
|
|
|
|
CAM = DEVICE_CAMERAS[("tici", "ar0231")].fcam
|
|
IMG = np.zeros(int(CAM.width*CAM.height*(3/2)), dtype=np.uint8)
|
|
IMG_BYTES = IMG.flatten().tobytes()
|
|
|
|
|
|
class TestModeld:
|
|
|
|
def setup_method(self):
|
|
self.vipc_server = VisionIpcServer("camerad")
|
|
self.vipc_server.create_buffers(VisionStreamType.VISION_STREAM_ROAD, 40, CAM.width, CAM.height)
|
|
self.vipc_server.create_buffers(VisionStreamType.VISION_STREAM_DRIVER, 40, CAM.width, CAM.height)
|
|
self.vipc_server.create_buffers(VisionStreamType.VISION_STREAM_WIDE_ROAD, 40, CAM.width, CAM.height)
|
|
self.vipc_server.start_listener()
|
|
Params().put("CarParams", get_demo_car_params().to_bytes())
|
|
|
|
self.sm = messaging.SubMaster(['modelV2', 'cameraOdometry'])
|
|
self.pm = messaging.PubMaster(['roadCameraState', 'wideRoadCameraState', 'liveCalibration'])
|
|
|
|
managed_processes['modeld'].start()
|
|
self.pm.wait_for_readers_to_update("roadCameraState", 10)
|
|
|
|
def teardown_method(self):
|
|
managed_processes['modeld'].stop()
|
|
del self.vipc_server
|
|
|
|
def _send_frames(self, frame_id, cams=None):
|
|
if cams is None:
|
|
cams = ('roadCameraState', 'wideRoadCameraState')
|
|
|
|
cs = None
|
|
for cam in cams:
|
|
msg = messaging.new_message(cam)
|
|
cs = getattr(msg, cam)
|
|
cs.frameId = frame_id
|
|
cs.timestampSof = int((frame_id * DT_MDL) * 1e9)
|
|
cs.timestampEof = int(cs.timestampSof + (DT_MDL * 1e9))
|
|
cam_meta = meta_from_camera_state(cam)
|
|
|
|
self.pm.send(msg.which(), msg)
|
|
self.vipc_server.send(cam_meta.stream, IMG_BYTES, cs.frameId,
|
|
cs.timestampSof, cs.timestampEof)
|
|
return cs
|
|
|
|
def _wait(self):
|
|
self.sm.update(5000)
|
|
if self.sm['modelV2'].frameId != self.sm['cameraOdometry'].frameId:
|
|
self.sm.update(1000)
|
|
|
|
def test_modeld(self):
|
|
for n in range(1, 500):
|
|
cs = self._send_frames(n)
|
|
self._wait()
|
|
|
|
mdl = self.sm['modelV2']
|
|
assert mdl.frameId == n
|
|
assert mdl.frameIdExtra == n
|
|
assert mdl.timestampEof == cs.timestampEof
|
|
assert mdl.frameAge == 0
|
|
assert mdl.frameDropPerc == 0
|
|
|
|
odo = self.sm['cameraOdometry']
|
|
assert odo.frameId == n
|
|
assert odo.timestampEof == cs.timestampEof
|
|
|
|
def test_dropped_frames(self):
|
|
"""
|
|
modeld should only run on consecutive road frames
|
|
"""
|
|
frame_id = -1
|
|
road_frames = list()
|
|
for n in range(1, 50):
|
|
if (random.random() < 0.1) and n > 3:
|
|
cams = random.choice([(), ('wideRoadCameraState', )])
|
|
self._send_frames(n, cams)
|
|
else:
|
|
self._send_frames(n)
|
|
road_frames.append(n)
|
|
self._wait()
|
|
|
|
if len(road_frames) < 3 or road_frames[-1] - road_frames[-2] == 1:
|
|
frame_id = road_frames[-1]
|
|
|
|
mdl = self.sm['modelV2']
|
|
odo = self.sm['cameraOdometry']
|
|
assert mdl.frameId == frame_id
|
|
assert mdl.frameIdExtra == frame_id
|
|
assert odo.frameId == frame_id
|
|
if n != frame_id:
|
|
assert not self.sm.updated['modelV2']
|
|
assert not self.sm.updated['cameraOdometry']
|