#!/usr/bin/env python3 """Convert the extracted Go2 leg with Kit and verify independent physics bodies.""" import argparse import json from pathlib import Path ROOT = Path(__file__).resolve().parents[2] def main(): if not __debug__: raise RuntimeError("Asset checks require Python without -O/PYTHONOPTIMIZE") from isaaclab.app import AppLauncher parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--asset_dir", type=Path, default=ROOT / "assets/generated/go2_fl") AppLauncher.add_app_launcher_args(parser) args = parser.parse_args() app = AppLauncher(args).app exit_code = 0 try: from pxr import PhysxSchema, Usd, UsdPhysics from isaaclab.sim.converters import UrdfConverter, UrdfConverterCfg directory = args.asset_dir.resolve() cfg = UrdfConverterCfg( asset_path=str(directory / "go2_fl.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, ) converter = UrdfConverter(cfg) stage = Usd.Stage.Open(converter.usd_path) if stage is None: raise RuntimeError("Converter produced no readable stage") root = stage.GetDefaultPrim() assert root, "No default prim" bodies = {p.GetName(): str(p.GetPath()) for p in stage.Traverse() if p.HasAPI(UsdPhysics.RigidBodyAPI)} revolute = [p for p in stage.Traverse() if p.IsA(UsdPhysics.RevoluteJoint)] fixed = [p for p in stage.Traverse() if p.IsA(UsdPhysics.FixedJoint)] expected = ["FL_hip_joint", "FL_thigh_joint", "FL_calf_joint"] assert sorted(p.GetName() for p in revolute) == sorted(expected) assert "FL_foot" in bodies and "anchor_base" in bodies def is_world_fixed(p): targets = UsdPhysics.Joint(p).GetBody0Rel().GetTargets() + UsdPhysics.Joint(p).GetBody1Rel().GetTargets() return len(targets) < 2 or any(not stage.GetPrimAtPath(t).HasAPI(UsdPhysics.RigidBodyAPI) for t in targets) assert any(is_world_fixed(p) for p in fixed), "No fixed-to-world joint" foot = stage.GetPrimAtPath(bodies["FL_foot"]) assert any(p.HasAPI(UsdPhysics.CollisionAPI) for p in Usd.PrimRange(foot, Usd.TraverseInstanceProxies())), ( "No foot collision" ) # Importer 3.0 produces nested rigid bodies. The generic spawner stops # at the first rigid body (anchor), so explicitly enable the foot here. PhysxSchema.PhysxContactReportAPI.Apply(foot).CreateThresholdAttr(0.0) stage.GetRootLayer().Save() assert foot.HasAPI(PhysxSchema.PhysxContactReportAPI) used_layers = stage.GetUsedLayers() missing = [ layer.identifier for layer in used_layers if not layer.anonymous and not Path(layer.realPath).is_file() ] assert not missing, missing mapping = { "usd_path": str(Path(converter.usd_path).relative_to(directory)), "default_prim": str(root.GetPath()), "body_paths": {k: v.removeprefix(str(root.GetPath())) for k, v in bodies.items()}, "joint_paths": {p.GetName(): str(p.GetPath()).removeprefix(str(root.GetPath())) for p in revolute}, "used_layers": [ str(Path(layer.realPath).relative_to(directory)) for layer in used_layers if layer.realPath ], "fixed_to_world": True, "merge_fixed_joints": False, } (directory / "conversion.json").write_text(json.dumps(mapping, indent=2) + "\n") print(json.dumps(mapping, indent=2)) except BaseException: import traceback traceback.print_exc() exit_code = 1 finally: app.close(exit_code=exit_code) if __name__ == "__main__": main()