Skip to content

[Question] IMU Sensor Requires RigidBodyAPI on Target Prim #3088

Closed

Description

@GiulioRomualdi

I'm not sure if this is expected behavior or a bug.

I'm trying to attach an IMU sensor to a frame that does not have a RigidBodyAPI. Specifically, the prim path is:

/ergoCub/root_link/torso_1/waist_imu_0

As shown in the image below, the prim exists and has valid transform data, but no RigidBodyAPI component:

Image

When I try to create the IMU sensor using:

imu = ImuCfg(prim_path="{ENV_REGEX_NS}/Robot/root_link/torso_1/waist_imu_0", debug_vis=False)

I get the following runtime error:

RuntimeError: Failed to find a RigidBodyAPI for the prim paths: /World/envs/env_.*/Robot/root_link/torso_1/waist_imu_0

This error originates from this section of the code:

if prim.HasAPI(UsdPhysics.RigidBodyAPI):
self._view = self._physics_sim_view.create_rigid_body_view(self.cfg.prim_path.replace(".*", "*"))
else:
raise RuntimeError(f"Failed to find a RigidBodyAPI for the prim paths: {self.cfg.prim_path}")

Question

Is it required that the target prim for an IMU sensor has RigidBodyAPI?
I was expecting it to be possible to attach IMUs to arbitrary (static or articulated) frames, not just rigid bodies.

I'm using Isaac Lab v2.1.1 and IsaacSim 4.5.0

Activity

  1. GiulioRomualdi commented on Aug 5, 2025

    @GiulioRomualdi
    ContributorAuthor

    I tried to dig a bit into the problem and I realized that the IMU class calls create_rigid_body_view() and then, every frame, uses that view’s get_transforms(), get_velocities(), and get_coms() methods. All three calls rely on the prim owning a UsdPhysics.RigidBodyAPI handle. Indeed, the key point is that PhysX only tracks pose, velocity, and COM buffers for rigid bodies. If the prim pointed is just an Xform (as in my case) it has no rigid-body data it is not possible to call that function.

    TLDR: the sensor grabs its data straight from PhysX’s rigid-body buffers, so it can only attach to prims that are rigid bodies. Anything else fails because the required physics data isn’t there.


    I'm currently modifing the imu sensor to give the user the possibility to set a prim that is just an Xform.

  2. Mayankm96 commented on Aug 5, 2025

    @Mayankm96
    Contributor

    Obtaining this data from an Xform by using an XformPrimView is typically expensive since that goes through USD APIs. The best way to do this is to always get a rigid body prim and specify an offset to the prim to the location on the body that you want to measure.

    The offset is specified through the ImuCfg.OffsetCfg.

  3. GiulioRomualdi commented on Aug 5, 2025

    @GiulioRomualdi
    ContributorAuthor

    Obtaining this data from an Xform by using an XformPrimView is typically expensive since that goes through USD APIs. The best way to do this is to always get a rigid body prim and specify an offset to the prim to the location on the body that you want to measure.

    Yes, I agree on that, but what do you think about computing this transformation once only in the __init__ of the class? That way we can still rely on the RigidBodyView during simulation for performance, but support attaching the IMU to non-rigid prims (like Xforms) by resolving the fixed transform once and applying it to the configured offset.

    On the other hand, are there any programmatic ways to calculate the offset in IsaacLab, or should I write a separate script that does it? I could traverse the USD hierarchy manually using UsdGeom.XformCache to get the relative transform from the rigid body to the IMU frame, but if there’s already a utility for that in the IsaacLab codebase, I’d rather reuse it.

  4. Mayankm96 commented on Aug 5, 2025

    @Mayankm96
    Contributor

    @GiulioRomualdi that's a reasonable solution. In the past, we did not support it because the URDF importer was not saving the "Xform" prims in the USD for collapsed links. Now that it does that, we can think of a way to automate this process to compute the offset automatically on initialization.

    There are two possible organizations of Xform that we would have to deal with:

    1. Xform is under a rigid body:

      Robot
      -- Link_A
      -- Link_B
        -- Xform
      
    2. Xform is outside any rigid body

      Robot
      -- Link_A
      -- Link_B
      -- Xform
      

    If a user specifies the path to the "Xform" it becomes unclear w.r.t. which rigid body prim this must be computed (for the second case). One possible solution is that we add another attribute to SensorCfg.OffsetCfg that can be used to specify the prim path to the Xform and automate the calculation of the offset for it w.r.t. rigid body path specified in the SensorCfg.prim_path. Though this ends up requiring to specify two prim paths.

    Are there any programmatic ways to calculate the offset in IsaacLab, or should I write a separate script that does it?

    I don't think there's a function for this. Only snippet I found was in the environment implementation for one of the direct envs

            def get_env_local_pose(env_pos: torch.Tensor, xformable: UsdGeom.Xformable, device: torch.device):
                """Compute pose in env-local coordinates"""
                world_transform = xformable.ComputeLocalToWorldTransform(0)
                world_pos = world_transform.ExtractTranslation()
                world_quat = world_transform.ExtractRotationQuat()
    
                px = world_pos[0] - env_pos[0]
                py = world_pos[1] - env_pos[1]
                pz = world_pos[2] - env_pos[2]
                qx = world_quat.imaginary[0]
                qy = world_quat.imaginary[1]
                qz = world_quat.imaginary[2]
                qw = world_quat.real
    
                return torch.tensor([px, py, pz, qw, qx, qy, qz], device=device)

    Looping @pascal-roth for this discussion as well.

  5. added theissue type on Aug 5, 2025
  6. added
    enhancement
    on Aug 5, 2025
  7. GiulioRomualdi commented on Aug 5, 2025

    @GiulioRomualdi
    ContributorAuthor

    Thank you for replying. Since I think it’s easier to discuss in front of the code, I’ve opened a PR that we can iterate on #3094

  8. GiulioRomualdi commented on Aug 6, 2025

    @GiulioRomualdi
    ContributorAuthor

    I've iterated further on the problem and found that it also affects other sensors, such as FrameTransform. So, I tried to implement a more general solution.

    In the end, I believe what a final user really needs is a function that can easily find the rigid body ancestor of a given prim and compute the corresponding offset. This way, we can use the same function (for IMU sensors, FrameTransform, etc.) to programmatically specify the offset.

    To achieve this, I implemented a simple Python function that takes a USD file and returns both the offset and the ancestor to the user. I think this solution is more self-contained and provides a reasonable workaround for the issue.

    from typing import Tuple
    from pxr import Usd, UsdGeom, UsdPhysics, Sdf, Gf
    
    
    def _as_wxyz(q: Gf.Quatd) -> Tuple[float, float, float, float]:
        im = q.GetImaginary()
        return (float(q.GetReal()), float(im[0]), float(im[1]), float(im[2]))
    
    
    def _robot_root_from_prim_path(prim_path: str) -> str:
        """
        Deduce a robot root from a concrete path.
          - '/Foo/...'            -> '/Foo'
          - '/World/Foo/...'      -> '/World/Foo'
        """
        parts = [p for p in prim_path.strip("/").split("/") if p]
        if not parts:
            raise ValueError(f"Invalid prim_path: {prim_path!r}")
        if parts[0] == "World":
            if len(parts) < 2:
                raise ValueError(f"Path under /World must have at least two segments: {prim_path!r}")
            return f"/{parts[0]}/{parts[1]}"
        return f"/{parts[0]}"
    
    
    def resolve_rigid_ancestor_and_offset_from_usd(
        usd_path: str,
        prim_path: str,
        ENV_REGEX_PARENT: str = "{ENV_REGEX_NS}/Robot"
        time_code: Usd.TimeCode = Usd.TimeCode.Default(),
    ) -> Tuple[str, Tuple[float, float, float], Tuple[float, float, float, float]]:
        """
        Open `usd_path`, find `prim_path`, walk up to the nearest ancestor with
        UsdPhysics.RigidBodyAPI, and return:
            parent_path: "ENV_REGEX_PARENT[/<relative path from robot root to rigid ancestor>]"
            pos (x, y, z): offset from that rigid ancestor to the child prim
            rot (w, x, y, z): offset quaternion (ancestor to child)
        """
        stage = Usd.Stage.Open(usd_path)
        if stage is None:
            raise RuntimeError(f"Could not open USD: '{usd_path}'")
    
        child = stage.GetPrimAtPath(prim_path)
        if not child or not child.IsValid():
            raise RuntimeError(f"Prim '{prim_path}' not found or invalid in '{usd_path}'")
    
        # Find nearest rigid-body ancestor
        rigid = child
        while rigid and rigid.IsValid():
            if rigid.HasAPI(UsdPhysics.RigidBodyAPI):
                break
            rigid = rigid.GetParent()
    
        if not rigid or not rigid.IsValid() or not rigid.HasAPI(UsdPhysics.RigidBodyAPI):
            raise RuntimeError(
                f"No rigid-body ancestor found for '{prim_path}' in '{usd_path}'. "
                "Ensure a parent Xform has UsdPhysics.RigidBodyAPI applied."
            )
    
        # Compute relative transform (ancestor -> child)
        xfc = UsdGeom.XformCache(time_code)
        rel = xfc.GetLocalToWorldTransform(rigid).GetInverse() * xfc.GetLocalToWorldTransform(child)
        rel.Orthonormalize()
        pos = rel.ExtractTranslation()
        quat = rel.ExtractRotationQuat()
    
        # Tokenize the returned parent path
        robot_root_path = _robot_root_from_prim_path(prim_path)
        rigid_path = rigid.GetPath().pathString
        if not rigid_path.startswith(robot_root_path):
            # Fallback: if robot root can't be deduced, use token root
            token_parent = ENV_REGEX_PARENT
        else:
            rel_path = rigid_path[len(robot_root_path):]  # e.g. "/root_link" or ""
            token_parent = ENV_REGEX_PARENT + rel_path  # preserves leading '/'
    
        pos_tuple = (float(pos[0]), float(pos[1]), float(pos[2]))
        rot_tuple = _as_wxyz(quat)
    
        return token_parent, pos_tuple, rot_tuple

    The function can be called as

    parent_path, offset_pos, offset_rot = resolve_rigid_ancestor_and_offset_from_usd(
            usd_path=<usd_path>,
            prim_path="<prim_path>"
        )
  9. Mayankm96 commented on Aug 10, 2025

    @Mayankm96
    Contributor

    Yes, we likely need to make a more generic structure to have in all the sensors.

    Adding @jtigue-bdai and @ooctipus to follow-up on this.

  10. self-assigned this
    on Oct 8, 2025
  11. AntoineRichard commented on Aug 27, 2026

    @AntoineRichard
    Collaborator

    Thanks for the detailed trace and for opening #3094, @GiulioRomualdi. The capability ships now: the IMU resolves the closest rigid-body ancestor of the target prim, computes the fixed ancestor→target transform once at initialization, and composes it with the configured sensor offset — so pointing the sensor at a plain Xform like waist_imu_0 just works. It landed in #3864 (see source/isaaclab/isaaclab/sensors/imu/base_imu.py and source/isaaclab_physx/isaaclab_physx/sensors/imu/imu.py).

    Closing as resolved — please reopen if it doesn't behave as expected on a current release.


    🤖 This issue was reviewed as part of an AI-assisted triage of the Isaac Lab backlog, with automated verification against the current codebase. If we got this wrong, please reopen — we'd rather hear about it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions