I'm using Bullet on my Final Project degree. I only use the collision detection module, and my objective is to detect collisions when the links of a robot arm hits external objects. More exactly, the aim is to prevent these collisions, so an alert could be generated and any security action would be taken.
I have successfully created the robot arm and detected collisions, but, how could I define a security margin for preventing them? This margin or distance has to be a constant. I've thought about enlarging their AABBs, so, for a given movement in the direction of a collision, the objects would appear earlier in the list of potential colliding pairs, and this would give us the opportunity to work with their contact manifolds. Then, set this distance as the collision margin for all objects, so we could do:
Code: Select all
int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
bool contact=false;
for (int i=0;i<numManifolds;i++)
{
btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
if (pt.getDistance()<SECURITY_MARGIN)
{
contact=true;
}
}
}
Is it right? I haven't tested it yet, because I don't know whether is possible to enlarge AABBs (and if it's, how).
Any other suggestion?
Thanks in advance.
Regards,
Francisco