42 #include <bullet/btBulletCollisionCommon.h>
48 static const std::string
NAME =
"Bullet";
49 const double MAX_DISTANCE_MARGIN = 99;
50 constexpr
char LOGNAME[] =
"collision_detection.bullet";
54 : CollisionEnv(model, padding, scale)
57 observer_handle_ =
getWorld()->addObserver(
58 [
this](
const World::ObjectConstPtr&
object, World::Action action) { notifyObjectChange(
object, action); });
60 for (
const std::pair<const std::string, urdf::LinkSharedPtr>& link :
robot_model_->getURDF()->links_)
62 addLinkAsCollisionObject(link.second);
67 double padding,
double scale)
68 : CollisionEnv(model, world, padding, scale)
71 observer_handle_ =
getWorld()->addObserver(
72 [
this](
const World::ObjectConstPtr&
object, World::Action action) { notifyObjectChange(
object, action); });
74 for (
const std::pair<const std::string, urdf::LinkSharedPtr>& link :
robot_model_->getURDF()->links_)
76 addLinkAsCollisionObject(link.second);
83 : CollisionEnv(other, world)
86 observer_handle_ =
getWorld()->addObserver(
87 [
this](
const World::ObjectConstPtr&
object,
World::Action action) { notifyObjectChange(
object, action); });
89 for (
const std::pair<const std::string, urdf::LinkSharedPtr>& link : other.robot_model_->getURDF()->links_)
91 addLinkAsCollisionObject(link.second);
111 const AllowedCollisionMatrix& acm)
const
122 std::vector<collision_detection_bullet::CollisionObjectWrapperPtr> cows;
127 manager_->setContactDistanceThreshold(MAX_DISTANCE_MARGIN);
130 for (
const collision_detection_bullet::CollisionObjectWrapperPtr& cow : cows)
133 manager_->setCollisionObjectsTransform(
138 for (
const std::string& link :
active_)
143 manager_->contactTest(res, req, acm,
true);
145 for (
const collision_detection_bullet::CollisionObjectWrapperPtr& cow : cows)
147 manager_->removeCollisionObject(cow->getName());
159 const AllowedCollisionMatrix& acm)
const
174 const AllowedCollisionMatrix& acm)
const
181 const AllowedCollisionMatrix* acm)
const
187 manager_->setContactDistanceThreshold(MAX_DISTANCE_MARGIN);
190 std::vector<collision_detection_bullet::CollisionObjectWrapperPtr> attached_cows;
194 for (
const collision_detection_bullet::CollisionObjectWrapperPtr& cow : attached_cows)
197 manager_->setCollisionObjectsTransform(
201 manager_->contactTest(res, req, acm,
false);
203 for (
const collision_detection_bullet::CollisionObjectWrapperPtr& cow : attached_cows)
205 manager_->removeCollisionObject(cow->getName());
216 std::vector<collision_detection_bullet::CollisionObjectWrapperPtr> attached_cows;
219 for (
const collision_detection_bullet::CollisionObjectWrapperPtr& cow : attached_cows)
227 for (
const std::string& link :
active_)
235 for (
const collision_detection_bullet::CollisionObjectWrapperPtr& cow : attached_cows)
255 std::vector<collision_detection_bullet::CollisionObjectType> collision_object_types;
265 auto cow = std::make_shared<collision_detection_bullet::CollisionObjectWrapper>(
267 collision_object_types,
false);
278 if (
manager_->hasCollisionObject(
id))
280 manager_->removeCollisionObject(
id);
291 if (
manager_->hasCollisionObject(
id))
293 manager_->removeCollisionObject(
id);
332 std::vector<collision_detection_bullet::CollisionObjectWrapperPtr>& cows)
const
334 std::vector<const moveit::core::AttachedBody*> attached_bodies;
341 std::vector<collision_detection_bullet::CollisionObjectType> collision_object_types(
348 collision_object_types, body->getTouchLinks()));
351 catch (std::exception&)
354 "Not adding " << body->getName() <<
" due to bad arguments.");
361 for (
const std::string& link : links)
369 ROS_ERROR_NAMED(
"collision_detection.bullet",
"Updating padding or scaling for unknown link: '%s'", link.c_str());
375 const moveit::core::RobotState& state,
const collision_detection_bullet::BulletDiscreteBVHManagerPtr& manager)
const
378 for (
const std::string& link :
active_)
387 if (!link->collision_array.empty())
389 const std::vector<urdf::CollisionSharedPtr>& col_array =
390 link->collision_array.empty() ? std::vector<urdf::CollisionSharedPtr>(1, link->collision) :
391 link->collision_array;
393 std::vector<shapes::ShapeConstPtr>
shapes;
395 std::vector<collision_detection_bullet::CollisionObjectType> collision_object_types;
397 for (
const auto& i : col_array)
399 if (i && i->geometry)
405 if (fabs(
getLinkScale(link->name) - 1.0) >= std::numeric_limits<double>::epsilon() ||
426 if (
manager_->hasCollisionObject(link->name))
428 manager_->removeCollisionObject(link->name);
438 active_.push_back(cow->getName());
440 catch (std::exception&)
442 ROS_ERROR_STREAM_NAMED(
"collision_detetction.bullet",
"Not adding " << link->name <<
" due to bad arguments.");