Files
Apollo3D_SE/world/commons/field_landmarks.py

42 lines
1.4 KiB
Python
Raw Normal View History

from __future__ import annotations
2026-03-10 09:35:27 -04:00
import numpy as np
2026-03-10 09:35:27 -04:00
from utils.math_ops import MathOps
class FieldLandmarks:
def __init__(self, field):
self.field = field
self.world = field.world
self.landmarks: dict[str, np.ndarray] = {}
self.canonical_landmarks: dict[str, np.ndarray] = field.get_canonical_landmarks()
2026-03-10 09:35:27 -04:00
def update_from_perception(self, landmark_id: str, landmark_pos: np.ndarray) -> None:
"""
Calculates the global position of all currently visible landmarks.
"""
world = self.world
local_cart_3d = MathOps.deg_sph2cart(landmark_pos)
global_pos_3d = MathOps.rel_to_global_3d(
local_pos_3d=local_cart_3d,
global_pos_3d=world.global_position,
global_orientation_quat=world.agent.robot.global_orientation_quat,
2026-03-10 09:35:27 -04:00
)
self.landmarks[landmark_id] = global_pos_3d
def get_landmark_position(
self, landmark_id: str, use_canonical: bool = False
) -> np.ndarray | None:
2026-03-10 09:35:27 -04:00
"""
Returns the current perceived or canonical global position for a landmark.
2026-03-10 09:35:27 -04:00
"""
source = self.canonical_landmarks if use_canonical else self.landmarks
return source.get(landmark_id)
def get_canonical_landmark_position(self, landmark_id: str) -> np.ndarray | None:
return self.canonical_landmarks.get(landmark_id)