flexible-collision-library / fcl

Flexible Collision Library
https://flexible-collision-library.github.io/
Other
1.35k stars 415 forks source link

After first collision detected,all other results are collisions #576

Closed marios-stam closed 2 years ago

marios-stam commented 2 years ago

I am facing a very weird bug. I am trying to detect collisions between 2 meshes and I am entering the coordinates of the one manually. As soon as the first collision is detected all the next results are collisions even if they weren't before. Do you have any idea what could be the problem?

void checker::setRobotTransform(float pos[3], float q[4]) { robot_mesh.set_transform(pos, q); }

bool checker::check_collision()
{

    std::cout << "Checking collision" << std::endl;
    // print coordinates of robot
    std::cout << "Robot coordinates: " << robot_mesh.collision_object->getTranslation()[0] << " "
              << robot_mesh.collision_object->getTranslation()[1] << " " << robot_mesh.collision_object->getTranslation()[2];

    // print rotation of robot
    std::cout << " - rotation: " << robot_mesh.collision_object->getQuatRotation().x() << " "
              << robot_mesh.collision_object->getQuatRotation().y() << " " << robot_mesh.collision_object->getQuatRotation().z() << " "
              << robot_mesh.collision_object->getQuatRotation().w() << std::endl;
    // print coordinates of environment
    std::cout << "Environment coordinates: " << environment_mesh.collision_object->getTranslation()[0] << " "
              << environment_mesh.collision_object->getTranslation()[1] << " " << environment_mesh.collision_object->getTranslation()[2];

    // print rotation of environment
    std::cout << " -rotation: " << environment_mesh.collision_object->getQuatRotation().x() << " "
              << environment_mesh.collision_object->getQuatRotation().y() << " " << environment_mesh.collision_object->getQuatRotation().z()
              << " " << environment_mesh.collision_object->getQuatRotation().w() << std::endl;

    request.gjk_solver_type = fcl::GJKSolverType::GST_INDEP;

    fcl::collide(environment_mesh.collision_object, robot_mesh.collision_object, request, result);

    std::cout << "Collision result: " << result.isCollision() << std::endl;

    return result.isCollision();
}`

image

I am updating the robot transform like this

void fcl_mesh::set_transform(float pos[], float quat[])
{

    // set transform
    fcl::Vector3f translation(pos[0], pos[1], pos[2]);

    // fc::Quaternion expects w, x, y, z
    fcl::Quaternion<float> q = fcl::Quaternion<float>(quat[3], quat[0], quat[1], quat[2]);

    collision_object->setTranslation(translation);
    collision_object->setQuatRotation(q);
}
marios-stam commented 2 years ago

I had to include this line before checking for every collision but this wasn't needed while I was working with the python bindings

 result.clear();