Files
gps-denied-onboard/src/vio_adapter/native/basalt.py
T
Oleksandr Bezdieniezhnykh 2425f8e6fd [AZ-243] Integrate production native VIO runtime
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-07 00:04:46 +03:00

48 lines
1.6 KiB
Python

"""Loader for installed BASALT-compatible VIO runtime packages."""
from collections.abc import Mapping
from importlib import import_module
from typing import Any
from vio_adapter.interfaces import NativeVioRunner, VioBackendError
from vio_adapter.types import VioBackendEstimate
class BasaltNativeRunner:
"""Adapts an installed BASALT binding to the VIO runner protocol."""
def __init__(
self,
module_name: str = "basalt_vio",
factory_name: str = "create_runner",
config: Mapping[str, object] | None = None,
) -> None:
self._module_name = module_name
self._factory_name = factory_name
self._config = dict(config or {})
self._runner: NativeVioRunner | None = None
def initialize(self) -> None:
try:
module = import_module(self._module_name)
factory = getattr(module, self._factory_name)
runner = factory(**self._config)
except Exception as exc:
raise VioBackendError(
f"unable to load BASALT runtime {self._module_name}:{self._factory_name}"
) from exc
if not isinstance(runner, NativeVioRunner):
raise VioBackendError(
f"BASALT runtime {self._module_name}:{self._factory_name} "
"does not implement NativeVioRunner"
)
self._runner = runner
self._runner.initialize()
def estimate(self, frame: Any, telemetry_window: tuple[Any, ...]) -> VioBackendEstimate:
if self._runner is None:
raise VioBackendError("BASALT runtime is not initialized")
return self._runner.estimate(frame, telemetry_window)