Sensor1.get_forces() vs acquire_net_contact_force_tensor()

Hi,
I’m working with a toy example which is based on the cartpole model but without the slider and I want to print the contact forces at the cart.

I see that there are 2 methods to get contact forces: 1) placing a sensor 2) acquire_net_force_tensor(), what is the difference between them?

In my example, I placed a sensor at the bottom of the cart
sensor_pose1 = gymapi.Transform(gymapi.Vec3(0, 0.0, -0.125))
sensor1 = gym.create_force_sensor(env, ball_handle, sensor_pose1)

when printing the values from the sensor and from acquire_net_contact_force_tensor(), the forces do not correspond:

See code here:
cart_pole_sensor.py (6.3 KB)
cartpole_sensor.urdf (1.1 KB)

1 Like

Hi,
Did you fix this problem? When I use ‘acquire_net_force_tensor()’ to get contact forces, the values are zeros at all time.

1 Like

With the tensor API, make sure you are calling refresh_net_contact_force_tensor for net contact forces or refresh_force_sensor_tensor for force sensors before reading the values from the buffer to retrieve the latest data from simulation. More documentation of force sensors can be found in the docs under programming/forcesensors.

You should also set contact_collection from 0 to 1

contact_collection: 1 # 0: CC_NEVER (don't collect contact info), 1: CC_LAST_SUBSTEP (collect only contacts on last substep), 2: CC_ALL_SUBSTEPS (default - all contacts)

in the corresponding yaml file for the environment, if you are using the examples from issacgymenvs.

3 Likes