"""SO-101 USD from newton-assets' robotstudio_so101, with the links of so101_new_calib_web.urdf.""" import json import sys import numpy as np from pxr import Gf, Usd, UsdGeom, UsdPhysics, UsdShade import robotusd as ru SOURCE, URDF, OUT = sys.argv[1:4] # Newton body -> URDF link. Joint names already match. LINKS = { "base": "base_link", "shoulder": "shoulder_link", "upper_arm": "upper_arm_link", "lower_arm": "lower_arm_link", "wrist": "wrist_link", "gripper": "gripper_link", "moving_jaw_so101_v1": "moving_jaw_so101_v1_link", } layer = ru.flatten(SOURCE) stage = Usd.Stage.Open(layer) def body(name): return next(str(p.GetPath()) for p in stage.Traverse() if p.HasAPI(UsdPhysics.RigidBodyAPI) and p.GetName() == name) # The URDF has no wrist camera mount: drop the body and the joint holding it. mount = body("camera_mount") for p in list(stage.Traverse()): if p.IsA(UsdPhysics.Joint) and mount in [str(t) for t in UsdPhysics.Joint(p).GetBody1Rel().GetTargets()]: ru.remove(layer, p.GetPath()) ru.remove(layer, mount) # Deepest first, so the parents' paths still hold. for old in sorted(LINKS, key=lambda n: -body(n).count("/")): ru.rename(layer, body(old), LINKS[old]) # The LeRobot visualizer's colors rather than Menagerie's yellow: printed parts light grey and the # STS3215 servos carbon black (sRGB #9ba1ab and #171a20). USD colors are linear. def linear(hex_color): srgb = [int(hex_color[i : i + 2], 16) / 255 for i in (1, 3, 5)] return Gf.Vec3f(*[c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4 for c in srgb]) for material in stage.GetPrimAtPath("/so101/Materials").GetChildren(): servo = material.GetName().startswith("sts3215") inputs = UsdShade.Material(material) inputs.GetInput("diffuseColor").Set(linear("#171a20" if servo else "#9ba1ab")) inputs.GetInput("metallic").Set(0.15 if servo else 0.1) inputs.GetInput("roughness").Set(0.75 if servo else 0.5) # The trail tip, where the URDF puts it. rest = ru.urdf_fk(URDF, {}) base = UsdGeom.XformCache().GetLocalToWorldTransform(stage.GetPrimAtPath(body("base_link"))) align = ru.np_matrix(base) @ np.linalg.inv(rest["base_link"]) ru.add_frame(stage, body("gripper_link"), "gripper_frame_link", align @ rest["gripper_frame_link"]) layer.documentation = ( "SO-101 (so101_new_calib) for LeRobot. Modified by LeRobot from newton-physics/newton-assets " "robotstudio_so101 (Apache-2.0, converted from MuJoCo Menagerie): flattened into one layer, wrist camera " "mount removed, links renamed to the so101_new_calib URDF's, gripper_frame_link added at the URDF's tip, " "parts recolored light grey with black servos." ) layer.customLayerData = { "lerobot:source": "https://github.com/newton-physics/newton-assets/tree/a96f0973b6ae69c90609f9fafef9d2c1db2d6431/robotstudio_so101", "lerobot:urdf": "https://huggingface.co/buckets/lerobot/robot-urdfs/resolve/so101/so101_new_calib_web.urdf", } layer.Export(OUT) out = Usd.Stage.Open(OUT) report = ru.check_against_urdf(out, URDF) report["visual_bounds_vs_source_mm"] = ru.compare_visual_bounds(Usd.Stage.Open(SOURCE), out, LINKS) report["meshes"] = sum(1 for p in out.Traverse() if p.IsA(UsdGeom.Mesh) and UsdGeom.Imageable(p).ComputePurpose() == "default") report["triangles"] = int( sum( np.maximum(np.array(UsdGeom.Mesh(p).GetFaceVertexCountsAttr().Get()) - 2, 0).sum() for p in out.Traverse() if p.IsA(UsdGeom.Mesh) and UsdGeom.Imageable(p).ComputePurpose() == "default" ) ) report["materials"] = { p.GetName(): {i.GetBaseName(): str(i.Get()) for i in UsdShade.Shader(p).GetInputs() if i.Get() is not None} for p in out.Traverse() if p.IsA(UsdShade.Shader) } print(json.dumps(report, indent=1, default=str))