Skip to content

how to exclude detection between some colliding bodies in DynamicAABBTreeCollisionManager #87

@Azure-Qiu

Description

@Azure-Qiu

Hi, I'm trying to apply FCL in a robotic arm, and when using fcl.DynamicAABBTreeCollisionManager I would like to exclude detection between some colliding bodies. I noticed that I can customize a callback function in manager.collide(cdata, my_callback), but I noticed that the collision objects o1,o2 in the callback function don't match the registered addresses, how do I correspond the collision objects for filtering?

import fcl
import numpy as np

def my_Callback(o1, o2, cdata):
    request = cdata.request
    result = cdata.result

    print(o1, type(o1))
    print(o2, type(o2))

    if cdata.done:
        return True

    fcl.collide(o1, o2, request, result)

    if (not request.enable_cost and result.is_collision and len(result.contacts) > request.num_max_contacts):
        cdata.done = True

    return cdata.done


# Create collision geometry and objects
geom1 = fcl.Cylinder(1.0, 1.0)
obj1 = fcl.CollisionObject(geom1)

geom2 = fcl.Cylinder(1.0, 1.0)
obj2 = fcl.CollisionObject(geom2, fcl.Transform(np.array([0.0, 0.0, 0.3])))

geom3 = fcl.Cylinder(1.0, 1.0)
obj3 = fcl.CollisionObject(geom3, fcl.Transform(np.array([0.0, 0.0, 3.0])))

geoms = [geom1, geom2, geom3]
objs = [obj1, obj2, obj3]
names = ['obj1', 'obj2', 'obj3']


# Create map from geometry IDs to objects
geom_id_to_obj = { id(geom) : obj for geom, obj in zip(geoms, objs) }

# Create map from geometry IDs to string names
geom_id_to_name = { id(geom) : name for geom, name in zip(geoms, names) }

# Create manager
manager = fcl.DynamicAABBTreeCollisionManager()
manager.registerObjects(objs)
manager.setup()

print(objs)
print(manager.getObjects())

# Create collision request structure
crequest = fcl.CollisionRequest(num_max_contacts=100, enable_contact=True)
cdata = fcl.CollisionData()

# Run collision request
manager.collide(cdata, my_Callback)

# Extract collision data from contacts and use that to infer set of
# objects that are in collision
objs_in_collision = set()

for contact in cdata.result.contacts:
    # Extract collision geometries that are in contact
    coll_geom_0 = contact.o1
    coll_geom_1 = contact.o2

    # Get their names
    coll_names = [geom_id_to_name[id(coll_geom_0)], geom_id_to_name[id(coll_geom_1)]]
    coll_names = tuple(sorted(coll_names))
    objs_in_collision.add(coll_names)

for coll_pair in objs_in_collision:
    print('Object {} in collision with object {}!'.format(coll_pair[0], coll_pair[1]))

[<fcl.fcl.CollisionObject object at 0x000002DDBFF6BE10>, <fcl.fcl.CollisionObject object at 0x000002DDD0594D20>, <fcl.fcl.CollisionObject object at 0x000002DDD0594C60>]
[<fcl.fcl.CollisionObject object at 0x000002DDBFF6BE10>, <fcl.fcl.CollisionObject object at 0x000002DDD0594D20>, <fcl.fcl.CollisionObject object at 0x000002DDD0594C60>]
<fcl.fcl.CollisionObject object at 0x000002DDD0594C00> <class 'fcl.fcl.CollisionObject'> 3151706541056
<fcl.fcl.CollisionObject object at 0x000002DDD0594CC0> <class 'fcl.fcl.CollisionObject'> 3151706541248
Object obj1 in collision with object obj2!

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions