feat: add error graphic
This commit is contained in:
12
autopilot.py
12
autopilot.py
@@ -3,6 +3,7 @@ import cv2
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
import math
|
||||
from visualization import VisualizationManager
|
||||
|
||||
random.seed(1)
|
||||
|
||||
@@ -10,6 +11,7 @@ class Pilot:
|
||||
def __init__(self): pass
|
||||
def handle(self, image: Image): pass
|
||||
def act(self) -> tuple[float, float] | None: pass
|
||||
def get_position(self) -> tuple[float, float]: pass
|
||||
|
||||
class AutoPilot(Pilot):
|
||||
prev_image: np.ndarray | None
|
||||
@@ -20,7 +22,7 @@ class AutoPilot(Pilot):
|
||||
bf_matcher: cv2.BFMatcher
|
||||
frame_count: int
|
||||
image_center: tuple # Центр изображения (x, y)
|
||||
viz_manager: object # Менеджер визуализации (опционально)
|
||||
viz_manager: VisualizationManager # Менеджер визуализации (опционально)
|
||||
|
||||
def __init__(self, viz_manager=None):
|
||||
self.prev_image = None
|
||||
@@ -46,6 +48,9 @@ class AutoPilot(Pilot):
|
||||
# Инициализация матчера для сопоставления ключевых точек
|
||||
self.bf_matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
|
||||
|
||||
def get_position(self):
|
||||
return self.x, self.y
|
||||
|
||||
def image_to_numpy(self, image: Image.Image) -> np.ndarray:
|
||||
"""Конвертирует PIL Image в numpy array для OpenCV"""
|
||||
return np.array(image)
|
||||
@@ -255,6 +260,7 @@ class AutoPilot(Pilot):
|
||||
|
||||
# Выводим текущее состояние БПЛА
|
||||
drone_state = self.get_drone_state()
|
||||
self.viz_manager.update_drone_trajectory(drone_state['x'], drone_state['y'])
|
||||
print(f" [Pilot] Drone Position: ({drone_state['x']:.2f}, {drone_state['y']:.2f})")
|
||||
print(f" [Pilot] Angle: {drone_state['angle_degrees']:.1f}°")
|
||||
|
||||
@@ -285,7 +291,7 @@ class AutoPilot(Pilot):
|
||||
distance_to_target = math.sqrt(self.x**2 + self.y**2)
|
||||
|
||||
# Если дрон находится рядом с целью, останавливаемся
|
||||
if distance_to_target < 10.0:
|
||||
if distance_to_target < 30.0:
|
||||
return None
|
||||
|
||||
# Вычисляем угол к цели
|
||||
@@ -320,7 +326,7 @@ class RandomPilot(Pilot):
|
||||
|
||||
def act(self) -> tuple[float, float] | None:
|
||||
self.counter += 1
|
||||
if self.counter > 40:
|
||||
if self.counter > 300:
|
||||
return None
|
||||
|
||||
return 1 / (self.counter + 20), 10.0
|
||||
|
||||
Reference in New Issue
Block a user