-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix #3 * Remove accidentally added notebook checkpoint * Collision checking and filtering with SceneGraphCollisionChecker * Add collision filtering and checking functions to airo-drake and call these from the notebook * Variable naming * More Pythonic version via list comprehension * filtered is now also allowed to be a positional argument and is now True by default
- Loading branch information
1 parent
c3fd5ab
commit 37b9c61
Showing
4 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import itertools | ||
from typing import List, Tuple | ||
|
||
from airo_typing import JointConfigurationType | ||
from pydrake.all import BodyIndex | ||
from pydrake.planning import RobotCollisionType, SceneGraphCollisionChecker | ||
|
||
|
||
def filter_collisions_between_all_body_pairs( | ||
collision_checker: SceneGraphCollisionChecker, | ||
body_indices_one: List[BodyIndex], | ||
body_indices_two: List[BodyIndex], | ||
filtered: bool = True, | ||
) -> None: | ||
"""Enable or disable collision filtering between all pairs of the bodies listed in body_indices_one and body_indices_two. | ||
When collision filtering is enabled for two bodies, they are allowed to collide. | ||
Args: | ||
collision_checker: The collision checker instance to alter. | ||
body_indices_one: A list of body indices. | ||
body_indices_two: A list of body indices. | ||
filtered: Whether to filter collisions between these bodies.""" | ||
|
||
body_combinations = itertools.product(body_indices_one, body_indices_two) | ||
for body_index_1, body_index_2 in body_combinations: | ||
collision_checker.SetCollisionFilteredBetween(body_index_1, body_index_2, filtered) | ||
|
||
|
||
def list_collisions_between_bodies( | ||
collision_checker: SceneGraphCollisionChecker, q: JointConfigurationType | ||
) -> List[Tuple[BodyIndex, BodyIndex, bool]]: | ||
"""List all collisions between bodies for a joint configuration. | ||
The return type of this function is a list that contains all colliding bodies (if any) and a boolean value that indicates whether the collision is a self-collision. | ||
When the boolean value is false, the collision is an environment collision. | ||
Args: | ||
collision_checker: The collision checker instance to use. | ||
q: The joint configuration of the robot to check. | ||
Returns: | ||
A list of tuples of colliding body indices and a boolean value that is True when the collision is a self collision.""" | ||
robot_clearance = collision_checker.CalcRobotClearance(q, 1.0) | ||
indices_one = robot_clearance.robot_indices() | ||
indices_two = robot_clearance.other_indices() | ||
collision_types = robot_clearance.collision_types() | ||
distances = robot_clearance.distances() | ||
|
||
return [ | ||
(tup[0], tup[1], tup[2] != RobotCollisionType.kEnvironmentCollision) | ||
for tup in zip(indices_one, indices_two, collision_types, distances) | ||
if tup[3] <= 0.0 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters