"""MODEL-LOAD (USD): load robot/robot.usd as an Isaac Lab Articulation on the PhysX backend, step it, report. Research and simulation project only. Do not install this device in a real vehicle or attempt to drive a vehicle with it. It has not been built or tested on any vehicle. Simulation-tested ยท Not built. Runs inside Isaac Lab's Python (queue: gpu), called by `uv run tasks.py usd`: isaaclab.bat -p usd_load_check.py [--seconds 2.0] [--dt 0.002] [--no_self_collisions] [--fix_root_link] What it does (one environment, headless): 1. spawns the USD at /World/Robot with one implicit actuator group over every joint (stiffness 0, damping 0, so the USD's own effort limits stay in force). By default the file is spawned as converted (no articulation_props). The importer (fix_base) puts ArticulationRootAPI on the seat_frame rigid body plus a separate world FixedJoint (root_joint), which PhysX parses as a floating-base articulation held by that external joint, and it disables self-collisions only through newton:selfCollisionEnabled, which PhysX does not read. --no_self_collisions adds PhysxArticulationRootPropertiesCfg(enabled_self_collisions=False); --fix_root_link adds ArticulationRootPropertiesCfg(fix_root_link=True) (Isaac Lab then relocates the root); 2. steps `seconds` with zero effort (passive), then `seconds` with each leader joint (every joint that is not a URDF follower) commanded at +50 % of its USD effort limit (driven); 3. records joint / body names, fixed-base flag, base-link drift, the runtime (PhysX-parsed) masses, inertias, COMs, joint limits, effort / velocity limits and joint friction, every joint position at the end of each phase, and whether all states stay finite; 4. mimic probe: the importer writes the URDF couplings (read from robot.urdf next to the USD) as NewtonMimicAPI (no PhysxMimicJointAPI); Kit's PhysX path enforces them. From rest, every leader is driven for 0.2 s and the follower-vs-leader slope (SI) is fitted: effective_multiplier vs the URDF multiplier. --mimic_si_to_physx first overrides coef1 of angular-leader / linear-follower pairs to multiplier*pi/180. Status PASS when the stage loads, every state stays finite and the base link drifts < 1 mm. Physical behaviour (springs, cords, contacts) is MuJoCo's job (Phase 4), not this check's. """ import argparse import json import sys sys.dont_write_bytecode = True from isaaclab.app import AppLauncher # noqa: E402 parser = argparse.ArgumentParser() parser.add_argument("usd") parser.add_argument("out") parser.add_argument("--seconds", type=float, default=2.0) parser.add_argument("--dt", type=float, default=0.002) parser.add_argument("--no_self_collisions", action="store_true", help="PhysX articulation self-collisions off") parser.add_argument("--fix_root_link", action="store_true", help="Isaac Lab fix_root_link=True at spawn") parser.add_argument("--mimic_si_to_physx", action="store_true", help="override newton:mimicCoef1 of angular-leader / linear-follower pairs to multiplier*pi/180 at spawn") AppLauncher.add_app_launcher_args(parser) args = parser.parse_args() app = AppLauncher(args).app import math # noqa: E402 import os # noqa: E402 import xml.etree.ElementTree as ET # noqa: E402 import torch # noqa: E402 import isaaclab.sim as sim_utils # noqa: E402 from isaaclab.actuators import ImplicitActuatorCfg # noqa: E402 from isaaclab.assets import Articulation, ArticulationCfg # noqa: E402 from isaaclab.sim import SimulationContext # noqa: E402 from isaaclab_physx.physics import PhysxCfg # noqa: E402 from isaaclab_physx.sim.schemas import PhysxArticulationRootPropertiesCfg # noqa: E402 def tolist(t): return [float(x) for x in t.reshape(-1).tolist()] def mimic_pairs() -> dict: """URDF couplings {follower: (leader, multiplier, offset)} from robot.urdf next to the USD.""" urdf = os.path.join(os.path.dirname(os.path.abspath(args.usd)), "robot.urdf") pairs = {} for j in ET.parse(urdf).getroot().findall("joint"): m = j.find("mimic") if m is not None: pairs[j.get("name")] = (m.get("joint"), float(m.get("multiplier", 1.0)), float(m.get("offset", 0.0))) return pairs def override_mimic_units() -> dict: """Author newton:mimicCoef1 = multiplier * pi / 180 on linear followers of angular leaders (stage opinion over the referenced file). Kit 110.3's PhysX path applies coef1 in USD position units (m per degree for this pair), while the Newton schema and the URDF use SI (m per rad).""" from pxr import UsdPhysics # noqa: PLC0415 stage = sim_utils.get_current_stage() done = {} for prim in stage.Traverse(): if not prim.HasAPI("NewtonMimicAPI") or not prim.IsA(UsdPhysics.PrismaticJoint): continue tg = prim.GetRelationship("newton:mimicJoint").GetTargets() leader = stage.GetPrimAtPath(tg[0]) if tg else None if leader is not None and leader.IsA(UsdPhysics.RevoluteJoint): a = prim.GetAttribute("newton:mimicCoef1") k = float(a.Get()) a.Set(k * math.pi / 180.0) done[prim.GetName()] = {"coef1_file": k, "coef1_set": k * math.pi / 180.0} return done def finite(r) -> bool: return bool(torch.isfinite(r.data.joint_pos.torch).all() and torch.isfinite(r.data.joint_vel.torch).all() and torch.isfinite(r.data.body_link_pose_w.torch).all()) def main() -> int: out = {"generated_by": "simulation/isaac/tools/usd_load_check.py (uv run tasks.py usd)", "usd": "robot/robot.usd", "backend": "PhysX (isaaclab_physx.physics.PhysxCfg)", "dt": args.dt, "seconds_per_phase": args.seconds, "spawn": {"no_self_collisions": args.no_self_collisions, "fix_root_link": args.fix_root_link, "mimic_si_to_physx": args.mimic_si_to_physx}} diag = args.no_self_collisions or args.fix_root_link or args.mimic_si_to_physx out["role"] = ("diagnostic for the Isaac Lab RL step (spawn options changed), not a criterion result" if diag else "MODEL-LOAD, USD part (file spawned as converted)") try: sim = SimulationContext(sim_utils.SimulationCfg(dt=args.dt, device=args.device, physics=PhysxCfg())) props = None if args.no_self_collisions or args.fix_root_link: props = PhysxArticulationRootPropertiesCfg(enabled_self_collisions=False if args.no_self_collisions else None, fix_root_link=True if args.fix_root_link else None) spawn = sim_utils.UsdFileCfg(usd_path=args.usd, articulation_props=props) cfg = ArticulationCfg(prim_path="/World/Robot", spawn=spawn, init_state=ArticulationCfg.InitialStateCfg(pos=(0.0, 0.0, 0.0), rot=(0.0, 0.0, 0.0, 1.0)), actuators={"all": ImplicitActuatorCfg(joint_names_expr=[".*"], stiffness=0.0, damping=0.0)}) robot = Articulation(cfg) if args.mimic_si_to_physx: out["mimic_overrides"] = override_mimic_units() sim.reset() r = robot r.update(args.dt) names = list(r.joint_names) out.update(joint_names=names, body_names=list(r.body_names), num_joints=r.num_joints, num_bodies=r.num_bodies, is_fixed_base=bool(r.is_fixed_base)) lim = r.data.joint_pos_limits.torch[0] out["runtime"] = { "body_mass": dict(zip(r.body_names, tolist(r.data.body_mass.torch[0]))), "body_inertia_9": {b: tolist(r.data.body_inertia.torch[0, i]) for i, b in enumerate(r.body_names)}, "body_com_pos_b": {b: tolist(r.data.body_com_pose_b.torch[0, i, :3]) for i, b in enumerate(r.body_names)}, "joint_pos_limits": {n: tolist(lim[i]) for i, n in enumerate(names)}, "joint_effort_limits": dict(zip(names, tolist(r.data.joint_effort_limits.torch[0]))), "joint_vel_limits": dict(zip(names, tolist(r.data.joint_vel_limits.torch[0]))), "joint_friction_coeff": dict(zip(names, tolist(r.data.joint_friction_coeff.torch[0]))), "units": "SI: rad or m, N*m or N, rad/s or m/s; inertia about the COM", } n = int(round(args.seconds / args.dt)) followers = mimic_pairs() # {follower: (leader, multiplier, offset)} from robot.urdf out["urdf_mimic"] = {f: {"leader": v[0], "multiplier": v[1], "offset": v[2]} for f, v in followers.items()} base0 = tolist(r.data.body_link_pos_w.torch[0, 0]) phases = {} for phase in ("passive", "driven"): eff = torch.zeros_like(r.data.joint_pos.torch) if phase == "driven": for i, nm in enumerate(names): if nm not in followers: eff[0, i] = 0.5 * out["runtime"]["joint_effort_limits"][nm] ok = True for _ in range(n): r.actuators.target_command.set_effort_index(value=eff) r.write_data_to_sim() sim.step() r.update(args.dt) ok = ok and finite(r) q = dict(zip(names, tolist(r.data.joint_pos.torch[0]))) phases[phase] = {"steps": n, "finite": ok and finite(r), "joint_pos_end": q, "effort_cmd": dict(zip(names, tolist(eff[0])))} out["phases"] = phases base1 = tolist(r.data.body_link_pos_w.torch[0, 0]) out["base_link"] = r.body_names[0] out["base_drift_m"] = math.dist(base0, base1) # Mimic probe: from rest (all joints 0), drive every leader at +50 % of its effort limit for 0.2 s and fit the # follower's displacement against the leader's (SI units, samples before either joint reaches a limit). The # slope is the coupling PhysX actually enforces; the URDF says follower = multiplier * leader. q0 = torch.zeros_like(r.data.joint_pos.torch) r.write_joint_position_to_sim_index(position=q0) r.write_joint_velocity_to_sim_index(velocity=torch.zeros_like(q0)) eff = torch.zeros_like(q0) for i, nm in enumerate(names): if nm not in followers: eff[0, i] = 0.5 * out["runtime"]["joint_effort_limits"][nm] samples = [] for _ in range(100): r.actuators.target_command.set_effort_index(value=eff) r.write_data_to_sim() sim.step() r.update(args.dt) samples.append(tolist(r.data.joint_pos.torch[0])) out["mimic_under_physx"] = {} for f, (ld, k, off) in followers.items(): if f not in names or ld not in names: continue fi, li = names.index(f), names.index(ld) fhi, lhi = out["runtime"]["joint_pos_limits"][f][1], out["runtime"]["joint_pos_limits"][ld][1] pts = [(s_[li], s_[fi]) for s_ in samples if 1e-4 < s_[li] < 0.98 * lhi and s_[fi] < 0.98 * fhi] sxx = sum(x * x for x, _ in pts) slope = sum(x * y for x, y in pts) / sxx if pts and sxx > 0 else None out["mimic_under_physx"][f] = { "leader": ld, "urdf_multiplier": k, "urdf_offset": off, "samples": len(pts), "leader_end": samples[-1][li], "follower_end": samples[-1][fi], "effective_multiplier": slope, "ratio_to_urdf": slope / k if slope is not None and k else None, "coupling_enforced": slope is not None and abs(slope) > 0.5 * abs(k)} out["all_finite"] = all(p["finite"] for p in phases.values()) and all( math.isfinite(v) for v in out["runtime"]["body_mass"].values()) out["status"] = "PASS" if out["all_finite"] and r.num_joints > 0 and out["base_drift_m"] < 1e-3 else "FAIL" except BaseException as e: # record the failure for the report, then re-raise import traceback out["status"] = "FAIL" # exception text plus the frames as module:function (no machine-specific paths in package files) frames = traceback.extract_tb(e.__traceback__) out["error"] = "".join(traceback.format_exception_only(type(e), e)).strip() out["error_frames"] = [f"{f.filename.replace(chr(92), '/').rsplit('/', 1)[-1]}:{f.name}" for f in frames[-4:]] with open(args.out, "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1) fh.write("\n") raise e with open(args.out, "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1) fh.write("\n") print(f"usd load check: {out['status']} ({out['num_joints']} joints, {out['num_bodies']} bodies)", flush=True) return 0 if __name__ == "__main__": rc = main() app.close() raise SystemExit(rc)