MESH-Benchmark / code /generation /native /multi_robot_coordinates.py
Heiheihaha17's picture
Add files using upload-large-folder tool
85407a7 verified
Raw History Blame Contribute Delete
1.39 kB
"""Multi-robot coordinates: yaw 0 faces -Z, positive yaw turns towards +X.
Kept separate from the frozen single-robot V1/V2 coordinate implementations.
"""
import hashlib
import math
import numpy as np
def opaque_id(namespace, value):
return hashlib.sha256(f"ease-mr-v2/{namespace}/{value}".encode()).hexdigest()[:24]
def local_geometry(receiver, yaw_deg, source):
delta = np.asarray(source, dtype=np.float64) - np.asarray(receiver, dtype=np.float64)
world = math.degrees(math.atan2(float(delta[0]), -float(delta[2])))
return {
"delta_world_xyz_m": delta.tolist(),
"distance_m": float(np.linalg.norm(delta)),
"world_azimuth_deg": world,
"local_azimuth_deg": (world - float(yaw_deg) + 180.0) % 360.0 - 180.0,
"elevation_deg": math.degrees(math.atan2(float(delta[1]), math.hypot(delta[0], delta[2]))),
}
def native_to_ambix_robot(rir, mapping, yaw_deg):
w = mapping["w_polarity"] * rir[mapping["w_channel"]]
world = {axis: item["polarity"] * rir[item["channel"]] / math.sqrt(3.0)
for axis, item in mapping["world_axis_mapping"].items()}
yaw = math.radians(yaw_deg)
right = math.cos(yaw) * world["world_x"] + math.sin(yaw) * world["world_z"]
front = math.sin(yaw) * world["world_x"] - math.cos(yaw) * world["world_z"]
return np.stack([w, -right, world["world_y"], front]).astype(np.float32)