Local preservation snapshot, not a new deployment or simulation acceptance.
90 lines
3.4 KiB
Python
90 lines
3.4 KiB
Python
"""Independent native trace audit of command envelopes, without obstacle oracle input."""
|
|
|
|
import math
|
|
|
|
import numpy as np
|
|
from navigation.footprint import Footprint
|
|
|
|
SCHEMA = "missioncore.sweep-qualification/v1"
|
|
PHASES = (
|
|
("hold", 3, 0, 0),
|
|
("left-arc", 5, 1, 0.08),
|
|
("release-left", 3, 1, 0),
|
|
("right-arc", 5, 1, -0.5),
|
|
("stop", 3, 0, 0),
|
|
("pivot-left", 5, 0, 0.8),
|
|
("counterpivot-right", 5, 0, -0.8),
|
|
("hold-pivot", 3, 0, 0),
|
|
("reverse-curve", 4, -0.5, 0.2),
|
|
("resume-curve", 4, 1, -0.08),
|
|
("final-hold", 3, 0, 0),
|
|
)
|
|
CRITERIA = dict(
|
|
window_stride_seconds=0.25,
|
|
numerical_tolerance_m=1e-6,
|
|
all_body_vertices_inside=True,
|
|
phase_transition_first_frame_included=True,
|
|
complete_horizon_only=True,
|
|
scope="observed-obstacle envelope; flat simulated ground, not ground support or hardware",
|
|
)
|
|
|
|
|
|
def phase_metrics(rows, geometry):
|
|
"""Project measured 3D body vertices; never integrate the requested twist."""
|
|
monitor = Footprint(geometry)
|
|
speed, yaw_rate = rows[0]["request"]
|
|
bounds = monitor.command_bounds(speed, yaw_rate)
|
|
lower = np.array(bounds["lower_xy_m"]) - bounds["discrepancy_xy_m"]
|
|
upper = np.array(bounds["upper_xy_m"]) + bounds["discrepancy_xy_m"]
|
|
dt = rows[0]["dt"]
|
|
# Include the first measured tick at/after the horizon. Rounding down would
|
|
# leave up to one physics frame of the claimed stopping interval unaudited.
|
|
frames = math.ceil(bounds["horizon_seconds"] / dt)
|
|
stride = max(1, round(CRITERIA["window_stride_seconds"] / dt))
|
|
vertices = np.array(
|
|
[
|
|
[x, y, z]
|
|
for x in (-geometry["length_m"] / 2, geometry["length_m"] / 2)
|
|
for y in (-geometry["width_m"] / 2, geometry["width_m"] / 2)
|
|
for z in (-geometry["height_m"] / 2, geometry["height_m"] / 2)
|
|
]
|
|
)
|
|
windows = []
|
|
for start in range(0, len(rows) - frames + 1, stride):
|
|
initial = rows[start]["pre_step"]
|
|
c, s = math.cos(initial["heading"]), math.sin(initial["heading"])
|
|
axes = np.array([[c, -s], [s, c]])
|
|
points = []
|
|
for row in rows[start : start + frames]:
|
|
if row["request"] != rows[0]["request"]:
|
|
raise ValueError("Qualification window changed command")
|
|
w, x, y, z = row["quaternion_wxyz"]
|
|
rotation = np.array(
|
|
[
|
|
[1 - 2 * (y * y + z * z), 2 * (x * y - w * z), 2 * (x * z + w * y)],
|
|
[2 * (x * y + w * z), 1 - 2 * (x * x + z * z), 2 * (y * z - w * x)],
|
|
[2 * (x * z - w * y), 2 * (y * z + w * x), 1 - 2 * (x * x + y * y)],
|
|
]
|
|
)
|
|
projected = (vertices @ rotation.T)[:, :2] + (
|
|
np.array(row["position"][:2]) - initial["position"][:2]
|
|
)
|
|
points.extend(projected @ axes)
|
|
points = np.array(points)
|
|
excess = float(np.maximum(lower - points, points - upper).max())
|
|
windows.append(
|
|
dict(
|
|
start_frame=start,
|
|
samples=len(points),
|
|
excess_m=excess,
|
|
passed=math.isfinite(excess) and excess <= CRITERIA["numerical_tolerance_m"],
|
|
)
|
|
)
|
|
return dict(
|
|
phase=rows[0]["phase"],
|
|
request=rows[0]["request"],
|
|
bounds=bounds,
|
|
windows=windows,
|
|
passed=bool(windows) and all(w["passed"] for w in windows),
|
|
)
|