File size: 1,393 Bytes
85407a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""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)