RigidPrimView apply_forces_and_torques_at_pos

Hi there,

I would like to use apply_forces_and_torques_at_pos to control an RL agent.
However, I am getting unexpected behavior out of the API.

Say I have a RigidBodyPrimView and I want to apply N forces at different positions. In this case, I tried to apply 8 forces. Also, for the sake of this example, I disabled gravity to figure out what was happening.

In this experiment, I apply forces as shown below:

print("forces", A[0:8])
print("Positions", O[0:8])
print("Indices", I[0:8])

self._platforms.base.apply_forces_and_torques_at_pos(forces=A, positions=O, indices=I, is_global=False)

The values inside the tensors are the following:

forces tensor([[ 0.7071,  0.7071,  0.0000],
        [-0.7071, -0.7071,  0.0000],
        [ 0.0000,  0.0000,  0.0000],
        [ 0.0000,  0.0000,  0.0000],
        [ 0.0000,  0.0000,  0.0000],
        [ 0.0000,  0.0000,  0.0000],
        [ 0.0000,  0.0000,  0.0000],
        [ 0.0000,  0.0000,  0.0000]], device='cuda:0')
Positions tensor([[ 0.3536,  0.3536,  0.0000],
        [ 0.3536,  0.3536,  0.0000],
        [-0.3536,  0.3536,  0.0000],
        [-0.3536,  0.3536,  0.0000],
        [-0.3536, -0.3536,  0.0000],
        [-0.3536, -0.3536,  0.0000],
        [ 0.3536, -0.3536,  0.0000],
        [ 0.3536, -0.3536,  0.0000]], device='cuda:0')
Indices tensor([0, 0, 0, 0, 0, 0, 0, 0], device='cuda:0')

From what I understand, this should result in the object not moving at all, the forces are canceling each other’s and are applied at the same position. Yet, the objects are moving.
After some debugging, it seems that providing multiple times the same index leads to some issues where indexes are getting mixed-up.

On the other hand, when applying actions as shown below, only the last action is being applied.

        A = A.reshape(self._num_envs, self._num_actions, 3)
        I = I.reshape(self._num_envs, self._num_actions)
        O = O.reshape(self._num_envs, self._num_actions, 3)
        for i in range(self._num_actions):
            self._platforms.base.apply_forces_and_torques_at_pos(forces=A[:,i], positions=O[:,i], indices=I[:,i], is_global=False)

Is there any way to solve this problem? I can create N fixed rigid bodies at the root of the object, which I assume would result in the correct behavior, it just seems wrong.

Thanks in advance,

Cheers,

Antoine

Hi Antoine,

The vectorized APIs in RigidPrimView should be called only once per physics simulation step. Each subsequent call within the same physics step will override the values that were passed in previous calls until a physics step happens. The forces and positions tensors should also have the shape of (num_bodies, 3), where num_bodies is the number of bodies in the RigidPrimView. We do not support passing in multiple values in the same call for the same body.

1 Like

Hi Kelly,

Thanks for the clarification. I figured as much. I ended up creating N dummy rigid-bodies at the root of the robot. Maybe it could be nice to add this to the doc?

Thanks again,

Cheers,

Antoine

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.