Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
"""Evaluate disturbance response from recorded body motion, never command alone."""
|
||||
|
||||
import math
|
||||
|
||||
from qualification_scene import yaw_from_pose
|
||||
|
||||
|
||||
def distance(rows, origin):
|
||||
total, previous = 0.0, origin
|
||||
for row in rows:
|
||||
xy = row["pose"][:2]
|
||||
total += math.dist(previous, xy)
|
||||
previous = xy
|
||||
return total
|
||||
|
||||
|
||||
def barrier_clearance(row, fixture):
|
||||
"""Conservative oriented body-box clearance to the barrier's near plane.
|
||||
|
||||
This is a fixture-specific geometric measurement, not a collision classifier.
|
||||
"""
|
||||
yaw = fixture["yaw"]
|
||||
delta = yaw_from_pose(row["pose"]) - yaw
|
||||
length, width = fixture["rover_size_xy_m"]
|
||||
extent = (length * abs(math.cos(delta)) + width * abs(math.sin(delta))) / 2
|
||||
centre = sum(
|
||||
(a - b) * axis
|
||||
for a, b, axis in zip(
|
||||
fixture["centre"][:2], row["pose"][:2], (math.cos(yaw), math.sin(yaw)), strict=True
|
||||
)
|
||||
)
|
||||
return centre - fixture["size_m"][0] / 2 - extent
|
||||
|
||||
|
||||
def box_separation(row, fixture):
|
||||
"""Signed SAT separation of the measured body and the bounded test box.
|
||||
|
||||
A positive projected gap is a conservative lower bound on planar distance;
|
||||
a nonpositive result means the rectangular projections overlap on all axes.
|
||||
Used only for qualification, never as a planner observation.
|
||||
"""
|
||||
body_yaw, box_yaw = yaw_from_pose(row["pose"]), fixture["yaw"]
|
||||
delta = [a - b for a, b in zip(row["pose"][:2], fixture["centre"][:2], strict=True)]
|
||||
gaps = []
|
||||
for angle in (body_yaw, body_yaw + math.pi / 2, box_yaw, box_yaw + math.pi / 2):
|
||||
extent = sum(
|
||||
(size[0] * abs(math.cos(yaw - angle)) + size[1] * abs(math.sin(yaw - angle))) / 2
|
||||
for yaw, size in ((body_yaw, fixture["rover_size_xy_m"]), (box_yaw, fixture["size_m"]))
|
||||
)
|
||||
gaps.append(abs(delta[0] * math.cos(angle) + delta[1] * math.sin(angle)) - extent)
|
||||
return max(gaps)
|
||||
|
||||
|
||||
def assess_challenge(spec, events, rows):
|
||||
starts = [e for e in events if e["event"] == "activated"]
|
||||
ends = [e for e in events if e["event"] == "restored"]
|
||||
result = {
|
||||
"schema_version": "missioncore.simulation-challenge-result/v1",
|
||||
"scenario_sha256": spec["sha256"],
|
||||
"name": spec["name"],
|
||||
"passed": False,
|
||||
"checks": {},
|
||||
"metrics": {},
|
||||
}
|
||||
checks, metrics = result["checks"], result["metrics"]
|
||||
if spec["name"] in {
|
||||
"route-obstacle",
|
||||
"route-obstacle-clearance",
|
||||
"route-obstacle-after-travel",
|
||||
}:
|
||||
# This fixture stays present through the episode. Route selection and
|
||||
# goal admission are verified separately from the physics separation.
|
||||
checks["persistent_obstacle"] = len(starts) == 1 and not ends
|
||||
if not checks["persistent_obstacle"]:
|
||||
return result
|
||||
fixture = starts[0].get("fixture")
|
||||
active = [r for r in rows if r["monotonic"] >= starts[0]["monotonic"]]
|
||||
clearance = (
|
||||
min((box_separation(r, fixture) for r in active), default=None) if fixture else None
|
||||
)
|
||||
metrics["minimum_box_separation_m"] = clearance
|
||||
checks["body_clearance"] = clearance is not None and clearance >= 0.05
|
||||
checks["range_observed"] = any(
|
||||
e["event"] == "obstacle-observation" and e["hits"] > 0 for e in events
|
||||
)
|
||||
result["passed"] = all(checks.values())
|
||||
return result
|
||||
checks["one_complete_disturbance"] = len(starts) == len(ends) == 1
|
||||
if not checks["one_complete_disturbance"]:
|
||||
return result
|
||||
start, end = starts[0], ends[0]
|
||||
checks["ordered_events"] = end["monotonic"] > start["monotonic"]
|
||||
active = [r for r in rows if start["monotonic"] <= r["monotonic"] < end["monotonic"]]
|
||||
after = [r for r in rows if r["monotonic"] >= end["monotonic"]]
|
||||
limits, trigger = spec["acceptance"], spec["trigger"]
|
||||
checks["triggered_while_moving"] = (
|
||||
math.hypot(*start["velocity"][:2]) >= trigger["minimum_speed_mps"]
|
||||
and start["travel_m"] >= trigger["travel_m"]
|
||||
and start["moving_seconds"] >= trigger["moving_seconds"]
|
||||
)
|
||||
checks["duration_observed"] = (
|
||||
end["monotonic"] - start["monotonic"] >= spec["duration_seconds"]
|
||||
and bool(active)
|
||||
and bool(after)
|
||||
)
|
||||
|
||||
def zero(row):
|
||||
return max(abs(v) for v in row["command"]) <= 1e-8
|
||||
|
||||
def quiet(row):
|
||||
return (
|
||||
zero(row)
|
||||
and math.hypot(*row["velocity"][:2]) <= limits["stop_speed_mps"]
|
||||
and math.sqrt(sum(v * v for v in row["angular_velocity"]))
|
||||
<= limits["stop_angular_speed_rps"]
|
||||
)
|
||||
|
||||
first_quiet = confirmed = command_zero = None
|
||||
quiet_seconds = 0.0
|
||||
for index, row in enumerate(active):
|
||||
if zero(row) and command_zero is None:
|
||||
command_zero = index
|
||||
if quiet(row):
|
||||
if first_quiet is None:
|
||||
first_quiet = index
|
||||
quiet_seconds += row["dt"]
|
||||
if quiet_seconds >= limits["stationary_seconds"]:
|
||||
confirmed = index
|
||||
break
|
||||
else:
|
||||
first_quiet, quiet_seconds = None, 0.0
|
||||
checks["sustained_body_stop"] = confirmed is not None
|
||||
metrics["trigger_speed_mps"] = math.hypot(*start["velocity"][:2])
|
||||
metrics["command_zero_wall_seconds"] = (
|
||||
active[command_zero]["monotonic"] - start["monotonic"] if command_zero is not None else None
|
||||
)
|
||||
if confirmed is not None:
|
||||
stopped = active[first_quiet]
|
||||
metrics.update(
|
||||
body_stop_wall_seconds=stopped["monotonic"] - start["monotonic"],
|
||||
body_stop_simulation_seconds=(
|
||||
stopped["simulation_time_ns"] - start["simulation_time_ns"]
|
||||
)
|
||||
/ 1e9,
|
||||
body_stop_travel_m=distance(active[: first_quiet + 1], start["pose"][:2]),
|
||||
stop_confirmation_wall_seconds=active[confirmed]["monotonic"] - start["monotonic"],
|
||||
)
|
||||
checks["stop_within_time"] = (
|
||||
metrics["body_stop_wall_seconds"] <= limits["stop_wall_seconds"]
|
||||
)
|
||||
checks["stop_within_distance"] = metrics["body_stop_travel_m"] <= limits["stop_travel_m"]
|
||||
checks["held_until_restored"] = all(quiet(row) for row in active[confirmed:])
|
||||
stale = [r for r in active if r["stop_reason"] in {
|
||||
"stale-camera", "stale-command", "stale-range", "stale-pose", "stale-perception"}]
|
||||
checks["stale_commands_zero"] = all(zero(r) for r in stale)
|
||||
metrics["recovery_travel_m"] = distance(after, end["pose"][:2])
|
||||
checks["fresh_motion_recovered"] = metrics["recovery_travel_m"] >= limits[
|
||||
"recovery_travel_m"
|
||||
] and any(
|
||||
r["stop_reason"] == "none"
|
||||
and not zero(r)
|
||||
and math.hypot(*r["velocity"][:2]) >= trigger["minimum_speed_mps"]
|
||||
for r in after
|
||||
)
|
||||
metrics["maximum_body_speed_mps"] = max(
|
||||
(math.hypot(*r["velocity"][:2]) for r in rows), default=0
|
||||
)
|
||||
checks["body_speed_within_015"] = metrics["maximum_body_speed_mps"] <= 0.15
|
||||
if spec["name"] == "obstacle":
|
||||
fixture = start.get("fixture")
|
||||
clearance = (
|
||||
min((barrier_clearance(r, fixture) for r in active), default=None) if fixture else None
|
||||
)
|
||||
metrics["minimum_body_box_clearance_m"] = clearance
|
||||
checks["barrier_clearance"] = (
|
||||
clearance is not None and clearance >= limits["minimum_clearance_m"]
|
||||
)
|
||||
metrics["maximum_range_hits"] = max(
|
||||
(e["hits"] for e in events if e["event"] == "obstacle-observation"), default=0
|
||||
)
|
||||
checks["barrier_observed_by_range"] = metrics["maximum_range_hits"] > 0
|
||||
else:
|
||||
checks["watchdog_exercised"] = bool(stale)
|
||||
checks["observations_dropped"] = any(e["event"] == "dropped" for e in events)
|
||||
if spec["name"] == "observation-delay":
|
||||
delayed = [e for e in events if e["event"] == "delayed-delivery"]
|
||||
delayed_ids = {e["frame_id"] for e in delayed}
|
||||
metrics["delayed_frames"] = len(delayed)
|
||||
checks["expired_sources_delivered"] = bool(delayed) and all(
|
||||
e["monotonic"] - e["captured_at"] >= spec["observation_delay_seconds"]
|
||||
for e in delayed
|
||||
)
|
||||
rejected = [r for r in active if r.get("decision_frame_id") in delayed_ids]
|
||||
checks["expired_decisions_rejected"] = bool(rejected) and all(
|
||||
r["stop_reason"] == "stale-camera" and zero(r) for r in rejected
|
||||
)
|
||||
result["passed"] = all(checks.values())
|
||||
return result
|
||||
Reference in New Issue
Block a user