isaac-sim / IsaacLab

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

[Bug Report] Center of Mass cannot be set with GPU pipeline #641

Closed AlanSunHR closed 4 months ago

AlanSunHR commented 4 months ago

Describe the bug

Cannot randomize the center of masses of bodies in an Articulation, with error "2024-07-04 09:45:53 [14,435ms] [Error] [omni.physx.tensors.plugin] Center of Mass cannot be set with GPU pipeline."

Steps to reproduce

I wrote some codes to randomize the center of mass:

def randomize_body_coms(
    env: ManagerBasedEnv, env_ids: torch.Tensor | None, max_displacement: float, asset_cfg: SceneEntityCfg
):
    """Randomize the CoM of the bodies by adding a random value sampled from the given range.

    .. tip::
        This function uses CPU tensors to assign the CoM. It is recommended to use this function
        only during the initialization of the environment.
    """
    # extract the used quantities (to enable type-hinting)
    asset: Articulation = env.scene[asset_cfg.name]

    # resolve environment ids
    if env_ids is None:
        env_ids = torch.arange(env.scene.num_envs, device="cpu")
    else:
        env_ids = env_ids.cpu()

    # resolve body indices
    if asset_cfg.body_ids == slice(None):
        body_ids = torch.arange(asset.num_bodies, dtype=torch.int, device="cpu")
    else:
        body_ids = torch.tensor(asset_cfg.body_ids, dtype=torch.int, device="cpu")

    # get the current com of the bodies (num_assets, num_bodies)
    coms = asset.root_physx_view.get_coms().clone()[:, body_ids, :3]

    # Randomize the com in range -max displacement to max displacement
    coms += torch.rand_like(coms) * 2 * max_displacement - max_displacement

    # Set the new coms
    new_coms = asset.root_physx_view.get_coms().clone()
    new_coms[:, asset_cfg.body_ids, 0:3] = coms
    asset.root_physx_view.set_coms(new_coms, env_ids)

when the above function executes, it failed with error:

2024-07-04 09:45:53 [14,435ms] [Error] [omni.physx.tensors.plugin] Center of Mass cannot be set with GPU pipeline.

System Info

Describe the characteristic of your environment:

Additional context

The randomization of center of mass at start up worked well in Orbit, but not in IsaacLab. Randomization of body masses at start up works in IsaacLab. I tried to write the randomization of CoM as similiar as possible to the mass, but it seems like a problem at the backend.

Checklist

Milad-Rakhsha-NV commented 4 months ago

I recently fixed this for ISIM-1183