Skip to content

Commit

Permalink
Add configuration option to include overlapping collision points
Browse files Browse the repository at this point in the history
  • Loading branch information
flferretti committed Feb 27, 2025
1 parent f2a99bd commit 36d8490
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docs/guide/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Environment variables starting with ``JAXSIM_COLLISION_`` are used to configure

*Default:* ``False``.

- ``JAXSIM_COLLISION_INCLUDE_OVERLAPS``: Enables or disables the inclusion of overlapping collision points.

*Default:* ``False``.

- ``JAXSIM_COLLISION_USE_BOTTOM_ONLY``: Limits collision detection to only the bottom half of the box or sphere.

*Default:* ``False``.
Expand Down
25 changes: 15 additions & 10 deletions src/jaxsim/api/kin_dyn_parameters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import dataclasses
import os

import jax.lax
import jax.numpy as jnp
Expand Down Expand Up @@ -797,18 +798,22 @@ def build_from(model_description: ModelDescription) -> ContactParameters:
collidable_points = model_description.all_enabled_collidable_points()

# Extract the positions L_p_C of the collidable points w.r.t. the link frames
# they are rigidly attached to. We exclude overlapping points.
points, idxs = jnp.unique(
jnp.vstack([cp.position for cp in collidable_points]),
axis=0,
return_index=True,
)
# they are rigidly attached to.
all_points = jnp.vstack([cp.position for cp in collidable_points])

if os.environ.get("JAXSIM_COLLISION_INCLUDE_OVERLAPS", "0").lower() in {
"false",
"0",
}:
points, idxs = jnp.unique(all_points, axis=0, return_index=True)
selected_points = map(collidable_points.__getitem__, idxs)
else:
points = all_points
selected_points = iter(collidable_points)

# Extract the indices of the links to which the collidable points are rigidly
# attached to.
# Extract the indices of the links to which the collidable points are rigidly attached.
link_index_of_points = tuple(
links_dict[cp.parent_link.name].index
for cp in map(collidable_points.__getitem__, idxs)
map(lambda cp: links_dict[cp.parent_link.name].index, selected_points)
)

# Build the ContactParameters object.
Expand Down

0 comments on commit 36d8490

Please sign in to comment.