41 return fcl::Transform3f(fcl::Matrix3f(frame.
M.
data[0], frame.
M.
data[1], frame.
M.
data[2], frame.
M.
data[3], frame.
M.
data[4], frame.
M.
data[5], frame.
M.
data[6], frame.
M.
data[7], frame.
M.
data[8]), fcl::Vec3f(frame.
p.
x(), frame.
p.
y(), frame.
p.
z()));
58 for (
const auto&
object : objects)
60 std::shared_ptr<fcl::CollisionObject> new_object;
81 for (fcl::CollisionObject* collision_object :
fcl_objects_)
83 std::shared_ptr<KinematicElement> element =
kinematic_elements_[
reinterpret_cast<long>(collision_object->getUserData())].lock();
86 ThrowPretty(
"Expired pointer, this should not happen - make sure to call UpdateCollisionObjects() after UpdateSceneFrames()");
89 collision_object->computeAABB();
100 if (element->is_robot_link || element->closest_robot_link.lock())
106 shape = scaled_shape;
115 shape = scaled_shape;
120 #if ROS_VERSION_MINIMUM(1, 12, 0) 121 std::shared_ptr<fcl::CollisionGeometry> geometry;
130 geometry.reset(
new fcl::Plane(p->a, p->b, p->c, p->d));
136 geometry.reset(
new fcl::Sphere(
s->radius));
142 const double* size =
s->size;
143 geometry.reset(
new fcl::Box(size[0], size[1], size[2]));
149 bool degenerate_capsule = (
s->length <= 2 *
s->radius);
152 geometry.reset(
new fcl::Cylinder(
s->radius,
s->length));
156 geometry.reset(
new fcl::Capsule(
s->radius,
s->length - 2 *
s->radius));
163 geometry.reset(
new fcl::Cone(
s->radius,
s->length));
168 auto g =
new fcl::BVHModel<fcl::OBBRSS>();
169 auto mesh =
dynamic_cast<const shapes::Mesh*
>(shape.get());
170 if (mesh->vertex_count > 0 && mesh->triangle_count > 0)
172 std::vector<fcl::Triangle> tri_indices(mesh->triangle_count);
173 for (
unsigned int i = 0; i < mesh->triangle_count; ++i)
175 fcl::Triangle(mesh->triangles[3 * i], mesh->triangles[3 * i + 1], mesh->triangles[3 * i + 2]);
177 std::vector<fcl::Vec3f> points(mesh->vertex_count);
178 for (
unsigned int i = 0; i < mesh->vertex_count; ++i)
179 points[i] = fcl::Vec3f(mesh->vertices[3 * i], mesh->vertices[3 * i + 1], mesh->vertices[3 * i + 2]);
182 g->addSubModel(points, tri_indices);
191 geometry.reset(
new fcl::OcTree(g->octree));
195 ThrowPretty(
"This shape type (" << ((
int)shape->type) <<
") is not supported using FCL yet");
197 geometry->computeLocalAABB();
198 geometry->setUserData(reinterpret_cast<void*>(kinematic_element_id));
199 std::shared_ptr<fcl::CollisionObject> ret(
new fcl::CollisionObject(geometry));
200 ret->setUserData(reinterpret_cast<void*>(kinematic_element_id));
207 std::shared_ptr<KinematicElement> e1 = scene->
kinematic_elements_[
reinterpret_cast<long>(o1->getUserData())].lock();
208 std::shared_ptr<KinematicElement> e2 = scene->
kinematic_elements_[
reinterpret_cast<long>(o2->getUserData())].lock();
210 bool isRobot1 = e1->is_robot_link || e1->closest_robot_link.lock();
211 bool isRobot2 = e2->is_robot_link || e2->closest_robot_link.lock();
213 if (!isRobot1 && !isRobot2)
return false;
215 if (isRobot1 && isRobot2 && !
self)
return false;
217 if (e1->parent.lock() == e2->parent.lock())
return false;
219 if (e1->closest_robot_link.lock() && e2->closest_robot_link.lock() && e1->closest_robot_link.lock() == e2->closest_robot_link.lock())
return false;
221 if (isRobot1 && isRobot2)
223 const std::string& name1 = e1->closest_robot_link.lock() ? e1->closest_robot_link.lock()->segment.getName() : e1->parent.lock()->segment.getName();
224 const std::string& name2 = e2->closest_robot_link.lock() ? e2->closest_robot_link.lock()->segment.getName() : e2->parent.lock()->segment.getName();
232 data->
request.num_max_contacts = 1000;
237 fcl::DistanceRequest req;
238 fcl::DistanceResult res;
239 req.enable_nearest_points =
false;
240 fcl::distance(o1, o2, req, res);
253 return data_->
result.isCollision();
260 std::shared_ptr<fcl::BroadPhaseCollisionManager> manager(
new fcl::DynamicAABBTreeCollisionManager());
266 return !data.
result.isCollision();
273 std::vector<fcl::CollisionObject*> shapes1;
274 std::vector<fcl::CollisionObject*> shapes2;
277 std::shared_ptr<KinematicElement> e =
kinematic_elements_[
reinterpret_cast<long>(o->getUserData())].lock();
278 if (e->segment.getName() == o1 || e->parent.lock()->segment.getName() == o1) shapes1.push_back(o);
279 if (e->segment.getName() == o2 || e->parent.lock()->segment.getName() == o2) shapes2.push_back(o);
281 if (shapes1.size() == 0)
ThrowPretty(
"Can't find object '" << o1 <<
"'!");
282 if (shapes2.size() == 0)
ThrowPretty(
"Can't find object '" << o2 <<
"'!");
285 for (fcl::CollisionObject* s1 : shapes1)
287 for (fcl::CollisionObject* s2 : shapes2)
290 if (data.
result.isCollision())
return false;
300 std::shared_ptr<KinematicElement> element =
kinematic_elements_[
reinterpret_cast<long>(
object->getUserData())].lock();
301 if (element->segment.getName() == name)
303 return Eigen::Map<Eigen::Vector3d>(element->frame.p.data);
311 std::vector<std::string> tmp;
314 std::shared_ptr<KinematicElement> element =
kinematic_elements_[
reinterpret_cast<long>(
object->getUserData())].lock();
315 if (!element->closest_robot_link.lock())
317 tmp.push_back(element->segment.getName());
325 std::vector<std::string> tmp;
328 std::shared_ptr<KinematicElement> element =
kinematic_elements_[
reinterpret_cast<long>(
object->getUserData())].lock();
329 if (element->closest_robot_link.lock())
331 tmp.push_back(element->segment.getName());
void UpdateCollisionObjectTransforms() override
Updates collision object transformations from the kinematic tree.
CollisionSceneFCL * scene
std::shared_ptr< fcl::CollisionObject > ConstructFclCollisionObject(long i, std::shared_ptr< KinematicElement > element)
fcl::CollisionResult result
std::shared_ptr< Shape > ShapePtr
std::vector< std::weak_ptr< KinematicElement > > kinematic_elements_
std::vector< Val > GetValuesFromMap(const std::map< Key, Val > &map)
std::map< std::string, std::shared_ptr< fcl::CollisionObject > > fcl_cache_
static bool CollisionCallback(fcl::CollisionObject *o1, fcl::CollisionObject *o2, void *data)
std::vector< std::string > GetCollisionRobotLinks() override
Gets the collision robot links.
#define REGISTER_COLLISION_SCENE_TYPE(TYPE, DERIV)
fcl::Transform3f KDL2fcl(const KDL::Frame &frame)
std::vector< std::string > GetCollisionWorldLinks() override
Gets the collision world links.
void UpdateCollisionObjects(const std::map< std::string, std::weak_ptr< KinematicElement >> &objects) override
Creates the collision scene from kinematic elements.
bool always_externally_updated_collision_scene_
std::vector< fcl::CollisionObject * > fcl_objects_
fcl::CollisionRequest request
Eigen::Vector3d GetTranslation(const std::string &name) override
bool IsCollisionFree(const std::string &o1, const std::string &o2, double safe_distance=0.0) override
#define HIGHLIGHT_NAMED(name, x)
AllowedCollisionMatrix acm_
bool IsStateValid(bool self=true, double safe_distance=0.0) override
Check if the whole robot is valid (collision only).
static bool IsAllowedToCollide(fcl::CollisionObject *o1, fcl::CollisionObject *o2, bool self, CollisionSceneFCL *scene)
double world_link_padding_
static void CheckCollision(fcl::CollisionObject *o1, fcl::CollisionObject *o2, CollisionData *data)
bool getAllowedCollision(const std::string &name1, const std::string &name2) const
double robot_link_padding_
bool replace_cylinders_with_capsules_
std::shared_ptr< const Shape > ShapeConstPtr