Bases: FailureCondition
MaxCollision (failure condition) used for navigation tasks
Episode terminates if the robot has collided more than max_collisions_allowed times
Note that we ignore collisions with any floor objects.
Parameters:
| Name |
Type |
Description |
Default |
robot_idn
|
int
|
robot identifier to evaluate collision checking with. Default is 0, corresponding to the first
robot added to the scene
|
0
|
ignore_self_collisions
|
bool
|
Whether to ignore robot self-collisions or not
|
True
|
max_collisions
|
int
|
Maximum number of collisions allowed for any robots in the scene before a termination
is triggered
|
500
|
Source code in OmniGibson/omnigibson/termination_conditions/max_collision.py
| class MaxCollision(FailureCondition):
"""
MaxCollision (failure condition) used for navigation tasks
Episode terminates if the robot has collided more than max_collisions_allowed times
Note that we ignore collisions with any floor objects.
Args:
robot_idn (int): robot identifier to evaluate collision checking with. Default is 0, corresponding to the first
robot added to the scene
ignore_self_collisions (bool): Whether to ignore robot self-collisions or not
max_collisions (int): Maximum number of collisions allowed for any robots in the scene before a termination
is triggered
"""
def __init__(self, robot_idn=0, ignore_self_collisions=True, max_collisions=500):
self._robot_idn = robot_idn
self._ignore_self_collisions = ignore_self_collisions
self._max_collisions = max_collisions
self._n_collisions = None
# Run super init
super().__init__()
def reset(self, task, env, env_indices):
# Call super first
super().reset(task, env, env_indices)
# Also reset collision counter
if self._n_collisions is None:
self._n_collisions = th.zeros(env.num_envs, dtype=th.int64)
self._n_collisions[env_indices] = 0
def _step(self, task, env, action):
# Terminate if the robot has collided more than self._max_collisions times
for env_idx in range(env.num_envs):
robot = env.scenes[env_idx].robots[self._robot_idn]
floors = list(env.scenes[env_idx].object_registry("category", "floors", []))
ignore_objs = floors + [robot] if self._ignore_self_collisions else floors
in_contact = RigidContactAPI.is_in_contact(
scene_idx=robot.scene.idx, query_set=[robot], with_set=None, ignore_set=ignore_objs, current_only=False
)
self._n_collisions[env_idx] += int(in_contact)
return self._n_collisions > self._max_collisions
|