-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collision filtering #4
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
20387be
Fix #3
m-decoster dd5d86e
Remove accidentally added notebook checkpoint
m-decoster 3be8e85
Collision checking and filtering with SceneGraphCollisionChecker
m-decoster c8a33df
Add collision filtering and checking functions to airo-drake and call…
m-decoster 56d46b7
Variable naming
m-decoster d43574a
More Pythonic version via list comprehension
m-decoster 5c0ae73
filtered is now also allowed to be a positional argument and is now T…
m-decoster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,54 @@ | ||
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 | ||
) -> 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 or not 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 list( | ||
map( | ||
lambda tup: (tup[0], tup[1], tup[2] != RobotCollisionType.kEnvironmentCollision), | ||
filter(lambda tup: tup[3] <= 0.0, zip(indices_one, indices_two, collision_types, distances)), | ||
) | ||
) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this asterisk * an accident?