Files
NODEDC_MISSION_CORE/simulation/ai-polygon/control_qualification.py
T
DCCONSTRUCTIONS d0e5f90952 Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
2026-10-08 09:59:51 +03:00

158 lines
5.9 KiB
Python

"""Frozen synthetic control matrix and independent measurements (no Isaac imports)."""
import math
SCHEMA = "missioncore.control-matrix/v1"
DT = 1 / 60
PHASES = (
("hold", 2, 0, 0),
("straight", 4, 1, 0),
("left-arc", 4, 1, 0.2),
("release-left", 2, 1, 0),
("right-arc", 4, 1, -0.2),
("release-right", 2, 1, 0),
("stop", 3, 0, 0),
("pivot-left", 12, 0, 0.35),
("hold-left", 3, 0, 0),
("pivot-right", 12, 0, -0.35),
("hold-right", 3, 0, 0),
("reverse", 3, -1, 0),
("hold-reverse", 3, 0, 0),
("resume", 3, 1, 0),
("final-hold", 3, 0, 0),
)
CRITERIA = {
"translation_fraction_min": 0.5,
"turn_fraction_min": 0.45,
"straight_heading_max_rad": 0.2,
"pivot_displacement_max_m": 0.3,
"settled_hold_speed_max_mps": 0.01,
"settled_hold_drift_max_m": 0.01,
"settled_after_s": 1.0,
"stop_deadline_s": 1.0,
"stop_speed_mps": 0.01,
"stop_stable_seconds": 0.25,
"arrival_radius_m": 0.4,
}
def specifications():
return [
dict(
id=f"v{speed:.2f}-m{100 + payload}-mu{friction:.2f}",
speed_mps=speed,
payload_kg=payload,
dynamic_friction=friction,
static_friction=friction + 0.1,
)
for speed in (0.1, 0.2, 0.3)
for payload in (0, 30)
for friction in (0.8, 0.35)
]
def angle_delta(a, b):
return math.atan2(math.sin(a - b), math.cos(a - b))
def phase_metrics(rows, criterion=CRITERIA):
first, last = rows[0], rows[-1]
requested_v, requested_w = first["request"]
distance = sum(r["distance_step_m"] for r in rows)
origin = first.get("phase_origin", first["position"])
displacement = max(math.dist(r["position"][:2], origin[:2]) for r in rows)
turn = sum(r["turn_step_rad"] for r in rows)
nominal_distance = sum(abs(r["nominal"][0]) * r["dt"] for r in rows)
nominal_turn = sum(r["nominal"][1] * r["dt"] for r in rows)
speeds = [math.hypot(*r["velocity"][:2]) for r in rows]
tail = [r for r in rows if r["phase_seconds"] >= criterion["settled_after_s"]]
drift = max(math.dist(r["position"][:2], tail[0]["position"][:2]) for r in tail)
speed = max(math.hypot(*r["velocity"][:2]) for r in tail)
checks = {}
if requested_v:
signed = sum(r["forward_mps"] * r["dt"] for r in rows)
checks["translation"] = signed * math.copysign(1, requested_v) > (
nominal_distance * criterion["translation_fraction_min"]
)
if requested_w:
checks["turn"] = turn * math.copysign(1, requested_w) > (
abs(nominal_turn) * criterion["turn_fraction_min"]
)
checks["continuous_arc"] = (
min(r["forward_mps"] for r in rows if r["phase_seconds"] >= 1) > 0.01
)
else:
checks["heading"] = abs(turn) < criterion["straight_heading_max_rad"]
elif requested_w:
checks["turn"] = turn * math.copysign(1, requested_w) > (
abs(nominal_turn) * criterion["turn_fraction_min"]
)
checks["pivot_position"] = displacement < criterion["pivot_displacement_max_m"]
else:
checks["hold_speed"] = speed < criterion["settled_hold_speed_max_mps"]
checks["hold_drift"] = drift < criterion["settled_hold_drift_max_m"]
checks["held_belts"] = all(all(r["held_sides"]) for r in tail)
stable_frames = round(criterion["stop_stable_seconds"] / first["dt"])
stopped_at = next(
(
i
for i in range(len(rows) - stable_frames + 1)
if max(speeds[i : i + stable_frames]) < criterion["stop_speed_mps"]
),
None,
)
stopping_time = None if stopped_at is None else rows[stopped_at]["phase_seconds"]
stopping_distance = (
None if stopped_at is None else sum(r["distance_step_m"] for r in rows[: stopped_at + 1])
)
if not requested_v and not requested_w:
checks["stop_deadline"] = (
stopping_time is not None and stopping_time <= criterion["stop_deadline_s"]
)
cumulative = 0.0
turning_times = {"90": None, "180": None}
for r in rows:
cumulative += r["turn_step_rad"]
for degrees in turning_times:
if turning_times[degrees] is None and abs(cumulative) >= math.radians(int(degrees)):
turning_times[degrees] = r["phase_seconds"]
return dict(
phase=first["phase"],
duration_s=last["phase_seconds"],
request=first["request"],
distance_m=distance,
maximum_displacement_m=displacement,
heading_change_rad=turn,
nominal_distance_m=nominal_distance,
nominal_turn_rad=nominal_turn,
peak_speed_mps=max(speeds),
mean_forward_mps=sum(r["forward_mps"] for r in rows) / len(rows),
mean_yaw_rps=sum(r["yaw_rps"] for r in rows) / len(rows),
peak_acceleration_mps2=max(abs(r["acceleration_mps2"]) for r in rows),
settled_hold_drift_m=drift,
settled_speed_mps=speed,
stopping_time_s=stopping_time,
stopping_distance_m=stopping_distance,
turning_times_s=turning_times,
checks=checks,
passed=all(checks.values()),
)
def goal_body_supported(position, heading, target, geometry, support_xyxy):
"""Independent rectangle fixture: arrival point AND whole body support.
Arrival radius bounds the reference point, not the entire 1.163 m body.
Does not authorize planner motion or infer unobserved terrain.
"""
if math.dist(position[:2], target[:2]) > CRITERIA["arrival_radius_m"]:
return False
xmin, ymin, xmax, ymax = support_xyxy
c, s = math.cos(heading), math.sin(heading)
for x in (-geometry["length_m"] / 2, geometry["length_m"] / 2):
for y in (-geometry["width_m"] / 2, geometry["width_m"] / 2):
px, py = position[0] + c * x - s * y, position[1] + s * x + c * y
if not (xmin <= px <= xmax and ymin <= py <= ymax):
return False
return True