95 lines
4.1 KiB
Python
95 lines
4.1 KiB
Python
"""Automatic recommendations must remain distinct from confirmed eligibility."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
pytest.importorskip("mujoco")
|
|
|
|
from mjrl.onboarding.inspect import inspect_asset
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
@pytest.mark.parametrize("asset,family,count", [
|
|
("g1_example/g1.xml", "biped", 2),
|
|
("go1_example/go1.xml", "quadruped", 4),
|
|
("wheeled_biped_example/robot.xml", "wheeled_biped", 2),
|
|
("multipod_example/multipod.xml", "multipod", 6),
|
|
])
|
|
def test_automatic_legged_route(asset, family, count):
|
|
report = inspect_asset(ROOT / "assets" / asset)
|
|
candidates = report["morphology_candidates"]
|
|
assert candidates["family"] == family
|
|
assert candidates["support_branch_count"] == count
|
|
assert candidates["base_body"]
|
|
assert candidates["foot_geoms"]
|
|
assert len(candidates["wheel_joints"]) == (2 if family == "wheeled_biped" else 0)
|
|
recommendation = report["recommendation"]
|
|
assert recommendation["tier"] == 3
|
|
assert recommendation["status"] == "needs_profile"
|
|
assert recommendation["next_step"] == "review-profile"
|
|
assert 3 not in recommendation["eligible_tiers"]
|
|
assert "calibrate_stance" in recommendation["prerequisites"]
|
|
assert not next(c["passed"] for c in report["checks"]
|
|
if c["name"] == "explicit_core_legged_profile")
|
|
|
|
|
|
def test_explicit_control_intent_wins():
|
|
report = inspect_asset(ROOT / "assets/go1_example/go1.xml",
|
|
profile={"control_intent": "deterministic"})
|
|
assert report["morphology_candidates"]["family"] == "quadruped"
|
|
assert report["recommendation"]["tier"] == 2
|
|
|
|
|
|
def test_direct_drive_wheels_are_not_legs():
|
|
report = inspect_asset(ROOT / "assets/differential_drive/robot.xml")
|
|
assert report["morphology_candidates"]["family"] is None
|
|
assert report["morphology_candidates"]["wheel_joints"]
|
|
assert report["recommendation"]["tier"] == 2
|
|
|
|
|
|
def test_arm_and_misleading_foot_names(tmp_path):
|
|
path = tmp_path / "arm.xml"
|
|
path.write_text('''<mujoco><worldbody><body name="base">
|
|
<geom size=".1"/><body name="upper"><joint name="shoulder"/>
|
|
<geom size=".1"/><body name="hand"><joint name="elbow"/>
|
|
<geom name="left_foot" size=".1"/><geom name="right_foot" size=".1"/>
|
|
</body></body></body></worldbody></mujoco>''')
|
|
report = inspect_asset(path)
|
|
assert report["morphology_candidates"]["family"] == "arm"
|
|
assert report["morphology_candidates"]["support_branch_count"] == 1
|
|
assert report["recommendation"]["tier"] == 2
|
|
|
|
|
|
def test_urdf_without_effort_has_pending_training_route(tmp_path):
|
|
inertia = '''<inertial><mass value="1"/><inertia ixx=".01" ixy="0"
|
|
ixz="0" iyy=".01" iyz="0" izz=".01"/></inertial>'''
|
|
collision = '<collision><geometry><sphere radius=".05"/></geometry></collision>'
|
|
links = f'<link name="base">{inertia}{collision}</link>'
|
|
joints = ''
|
|
for side in ("left", "right"):
|
|
links += f'<link name="{side}_foot">{inertia}{collision}</link>'
|
|
joints += f'''<joint name="{side}_hip" type="continuous">
|
|
<parent link="base"/><child link="{side}_foot"/>
|
|
<origin xyz="0 {'.1' if side == 'left' else '-.1'} -.2"/>
|
|
<axis xyz="0 1 0"/></joint>'''
|
|
path = tmp_path / "robot.urdf"
|
|
path.write_text(f'<robot name="biped">{links}{joints}</robot>')
|
|
report = inspect_asset(path)
|
|
assert report["morphology_candidates"]["family"] == "biped"
|
|
assert report["morphology_candidates"]["foot_geoms"]
|
|
assert report["recommendation"]["tier"] == 3
|
|
assert report["recommendation"]["status"] == "needs_profile"
|
|
assert "build_floating_base_mjcf" in report["recommendation"]["prerequisites"]
|
|
assert "supply_actuation_and_effort_limits" in report["recommendation"]["prerequisites"]
|
|
assert 3 not in report["recommendation"]["eligible_tiers"]
|
|
|
|
|
|
def test_ambiguous_models_do_not_infer(tmp_path):
|
|
for name in ("a", "b"):
|
|
(tmp_path / f"{name}.xml").write_text('<mujoco/>')
|
|
report = inspect_asset(tmp_path)
|
|
assert report["morphology_candidates"] is None
|
|
assert report["recommendation"]["tier"] == 0
|