Skip to content

Official Codebase of 3DCodeVerse

Python

motion gate: a motion that leans along the planned direction (0.2 < cos <= 0.5) is a WARN with a pivot hint, not WRONG

ziyao63d1b48074a0
diff --git a/harness/codeverse/spatial/joints_sweep.py b/harness/codeverse/spatial/joints_sweep.py
index 70d3d321..f729908f 100644
--- a/harness/codeverse/spatial/joints_sweep.py
+++ b/harness/codeverse/spatial/joints_sweep.py
@@ -71,12 +71,21 @@ class SweepReport(BaseModel):
summary: SweepSummary
+#: cos(observed, expected) above this is the planned direction; between PARTIAL_COS and
+#: this the motion leans along it (WARN, not WRONG); below PARTIAL_COS it is wrong
+OK_COS = 0.5
+PARTIAL_COS = 0.2
+
+
class MotionCheck(BaseModel):
joint: str
expected: str
observed_dir: tuple[float, float, float]
ok: bool
message: str
+ cos: float = 0.0
+ partial: bool = Field(default=False, description="not ok, but the motion leans along the planned direction "
+ "(PARTIAL_COS < cos <= OK_COS): a pivot / axis-line refinement, not a reversal")
# ------------------------------------------------------------------ sweep
@@ -323,10 +332,18 @@ def motion_direction_check(robot: Robot, joint: str, expected: str, *, probe: fl
d = delta / n if n > 1e-9 else delta
want = np.asarray(_DIRS[key], dtype=float)
cos = float(d @ want)
- ok = cos > 0.5
+ ok = cos > OK_COS
+ partial = (not ok) and cos > PARTIAL_COS
+ # compare_art_v4 (2026-08-29): 6 of 23 round-0 "WRONG" findings sat at cos 0.17-0.41 — an
+ # arm pitching up-and-forward for "up" — and the judge repeated each as a critical
+ # defect. That band is a pivot / axis-line refinement, reported as such.
+ verdict = ("ok" if ok else
+ f"MOSTLY along {expected} (cos {cos:.2f}) — move the pivot / axis line so the part moves squarely along it"
+ if partial else "WRONG — flip the axis sign or swap limits")
return MotionCheck(joint=joint, expected=expected, observed_dir=tuple(round(float(v), 4) for v in d), ok=ok,
+ cos=round(cos, 4), partial=partial,
message=(f"{joint}: child '{j.child}' moves {tuple(round(float(v),3) for v in d)} for q={probe:+.3g}; "
- f"expected {expected} ({'ok' if ok else 'WRONG — flip the axis sign or swap limits'})"))
+ f"expected {expected} ({verdict})"))
def summary_text(report: SweepReport) -> str:
diff --git a/harness/codeverse/tracks/articulated_object.py b/harness/codeverse/tracks/articulated_object.py
index 412cb971..e0902922 100644
--- a/harness/codeverse/tracks/articulated_object.py
+++ b/harness/codeverse/tracks/articulated_object.py
@@ -278,9 +278,16 @@ def default_motion_checks(ws: Workspace, plan: Plan | None) -> GateReport | None
findings.append(GateFinding(gate=MOTION_GATE, severity=Severity.WARN, target=j.name,
message=f"motion check skipped: {e}", data={"expected": expected}))
continue
- data = {"expected": expected, "observed_dir": list(chk.observed_dir), "motion": j.motion}
+ data = {"expected": expected, "observed_dir": list(chk.observed_dir), "motion": j.motion,
+ "cos": getattr(chk, "cos", None)}
if chk.ok:
findings.append(GateFinding(gate=MOTION_GATE, severity=Severity.INFO, target=j.name, message=chk.message, data=data))
+ elif getattr(chk, "partial", False):
+ findings.append(GateFinding(
+ gate=MOTION_GATE, severity=Severity.WARN, target=j.name,
+ message=f"{chk.message}. Plan says: \"{j.motion}\"",
+ fix_hint=f"refine joint {j.name}: keep the axis sign; move the pivot / axis line so '{j.child}' moves "
+ f"squarely along {expected}", data=data))
else:
findings.append(GateFinding(
gate=MOTION_GATE, severity=Severity.ERROR, target=j.name,
diff --git a/harness/tests/urdf_joints/test_motion_band.py b/harness/tests/urdf_joints/test_motion_band.py
new file mode 100644
index 00000000..a4828487
--- /dev/null
+++ b/harness/tests/urdf_joints/test_motion_band.py
@@ -0,0 +1,44 @@
+"""The motion gate's middle band: leaning along the planned direction is a WARN, not WRONG."""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+from codeverse.contracts.artifacts import Severity
+from codeverse.spatial.joints import load_urdf, motion_direction_check
+from codeverse.spatial.joints_sweep import OK_COS, PARTIAL_COS
+from tests.urdf_joints.conftest import write_mesh_robot
+
+
+def test_flags_follow_the_cosine_bands(tmp_path):
+ urdf, meshes = write_mesh_robot(tmp_path)
+ r = load_urdf(urdf, meshes)
+ seen = set()
+ for expected in ("front", "back", "left", "right", "up", "down"):
+ chk = motion_direction_check(r, "hinge", expected)
+ assert chk.ok == (chk.cos > OK_COS)
+ assert chk.partial == ((not chk.ok) and chk.cos > PARTIAL_COS)
+ seen.add("ok" if chk.ok else "partial" if chk.partial else "wrong")
+ if chk.partial:
+ assert "MOSTLY" in chk.message and "WRONG" not in chk.message
+ elif not chk.ok:
+ assert "WRONG" in chk.message
+ assert "ok" in seen and "wrong" in seen # the door swings to the front-left: both extremes are exercised
+
+
+def test_partial_is_a_warn_in_the_gate(tmp_path, cabinet_plan, monkeypatch):
+ from codeverse.spatial import joints as sj
+ from codeverse.tracks import articulated_object as ao
+
+ urdf, meshes = write_mesh_robot(tmp_path / "artifacts")
+ ws = SimpleNamespace(artifacts=tmp_path / "artifacts", src=tmp_path / "src")
+
+ def leaning(robot, joint, expected, *, probe=None):
+ return sj.MotionCheck(joint=joint, expected=expected, observed_dir=(0.0, -0.4, 0.9), ok=False, partial=True,
+ cos=0.4, message=f"{joint}: MOSTLY along {expected} (cos 0.40)")
+
+ monkeypatch.setattr(sj, "motion_direction_check", leaning)
+ rep = ao.default_motion_checks(ws, cabinet_plan)
+ assert rep is not None and rep.passed # a WARN never fails the gate
+ f = [x for x in rep.findings if x.target == "hinge"][0]
+ assert f.severity == Severity.WARN and f.data["cos"] == 0.4 and "keep the axis sign" in f.fix_hint