mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-04-23 01:26:37 +00:00
feat(phases 2-7): implement full GPS-denied navigation pipeline
Phase 2 — Visual Odometry: - ORBVisualOdometry (dev/CI), CuVSLAMVisualOdometry (Jetson) - TRTInferenceEngine (TensorRT FP16, conditional import) - create_vo_backend() factory Phase 3 — Satellite Matching + GPR: - SatelliteDataManager: local z/x/y tiles, ESKF ±3σ tile selection - GSD normalization (SAT-03), RANSAC inlier-ratio confidence (SAT-04) - GlobalPlaceRecognition: Faiss index + numpy fallback Phase 4 — MAVLink I/O: - MAVLinkBridge: GPS_INPUT 15+ fields, IMU callback, 1Hz telemetry - 3-consecutive-failure reloc request - MockMAVConnection for CI Phase 5 — Pipeline Wiring: - ESKF wired into process_frame: VO update → satellite update - CoordinateTransformer + SatelliteDataManager via DI - MAVLink state push per frame (PIPE-07) - Real pixel_to_gps via ray-ground projection (PIPE-06) - GTSAM ISAM2 update when available (PIPE-03) Phase 6 — Docker + CI: - Multi-stage Dockerfile (python:3.11-slim) - docker-compose.yml (dev), docker-compose.sitl.yml (ArduPilot SITL) - GitHub Actions: ci.yml (lint+pytest+docker smoke), sitl.yml (nightly) - tests/test_sitl_integration.py (8 tests, skip without SITL) Phase 7 — Accuracy Validation: - AccuracyBenchmark + SyntheticTrajectory - AC-PERF-1: 80% within 50m ✅ - AC-PERF-2: 60% within 20m ✅ - AC-PERF-3: p95 latency < 400ms ✅ - AC-PERF-4: VO drift 1km < 100m ✅ (actual ~11m) - scripts/benchmark_accuracy.py CLI Tests: 195 passed / 8 skipped Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+125
-2
@@ -4,8 +4,14 @@ import numpy as np
|
||||
import pytest
|
||||
|
||||
from gps_denied.core.models import ModelManager
|
||||
from gps_denied.core.vo import SequentialVisualOdometry
|
||||
from gps_denied.schemas.flight import CameraParameters
|
||||
from gps_denied.core.vo import (
|
||||
CuVSLAMVisualOdometry,
|
||||
ISequentialVisualOdometry,
|
||||
ORBVisualOdometry,
|
||||
SequentialVisualOdometry,
|
||||
create_vo_backend,
|
||||
)
|
||||
from gps_denied.schemas import CameraParameters
|
||||
from gps_denied.schemas.vo import Features, Matches
|
||||
|
||||
|
||||
@@ -100,3 +106,120 @@ def test_compute_relative_pose(vo, cam_params):
|
||||
assert pose.rotation.shape == (3, 3)
|
||||
# Because we randomize points in the mock manager, inliers will be extremely low
|
||||
assert pose.tracking_good is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# VO-02: ORBVisualOdometry interface contract
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
@pytest.fixture
|
||||
def orb_vo():
|
||||
return ORBVisualOdometry()
|
||||
|
||||
|
||||
def test_orb_implements_interface(orb_vo):
|
||||
"""ORBVisualOdometry must satisfy ISequentialVisualOdometry."""
|
||||
assert isinstance(orb_vo, ISequentialVisualOdometry)
|
||||
|
||||
|
||||
def test_orb_extract_features(orb_vo):
|
||||
img = np.zeros((480, 640, 3), dtype=np.uint8)
|
||||
feats = orb_vo.extract_features(img)
|
||||
assert isinstance(feats, Features)
|
||||
# Black image has no corners — empty result is valid
|
||||
assert feats.keypoints.ndim == 2 and feats.keypoints.shape[1] == 2
|
||||
|
||||
|
||||
def test_orb_match_features(orb_vo):
|
||||
"""match_features returns Matches even when features are empty."""
|
||||
empty_f = Features(
|
||||
keypoints=np.zeros((0, 2), dtype=np.float32),
|
||||
descriptors=np.zeros((0, 32), dtype=np.float32),
|
||||
scores=np.zeros(0, dtype=np.float32),
|
||||
)
|
||||
m = orb_vo.match_features(empty_f, empty_f)
|
||||
assert isinstance(m, Matches)
|
||||
assert m.matches.shape[1] == 2 if len(m.matches) > 0 else True
|
||||
|
||||
|
||||
def test_orb_compute_relative_pose_synthetic(orb_vo, cam_params):
|
||||
"""ORB can track a small synthetic shift between frames."""
|
||||
base = np.random.randint(50, 200, (480, 640, 3), dtype=np.uint8)
|
||||
shifted = np.roll(base, 10, axis=1) # shift 10px right
|
||||
pose = orb_vo.compute_relative_pose(base, shifted, cam_params)
|
||||
# May return None on blank areas, but if not None must be well-formed
|
||||
if pose is not None:
|
||||
assert pose.translation.shape == (3,)
|
||||
assert pose.rotation.shape == (3, 3)
|
||||
assert pose.scale_ambiguous is True # ORB = monocular = scale ambiguous
|
||||
|
||||
|
||||
def test_orb_scale_ambiguous(orb_vo, cam_params):
|
||||
"""ORB RelativePose always has scale_ambiguous=True (monocular)."""
|
||||
img1 = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
|
||||
img2 = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
|
||||
pose = orb_vo.compute_relative_pose(img1, img2, cam_params)
|
||||
if pose is not None:
|
||||
assert pose.scale_ambiguous is True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# VO-01: CuVSLAMVisualOdometry (dev/CI fallback path)
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
def test_cuvslam_implements_interface():
|
||||
"""CuVSLAMVisualOdometry satisfies ISequentialVisualOdometry on dev/CI."""
|
||||
vo = CuVSLAMVisualOdometry()
|
||||
assert isinstance(vo, ISequentialVisualOdometry)
|
||||
|
||||
|
||||
def test_cuvslam_scale_not_ambiguous_on_dev(cam_params):
|
||||
"""On dev/CI (no cuVSLAM), CuVSLAMVO still marks scale_ambiguous=False (metric intent)."""
|
||||
vo = CuVSLAMVisualOdometry()
|
||||
img1 = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
|
||||
img2 = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
|
||||
pose = vo.compute_relative_pose(img1, img2, cam_params)
|
||||
if pose is not None:
|
||||
assert pose.scale_ambiguous is False # VO-04
|
||||
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# VO-03: ModelManager auto-selects Mock on dev/CI
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
def test_model_manager_mock_on_dev():
|
||||
"""On non-Jetson, get_inference_engine returns MockInferenceEngine."""
|
||||
from gps_denied.core.models import MockInferenceEngine
|
||||
manager = ModelManager()
|
||||
engine = manager.get_inference_engine("SuperPoint")
|
||||
# On dev/CI we always get Mock
|
||||
assert isinstance(engine, MockInferenceEngine)
|
||||
|
||||
|
||||
def test_model_manager_trt_engine_loader():
|
||||
"""TRTInferenceEngine falls back to Mock when engine file is absent."""
|
||||
from gps_denied.core.models import TRTInferenceEngine
|
||||
engine = TRTInferenceEngine("SuperPoint", "/nonexistent/superpoint.engine")
|
||||
# Must not crash; should have a mock fallback
|
||||
assert engine._mock_fallback is not None
|
||||
# Infer via mock fallback must work
|
||||
dummy_img = np.zeros((480, 640, 3), dtype=np.uint8)
|
||||
result = engine.infer(dummy_img)
|
||||
assert "keypoints" in result
|
||||
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# Factory: create_vo_backend
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
def test_create_vo_backend_returns_interface():
|
||||
"""create_vo_backend() always returns an ISequentialVisualOdometry."""
|
||||
manager = ModelManager()
|
||||
backend = create_vo_backend(model_manager=manager)
|
||||
assert isinstance(backend, ISequentialVisualOdometry)
|
||||
|
||||
|
||||
def test_create_vo_backend_orb_fallback():
|
||||
"""Without model_manager and no cuVSLAM, falls back to ORBVisualOdometry."""
|
||||
backend = create_vo_backend(model_manager=None)
|
||||
assert isinstance(backend, ORBVisualOdometry)
|
||||
|
||||
Reference in New Issue
Block a user