isaac-sim / IsaacLab

Unified framework for robot learning built on NVIDIA Isaac Sim
https://isaac-sim.github.io/IsaacLab
Other
1.96k stars 776 forks source link

[Question] How to get RigidObject from from_files.spawn_from_usd #961

Open ben-kaye opened 2 weeks ago

ben-kaye commented 2 weeks ago

Question

I need to get RigidObject from a scene which is loaded from file and contains many rigid body xforms.

cfg = sim_utils.UsdFileCfg(
        usd_path="/workspace/isaaclab/shared/ramp1/usda/0001.usda")
asm_prim:Usd.Prim = cfg.func("/World/Origin1/Asm0001", cfg)

I have tried to load it using this helper function:

def get_parts(assembly_root_prim: Usd.Prim) -> list[RigidObject]:

    paths = (c.GetPath().pathString for c in assembly_root_prim.GetChildren())
    cfgs = (RigidObjectCfg(prim_path=p) for p in paths)
    return [RigidObject(cfg) for cfg in cfgs]

However, the RigidObjects generated have _initialized: False and all the relevant properties do not exist. I can run the simulation and open the scene in Isaac sim and the file imports correctly and the rigid bodies exist in the tree, but the RigidObject view does not work. Including if I run the sim for a while and then try generating the RigidObject views.

minimal script (edit)

sim = sim_utils.SimulationContext(sim_utils.SimulationCfg(dt=0.01))
cfg = sim_utils.GroundPlaneCfg()
cfg.func("/World/defaultGroundPlane", cfg)
prim_utils.create_prim("/World/Origin1", "Xform", translation=origins[0])
cfg = sim_utils.UsdFileCfg(
        usd_path="/workspace/isaaclab/shared/ramp1/usda/0001.usda"
    )
asm_prim = cfg.func("/World/Origin1/Asm0001", cfg)
sim.reset()
parts = get_parts(asm_prim)

I include an abridged version of my usd. It contains many of these parts 0001.usda

#usda 1.0
(
    defaultPrim = "assembly"
    upAxis = "Z"
)

def Xform "assembly"
{
    float xformOp:rotateX = -90
    double3 xformOp:translate = (0, -0.019999999552965164, 0)
    uniform token[] xformOpOrder = ["xformOp:rotateX", "xformOp:translate"]

    def Xform "part0" (
        prepend references = @../busd/b0.usda@</b0>
    )
    {
        quatf xformOp:orient = (1, 0, 0, 0)
        double3 xformOp:translate = (0, 0, 0)
        uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient"]
    }
... etc

referencing rigid bodies such as:

#usda 1.0
(
    defaultPrim = "b0"
)

def Xform "b0" (
    prepend apiSchemas = ["PhysicsMassAPI", "PhysicsRigidBodyAPI", "PhysxRigidBodyAPI"]
)
{
    float physics:mass = 0.08879914
    bool physics:rigidBodyEnabled = 1

    def Xform "geometry" (
        instanceable = true
        prepend references = @./b0_instance.usda@</b0/geometry>
    )
    {
        double3 xformOp:translate = (0, 0, 0)
        uniform token[] xformOpOrder = ["xformOp:translate"]
    }
}
kellyguo11 commented 21 hours ago

Hello, can you try moving parts = get_parts(asm_prim) to before sim.reset()? The initialization of the views will happen on simulation start, so the RigidObjects should be created before starting simulation.