Skip to content

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

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?

importfclimportnumpyasnpdefmy_Callback(o1, o2, cdata):
request=cdata.requestresult=cdata.resultprint(o1, type(o1))
print(o2, type(o2))
ifcdata.done:
returnTruefcl.collide(o1, o2, request, result)
if (notrequest.enable_costandresult.is_collisionandlen(result.contacts) >request.num_max_contacts):
cdata.done=Truereturncdata.done# Create collision geometry and objectsgeom1=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 objectsgeom_id_to_obj= { id(geom) : objforgeom, objinzip(geoms, objs) }
# Create map from geometry IDs to string namesgeom_id_to_name= { id(geom) : nameforgeom, nameinzip(geoms, names) }
# Create managermanager=fcl.DynamicAABBTreeCollisionManager()
manager.registerObjects(objs)
manager.setup()
print(objs)
print(manager.getObjects())
# Create collision request structurecrequest=fcl.CollisionRequest(num_max_contacts=100, enable_contact=True)
cdata=fcl.CollisionData()
# Run collision requestmanager.collide(cdata, my_Callback)
# Extract collision data from contacts and use that to infer set of# objects that are in collisionobjs_in_collision=set()
forcontactincdata.result.contacts:
# Extract collision geometries that are in contactcoll_geom_0=contact.o1coll_geom_1=contact.o2# Get their namescoll_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)
forcoll_pairinobjs_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