7f39abb613
Add declarative single-leg import, fixed-anchor benchmark, masked shared-policy PPO prototype, regression tests, and consolidated documentation.
86 lines
3.6 KiB
Python
86 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Convert a PartSpec-derived single-leg bundle and validate its USD mapping."""
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def main():
|
|
if not __debug__:
|
|
raise RuntimeError("Conversion assertions require Python without -O")
|
|
from isaaclab.app import AppLauncher
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--bundle", type=Path, required=True)
|
|
AppLauncher.add_app_launcher_args(parser)
|
|
args = parser.parse_args()
|
|
app = AppLauncher(args).app
|
|
code = 0
|
|
try:
|
|
from SkillFactory.legs.spec import load_bundle
|
|
from SkillFactory.legs.urdf import digest
|
|
|
|
from pxr import PhysxSchema, Usd, UsdPhysics
|
|
|
|
from isaaclab.sim.converters import UrdfConverter, UrdfConverterCfg
|
|
|
|
directory = args.bundle.resolve()
|
|
bundle = load_bundle(directory)
|
|
converter = UrdfConverter(
|
|
UrdfConverterCfg(
|
|
asset_path=str(directory / "leg.urdf"),
|
|
usd_dir=str(directory / "usd"),
|
|
fix_base=True,
|
|
merge_fixed_joints=False,
|
|
force_usd_conversion=True,
|
|
joint_drive=UrdfConverterCfg.JointDriveCfg(target_type="none"),
|
|
run_multi_physics_conversion=False,
|
|
)
|
|
)
|
|
stage = Usd.Stage.Open(converter.usd_path)
|
|
assert stage and stage.GetDefaultPrim()
|
|
root = stage.GetDefaultPrim()
|
|
bodies = {
|
|
prim.GetName(): str(prim.GetPath()) for prim in stage.Traverse() if prim.HasAPI(UsdPhysics.RigidBodyAPI)
|
|
}
|
|
revolute = [prim for prim in stage.Traverse() if prim.IsA(UsdPhysics.RevoluteJoint)]
|
|
assert sorted(prim.GetName() for prim in revolute) == sorted(bundle["joint_order"])
|
|
assert set(bundle["links"]) | {bundle["anchor_body"]} == set(bodies)
|
|
fixed_world = False
|
|
for prim in stage.Traverse():
|
|
if prim.IsA(UsdPhysics.FixedJoint):
|
|
joint = UsdPhysics.Joint(prim)
|
|
targets = joint.GetBody0Rel().GetTargets() + joint.GetBody1Rel().GetTargets()
|
|
fixed_world |= len(targets) < 2 or any(
|
|
not stage.GetPrimAtPath(path).HasAPI(UsdPhysics.RigidBodyAPI) for path in targets
|
|
)
|
|
assert fixed_world, "Missing fixed-to-world support"
|
|
foot = stage.GetPrimAtPath(bodies[bundle["foot"]["body"]])
|
|
assert any(prim.HasAPI(UsdPhysics.CollisionAPI) for prim in Usd.PrimRange(foot, Usd.TraverseInstanceProxies()))
|
|
PhysxSchema.PhysxContactReportAPI.Apply(foot).CreateThresholdAttr(0.0)
|
|
stage.GetRootLayer().Save()
|
|
layers = [Path(layer.realPath).resolve() for layer in stage.GetUsedLayers() if layer.realPath]
|
|
assert layers and all(layer.is_relative_to(directory) and layer.is_file() for layer in layers)
|
|
conversion = {
|
|
"usd_path": str(Path(converter.usd_path).relative_to(directory)),
|
|
"manifest_sha256": digest(directory / "manifest.json"),
|
|
"fixed_to_world": True,
|
|
"body_paths": {name: path.removeprefix(str(root.GetPath())) for name, path in bodies.items()},
|
|
"joint_paths": {prim.GetName(): str(prim.GetPath()).removeprefix(str(root.GetPath())) for prim in revolute},
|
|
"used_layers": sorted(str(layer.relative_to(directory)) for layer in layers),
|
|
}
|
|
(directory / "conversion.json").write_text(json.dumps(conversion, indent=2) + "\n")
|
|
print(json.dumps(conversion, indent=2))
|
|
except BaseException:
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
code = 1
|
|
finally:
|
|
app.close(exit_code=code)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|