How to get the position of an object

Hello, I 'm using python scripts to run Isaac Sim. I need to get the position of an object which is composed of two cylinders in the script.

With only one cylinder, I can use the code below to get the position.

cylinder_position, cylinder_orientation = target.get_world_pose()

But when I try to use the prim to combine the two cylinders as one object, I fail to get a correct position using the prim.get_world_pose( ), with the position fixed as [0,0,0]. I wonder how the position of prim can follow the movement of cylinder, or are there other ways to get the position?

Thanks in advance!

Hi @Follograph

Can you provide more information (or a simplified .usd file) on the hierarchy/structure of the prims involved?

Hi @toni.nv

Here is my script to load the scene tube1.txt (4.2 KB), below is the prim to create the object and how I get the position.

target = XFormPrim("/World/target", name="target")
    # Make a target to follow
    target1 = cylinder.DynamicCylinder(
        "/World/target/bot",
        position=np.array([0.5, 0, 0.021]),
        orientation=np.array([0, 1, 0, 0]),
        color=np.array([1.0, 0, 0]),
        radius=0.008,
        height=0.042,
        mass=0.2,
    )
    target2 = cylinder.DynamicCylinder(
        "/World/target/top",
        position=np.array([0.5, 0, 0.046]),
        orientation=np.array([0, 1, 0, 0]),
        color=np.array([1.0, 0, 0]),
        radius=0.01,
        height=0.008,
        mass=0.2,
    )

if cube_position is None:
            cube_position, cube_orientation = target.get_world_pose()

It turns out that the origin of the target prim locates at [0,0,0]. How can I make the origin attached to the cylinder so that the position of the prim shows the position of the object as the object moves? Similar to this prim I create in GUI.

Thanks for your response!

Hi @Follograph

In this case, the recommended way to go is to wrap the /World/target XFrom prim with the Isaac Sim core RigidPrim API (since the dynamic object has both: Collider API and Rigid Body API) and use the wrapped prim to get the pose

Hi @toni.nv

I tried to add the RigidPrim API, but it seems hard to add the cylinders to the prim and the Rigid Body API of prim and cylinders will collide. Whatever, it is a possible way and I will try again later. Thanks!