IsaacLab: [Question] Filtering contacts between bodies

Question

Currently, the contact sensor works well for checking the contact forces on various links using a prim path expression in the form of regex. For example,

ContactSensorCfg(prim_path="{ENV_REGEX_NS}/Robot/.*", history_length=3, track_air_time=True)

Is it possible to filter out the collision/contacts of the robot with only certain objects in the environment? Currently, there exists an argument for the ContactSensorCfg called filter_prim_paths_expr which is supposed to do this, but when I pass expressions such as /World/envs/env_.*/Object/link_.*, it throws out the error:

[Error] [omni.physx.tensors.plugin] Filter pattern '/World/envs/env_.*/Object/link_.*' did not match the correct number of entries.

The Contact Sensor uses the RigidContactView class from omni.isaac.core but the example in the documentation only shows contact filtering with one environment. Using a regex expression instead in the same example doesn’t seem to work and returns a similar error as above.

Since the documentation is lacking for this use case, can the authors provide any guide to perform filtering contacts using regex expressions?

Thanks in advance 😃

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@AravindhPadmanabhan Based on this and this, using filter_prim_paths_expr=["/World/defaultGroundPlane/terrain/mesh"] should work.

@xzhu0428 , thanks a lot, your suggestion worked and I am able to get contact points.

But, I still have to specify max_contact_data_count (in line 260 of contact_sensor.py) to a non-zero value and if I set it to a value more than the number of bodies, I get more contact points and normals than the number of bodies in the contact sensor. And I get the following warning: Incomplete contact data is reported in GpuRigidContactView::getContactData because there are more contact data points than specified maxContactDataCount = 24. Could you please enlighten me on what these contact points mean and guide me to some documentation on how to find out which row corresponds to which body?

I had the same issue when I was working with the rough terrain ground mesh, but when I tried a flat environment using the ground plane:

/World/ground/GroundPlane/CollisionPlane

I did not get this issue, this collision plane didnt show up as a mesh, which leads me to believe that the mesh might calculate collisions in a different way? I’m really not sure thought, I’ll let you know once I find out more!

@AravindhPadmanabhan Based on this and this, using filter_prim_paths_expr=["/World/defaultGroundPlane/terrain/mesh"] should work.

After I set it up like this, I encountered this error: 2024-07-23 10:58:51 [9,486ms] [Error] [omni.physx.tensors.plugin] Filter pattern ‘/World/GroundPlane/terrain/mesh’ did not match the correct number of entries (expected 10, found 0)

@xliu0105 For the ground plane, you may configure the ContactSensor as:

contact_forces = ContactSensorCfg(
        prim_path="{ENV_REGEX_NS}/Robot/LF_FOOT",
        filter_prim_paths_expr=["/World/defaultGroundPlane/GroundPlane/CollisionPlane"],
    )

However, I still have similar issues as @shafeef901 when I try to filter multiple prims for a franka arm.

prim_path="{ENV_REGEX_NS}/Object", 
#  doesn't work
filter_prim_paths_expr= ["{ENV_REGEX_NS}/Robot/.*finger"],
#  works
filter_prim_paths_expr= ["{ENV_REGEX_NS}/Robot/.*rightfinger", "{ENV_REGEX_NS}/Robot/.*leftfinger"], 

When using the the first expression, an error will pop out

[Error] [omni.physx.tensors.plugin] Filter pattern '/World/envs/env_*/Robot/*finger' did not match the correct number of entries (expected 1, found 2)

@Mayankm96 It seems to me that each expression can only correspond to one prim, is it correct?

Hello @Mayankm96 ,

I think I found a mistake in the newly added contact force assertions used in the unit test for the contact sensor.

I tried running test_contact_sensor.py and printed out the tensors being used in the assertions in line 292 and 295 and they turn out to be all 0s. Looks like the assertion passes only because they are all zero tensors.

I came across this when I was trying to find the contact forces and contact points of a robot with the ground. I tried this out using the example in source/standalone/tutorials/04_sensors/add_sensors_on_robot.py. I was able to get the contact forces using ContactSensor.data.net_forces_w. But to get contact points, I specified filters in ContactSensorCfg.filter_prim_paths_expr and used ContactSensor.contact_physx_view.get_contact_data(). Hence, I modified the ContactSensorCfg to look like this:

contact_forces = ContactSensorCfg(
        prim_path="{ENV_REGEX_NS}/Robot/.*_FOOT", update_period=0.0, history_length=6, debug_vis=True,
        filter_prim_paths_expr = ["/World/defaultGroundPlane"]
    )

I printed out Contact_sensor.data.net_forces_w, ContactSensor.data.force_matrix_w and ContactSensor.contact_physx_view.get_contact_data(). While net_forces_w had non-zero values which seemed reasonably correct, force_matrix_w and get_contact_data() were filled with 0s, as shown in the image below. I also got a warning that said GPU contact filter for collider '/World/defaultGroundPlane' is not supported. Could you please look into this and let me know how I can get the contact points between two prims? Thanks in advance!

Screenshot from 2024-05-13 13-56-45

P.S.: Also had to make max_contact_data_count a non-zero value in the create_rigid_contact_view() function in line 258 of source/extensions/omni.isaac.orbit/omni/isaac/orbit/sensors/contact_sensor/contact_sensor.py for get_contact_data() to work

It seems to me that filtering doesn’t work with regex expressions. So filter_prim_paths_expr should probably be renamed to filter_prim_paths. Furthermore, since we define contact_sensor in the config file, it’s not straightforward to infer num_envs. In my case, I hardcoded it to test it. Is there a better way to do so?