54 std::map<std::string, std::vector<CollisionSphere>> link_body_decompositions;
62 const robot_model::RobotModelConstPtr& kmodel,
63 const std::map<std::string, std::vector<CollisionSphere>>& link_body_decompositions,
double size_x,
double size_y,
64 double size_z,
bool use_signed_distance_field,
double resolution,
double collision_tolerance,
65 double max_propogation_distance,
double padding,
double scale)
68 initialize(link_body_decompositions, Eigen::Vector3d(size_x, size_y, size_z), Eigen::Vector3d(0, 0, 0),
69 use_signed_distance_field, resolution, collision_tolerance, max_propogation_distance);
73 const Eigen::Vector3d& origin,
bool use_signed_distance_field,
75 double max_propogation_distance,
double padding)
78 std::map<std::string, std::vector<CollisionSphere>> link_body_decompositions;
79 initialize(link_body_decompositions, size, origin, use_signed_distance_field, resolution, collision_tolerance,
80 max_propogation_distance);
102 const std::map<std::string, std::vector<CollisionSphere>>& link_body_decompositions,
const Eigen::Vector3d& size,
103 const Eigen::Vector3d& origin,
bool use_signed_distance_field,
double resolution,
double collision_tolerance,
104 double max_propogation_distance)
116 const std::vector<const moveit::core::JointModelGroup*>& jmg =
robot_model_->getJointModelGroups();
117 for (std::vector<const moveit::core::JointModelGroup*>::const_iterator it = jmg.begin(); it != jmg.end(); it++)
121 std::map<std::string, bool> updated_group_entry;
123 for (
unsigned int i = 0; i < links.size(); i++)
125 updated_group_entry[links[i]] =
true;
129 DistanceFieldCacheEntryPtr dfce =
138 bool generate_distance_field)
const 141 if (!dfce || (generate_distance_field && !dfce->distance_field_))
145 DistanceFieldCacheEntryPtr new_dfce =
158 GroupStateRepresentationPtr& gsr)
const 178 DistanceFieldCacheEntryConstPtr
183 DistanceFieldCacheEntryConstPtr ret;
190 if (group_name != cur->group_name_)
192 ROS_DEBUG(
"No cache entry as group name changed from %s to %s", cur->group_name_.c_str(), group_name.c_str());
204 ROS_DEBUG(
"Regenerating distance field as some relevant part of the acm changed");
214 GroupStateRepresentationPtr gsr;
221 GroupStateRepresentationPtr& gsr)
const 231 GroupStateRepresentationPtr gsr;
239 GroupStateRepresentationPtr& gsr)
const 243 ROS_WARN(
"Shouldn't be calling this function with initialized gsr - ACM " 251 GroupStateRepresentationPtr& gsr)
const 253 for (
unsigned int i = 0; i < gsr->dfce_->link_names_.size() + gsr->dfce_->attached_body_names_.size(); i++)
255 bool is_link = i < gsr->dfce_->link_names_.size();
256 if ((is_link && !gsr->dfce_->link_has_geometry_[i]) || !gsr->dfce_->self_collision_enabled_[i])
258 const std::vector<CollisionSphere>* collision_spheres_1;
263 collision_spheres_1 = &(gsr->link_body_decompositions_[i]->getCollisionSpheres());
264 sphere_centers_1 = &(gsr->link_body_decompositions_[i]->getSphereCenters());
268 collision_spheres_1 =
269 &(gsr->attached_body_decompositions_[i - gsr->dfce_->link_names_.size()]->getCollisionSpheres());
270 sphere_centers_1 = &(gsr->attached_body_decompositions_[i - gsr->dfce_->link_names_.size()]->getSphereCenters());
275 std::vector<unsigned int> colls;
282 for (
unsigned int j = 0; j < colls.size(); j++)
287 con.
pos = gsr->link_body_decompositions_[i]->getSphereCenters()[colls[j]];
294 gsr->attached_body_decompositions_[i - gsr->dfce_->link_names_.size()]->getSphereCenters()[colls[j]];
296 con.
body_name_1 = gsr->dfce_->attached_body_names_[i - gsr->dfce_->link_names_.size()];
305 gsr->gradients_[i].types[colls[j]] =
SELF;
307 gsr->gradients_[i].collision =
true;
321 ROS_DEBUG(
"Link %s in self collision", gsr->dfce_->link_names_[i].c_str());
332 bool in_collision =
false;
334 for (
unsigned int i = 0; i < gsr->dfce_->link_names_.size(); i++)
336 const std::string& link_name = gsr->dfce_->link_names_[i];
337 bool is_link = i < gsr->dfce_->link_names_.size();
338 if ((is_link && !gsr->dfce_->link_has_geometry_[i]) || !gsr->dfce_->self_collision_enabled_[i])
343 const std::vector<CollisionSphere>* collision_spheres_1;
347 collision_spheres_1 = &(gsr->link_body_decompositions_[i]->getCollisionSpheres());
348 sphere_centers_1 = &(gsr->link_body_decompositions_[i]->getSphereCenters());
352 collision_spheres_1 =
353 &(gsr->attached_body_decompositions_[i - gsr->dfce_->link_names_.size()]->getCollisionSpheres());
354 sphere_centers_1 = &(gsr->attached_body_decompositions_[i - gsr->dfce_->link_names_.size()]->getSphereCenters());
360 if (gsr->dfce_->acm_.getSize() > 0)
363 for (
unsigned int j = 0; j < gsr->dfce_->link_names_.size(); j++)
366 if (link_name == gsr->dfce_->link_names_[j])
372 if (gsr->dfce_->acm_.getEntry(link_name, gsr->dfce_->link_names_[j], col_type) &&
378 if (gsr->link_distance_fields_[j])
380 coll = gsr->link_distance_fields_[j]->getCollisionSphereGradients(
407 GroupStateRepresentationPtr& gsr)
const 409 unsigned int num_links = gsr->dfce_->link_names_.size();
410 unsigned int num_attached_bodies = gsr->dfce_->attached_body_names_.size();
412 for (
unsigned int i = 0; i < num_links + num_attached_bodies; i++)
414 for (
unsigned int j = i + 1; j < num_links + num_attached_bodies; j++)
418 bool i_is_link = i < num_links;
419 bool j_is_link = j < num_links;
421 if ((i_is_link && !gsr->dfce_->link_has_geometry_[i]) || (j_is_link && !gsr->dfce_->link_has_geometry_[j]))
424 if (!gsr->dfce_->intra_group_collision_enabled_[i][j])
427 if (i_is_link && j_is_link &&
435 else if (!i_is_link || !j_is_link)
438 if (!i_is_link && j_is_link)
440 for (
unsigned int k = 0; k < gsr->attached_body_decompositions_[i - num_links]->getSize(); k++)
443 gsr->link_body_decompositions_[j],
444 gsr->attached_body_decompositions_[i - num_links]->getPosedBodySphereDecomposition(k)))
451 else if (i_is_link && !j_is_link)
453 for (
unsigned int k = 0; k < gsr->attached_body_decompositions_[j - num_links]->getSize(); k++)
456 gsr->link_body_decompositions_[i],
457 gsr->attached_body_decompositions_[j - num_links]->getPosedBodySphereDecomposition(k)))
466 for (
unsigned int k = 0; k < gsr->attached_body_decompositions_[i - num_links]->getSize() && all_ok; k++)
468 for (
unsigned int l = 0; l < gsr->attached_body_decompositions_[j - num_links]->getSize(); l++)
471 gsr->attached_body_decompositions_[i - num_links]->getPosedBodySphereDecomposition(k),
472 gsr->attached_body_decompositions_[j - num_links]->getPosedBodySphereDecomposition(l)))
493 name_1 = gsr->dfce_->link_names_[i];
497 name_1 = gsr->dfce_->attached_body_names_[i - num_links];
502 name_2 = gsr->dfce_->link_names_[j];
506 name_2 = gsr->dfce_->attached_body_names_[j - num_links];
510 collision_detection::CollisionResult::ContactMap::iterator it =
511 res.
contacts.find(std::pair<std::string, std::string>(name_1, name_2));
518 num_pair = it->second.size();
521 const std::vector<CollisionSphere>* collision_spheres_1;
522 const std::vector<CollisionSphere>* collision_spheres_2;
527 collision_spheres_1 = &(gsr->link_body_decompositions_[i]->getCollisionSpheres());
528 sphere_centers_1 = &(gsr->link_body_decompositions_[i]->getSphereCenters());
532 collision_spheres_1 = &(gsr->attached_body_decompositions_[i - num_links]->getCollisionSpheres());
533 sphere_centers_1 = &(gsr->attached_body_decompositions_[i - num_links]->getSphereCenters());
537 collision_spheres_2 = &(gsr->link_body_decompositions_[j]->getCollisionSpheres());
538 sphere_centers_2 = &(gsr->link_body_decompositions_[j]->getSphereCenters());
542 collision_spheres_2 = &(gsr->attached_body_decompositions_[j - num_links]->getCollisionSpheres());
543 sphere_centers_2 = &(gsr->attached_body_decompositions_[j - num_links]->getSphereCenters());
546 for (
unsigned int k = 0; k < collision_spheres_1->size() && num_pair < (int)req.
max_contacts_per_pair; k++)
548 for (
unsigned int l = 0; l < collision_spheres_2->size() && num_pair < (int)req.
max_contacts_per_pair; l++)
550 Eigen::Vector3d gradient = (*sphere_centers_1)[k] - (*sphere_centers_2)[l];
551 double dist = gradient.norm();
556 if (dist < (*collision_spheres_1)[k].radius_ + (*collision_spheres_2)[l].radius_)
574 con.
pos = gsr->link_body_decompositions_[i]->getSphereCenters()[k];
598 gsr->gradients_[i].types[k] =
INTRA;
599 gsr->gradients_[i].collision =
true;
600 gsr->gradients_[j].types[l] =
INTRA;
601 gsr->gradients_[j].collision =
true;
636 bool in_collision =
false;
637 unsigned int num_links = gsr->dfce_->link_names_.size();
638 unsigned int num_attached_bodies = gsr->dfce_->attached_body_names_.size();
640 for (
unsigned int i = 0; i < num_links + num_attached_bodies; i++)
642 for (
unsigned int j = i + 1; j < num_links + num_attached_bodies; j++)
646 bool i_is_link = i < num_links;
647 bool j_is_link = j < num_links;
648 if ((i_is_link && !gsr->dfce_->link_has_geometry_[i]) || (j_is_link && !gsr->dfce_->link_has_geometry_[j]))
650 if (!gsr->dfce_->intra_group_collision_enabled_[i][j])
652 const std::vector<CollisionSphere>* collision_spheres_1;
653 const std::vector<CollisionSphere>* collision_spheres_2;
658 collision_spheres_1 = &(gsr->link_body_decompositions_[i]->getCollisionSpheres());
659 sphere_centers_1 = &(gsr->link_body_decompositions_[i]->getSphereCenters());
663 collision_spheres_1 = &(gsr->attached_body_decompositions_[i - num_links]->getCollisionSpheres());
664 sphere_centers_1 = &(gsr->attached_body_decompositions_[i - num_links]->getSphereCenters());
668 collision_spheres_2 = &(gsr->link_body_decompositions_[j]->getCollisionSpheres());
669 sphere_centers_2 = &(gsr->link_body_decompositions_[j]->getSphereCenters());
673 collision_spheres_2 = &(gsr->attached_body_decompositions_[j - num_links]->getCollisionSpheres());
674 sphere_centers_2 = &(gsr->attached_body_decompositions_[j - num_links]->getSphereCenters());
676 for (
unsigned int k = 0; k < collision_spheres_1->size(); k++)
678 for (
unsigned int l = 0; l < collision_spheres_2->size(); l++)
680 Eigen::Vector3d gradient = (*sphere_centers_1)[k] - (*sphere_centers_2)[l];
681 double dist = gradient.norm();
682 if (dist < gsr->gradients_[i].distances[k])
684 gsr->gradients_[i].distances[k] = dist;
685 gsr->gradients_[i].gradients[k] = gradient;
686 gsr->gradients_[i].types[k] =
INTRA;
688 if (dist < gsr->gradients_[j].distances[l])
690 gsr->gradients_[j].distances[l] = dist;
691 gsr->gradients_[j].gradients[l] = -gradient;
692 gsr->gradients_[j].types[l] =
INTRA;
706 if (
robot_model_->getJointModelGroup(group_name) == NULL)
708 ROS_WARN(
"No group %s", group_name.c_str());
712 dfce->group_name_ = group_name;
720 ROS_WARN_STREAM(
"Allowed Collision Matrix is null, enabling all collisions " 721 "in the DistanceFieldCacheEntry");
725 dfce->link_names_ =
robot_model_->getJointModelGroup(group_name)->getUpdatedLinkModelNames();
726 std::vector<const moveit::core::AttachedBody*> all_attached_bodies;
727 dfce->state_->getAttachedBodies(all_attached_bodies);
728 unsigned int att_count = 0;
731 std::vector<bool> all_true(dfce->link_names_.size() + all_attached_bodies.size(),
true);
732 std::vector<bool> all_false(dfce->link_names_.size() + all_attached_bodies.size(),
false);
735 dfce->self_collision_enabled_.resize(dfce->link_names_.size() + all_attached_bodies.size(),
true);
736 dfce->intra_group_collision_enabled_.resize(dfce->link_names_.size() + all_attached_bodies.size());
738 for (
unsigned int i = 0; i < dfce->link_names_.size(); i++)
740 std::string link_name = dfce->link_names_[i];
744 for (
unsigned int j = 0; j < lsv.size(); j++)
746 if (lsv[j]->
getName() == link_name)
748 dfce->link_state_indices_.push_back(j);
756 ROS_DEBUG(
"No link state found for link %s", dfce->link_names_[i].c_str());
762 dfce->link_has_geometry_.push_back(
true);
770 dfce->self_collision_enabled_[i] =
false;
773 dfce->intra_group_collision_enabled_[i] = all_true;
774 for (
unsigned int j = i + 1; j < dfce->link_names_.size(); j++)
776 if (link_name == dfce->link_names_[j])
778 dfce->intra_group_collision_enabled_[i][j] =
false;
783 dfce->intra_group_collision_enabled_[i][j] =
false;
787 std::vector<const moveit::core::AttachedBody*> link_attached_bodies;
789 for (
unsigned int j = 0; j < link_attached_bodies.size(); j++, att_count++)
791 dfce->attached_body_names_.push_back(link_attached_bodies[j]->
getName());
792 dfce->attached_body_link_state_indices_.push_back(dfce->link_state_indices_[i]);
794 if (acm->
getEntry(link_name, link_attached_bodies[j]->getName(), t))
798 dfce->intra_group_collision_enabled_[i][att_count + dfce->link_names_.size()] =
false;
806 if (link_attached_bodies[j]->getTouchLinks().find(link_name) !=
807 link_attached_bodies[j]->getTouchLinks().end())
809 dfce->intra_group_collision_enabled_[i][att_count + dfce->link_names_.size()] =
false;
818 dfce->self_collision_enabled_[i] =
true;
819 dfce->intra_group_collision_enabled_[i] = all_true;
824 dfce->link_has_geometry_.push_back(
false);
825 dfce->link_body_indices_.push_back(0);
826 dfce->self_collision_enabled_[i] =
false;
827 dfce->intra_group_collision_enabled_[i] = all_false;
831 for (
unsigned int i = 0; i < dfce->attached_body_names_.size(); i++)
833 dfce->intra_group_collision_enabled_[i + dfce->link_names_.size()] = all_true;
837 if (acm->
getEntry(dfce->attached_body_names_[i], dfce->attached_body_names_[i], t) &&
840 dfce->self_collision_enabled_[i + dfce->link_names_.size()] =
false;
842 for (
unsigned int j = i + 1; j < dfce->attached_body_names_.size(); j++)
844 if (acm->
getEntry(dfce->attached_body_names_[i], dfce->attached_body_names_[j], t) &&
847 dfce->intra_group_collision_enabled_[i + dfce->link_names_.size()][j + dfce->link_names_.size()] =
false;
858 std::map<std::string, GroupStateRepresentationPtr>::const_iterator it =
862 dfce->pregenerated_group_state_representation_ = it->second;
865 std::map<std::string, bool> updated_map;
866 if (!dfce->link_names_.empty())
868 const std::vector<const moveit::core::JointModel*>& child_joint_models =
869 dfce->state_->getJointModelGroup(dfce->group_name_)->getActiveJointModels();
870 for (
unsigned int i = 0; i < child_joint_models.size(); i++)
872 updated_map[child_joint_models[i]->getName()] =
true;
877 const std::vector<std::string> state_variable_names = state.
getVariableNames();
878 for (std::vector<std::string>::const_iterator name_iter = state_variable_names.begin();
879 name_iter != state_variable_names.end(); name_iter++)
882 dfce->state_values_.push_back(val);
883 if (updated_map.count(*name_iter) == 0)
885 dfce->state_check_indices_.push_back(dfce->state_values_.size() - 1);
886 ROS_DEBUG_STREAM(
"Non-group joint " << *name_iter <<
" will be checked for state changes");
890 if (generate_distance_field)
892 if (dfce->distance_field_)
895 "will use existing one");
899 std::vector<PosedBodyPointDecompositionPtr> non_group_link_decompositions;
900 std::vector<PosedBodyPointDecompositionVectorPtr> non_group_attached_body_decompositions;
901 const std::map<std::string, bool>& updated_group_map =
in_group_update_map_.find(group_name)->second;
902 for (
unsigned int i = 0; i <
robot_model_->getLinkModelsWithCollisionGeometry().size(); i++)
904 std::string link_name =
robot_model_->getLinkModelsWithCollisionGeometry()[i]->getName();
906 if (updated_group_map.find(link_name) != updated_group_map.end())
913 non_group_link_decompositions.back()->updatePose(dfce->state_->getFrameTransform(link_state->
getName()));
915 std::vector<const moveit::core::AttachedBody*> attached_bodies;
916 dfce->state_->getAttachedBodies(attached_bodies, link_state);
917 for (
unsigned int j = 0; j < attached_bodies.size(); j++)
919 non_group_attached_body_decompositions.push_back(
933 for (
unsigned int i = 0; i < non_group_link_decompositions.size(); i++)
935 all_points.insert(all_points.end(), non_group_link_decompositions[i]->getCollisionPoints().begin(),
936 non_group_link_decompositions[i]->getCollisionPoints().end());
939 for (
unsigned int i = 0; i < non_group_attached_body_decompositions.size(); i++)
941 all_points.insert(all_points.end(), non_group_attached_body_decompositions[i]->getCollisionPoints().begin(),
942 non_group_attached_body_decompositions[i]->getCollisionPoints().end());
945 dfce->distance_field_->addPointsToField(all_points);
946 ROS_DEBUG_STREAM(
"CollisionRobot distance field has been initialized with " << all_points.size() <<
" points.");
954 const std::vector<const moveit::core::LinkModel*>& link_models =
robot_model_->getLinkModelsWithCollisionGeometry();
955 for (
unsigned int i = 0; i < link_models.size(); i++)
957 if (link_models[i]->getShapes().empty())
959 ROS_WARN(
"No collision geometry for link model %s though there should be", link_models[i]->
getName().c_str());
965 link_models[i]->getCollisionOriginTransforms(), resolution,
973 visualization_msgs::MarkerArray& model_markers)
const 976 std_msgs::ColorRGBA robot_color;
978 robot_color.b = 0.8f;
982 std_msgs::ColorRGBA world_links_color;
983 world_links_color.r = 1;
984 world_links_color.g = 1;
985 world_links_color.b = 0;
986 world_links_color.a = 0.5;
989 visualization_msgs::Marker sphere_marker;
990 sphere_marker.header.frame_id =
robot_model_->getRootLinkName();
991 sphere_marker.header.stamp =
ros::Time(0);
993 sphere_marker.id = 0;
994 sphere_marker.type = visualization_msgs::Marker::SPHERE;
995 sphere_marker.action = visualization_msgs::Marker::ADD;
996 sphere_marker.pose.orientation.x = 0;
997 sphere_marker.pose.orientation.y = 0;
998 sphere_marker.pose.orientation.z = 0;
999 sphere_marker.pose.orientation.w = 1;
1000 sphere_marker.color = robot_color;
1003 unsigned int id = 0;
1007 std::map<std::string, unsigned int>::const_iterator map_iter;
1011 const std::string& link_name = map_iter->first;
1012 unsigned int link_index = map_iter->second;
1015 if (std::find(group_link_names.begin(), group_link_names.end(), link_name) != group_link_names.end())
1017 sphere_marker.color = robot_color;
1021 sphere_marker.color = world_links_color;
1024 collision_detection::PosedBodySphereDecompositionPtr sphere_representation(
1027 for (
unsigned int j = 0; j < sphere_representation->getCollisionSpheres().size(); j++)
1029 tf::pointEigenToMsg(sphere_representation->getSphereCenters()[j], sphere_marker.pose.position);
1030 sphere_marker.scale.x = sphere_marker.scale.y = sphere_marker.scale.z =
1031 2 * sphere_representation->getCollisionSpheres()[j].radius_;
1032 sphere_marker.id = id;
1035 model_markers.markers.push_back(sphere_marker);
1041 double resolution,
const std::map<std::string, std::vector<CollisionSphere>>& link_spheres)
1044 const std::vector<const moveit::core::LinkModel*>& link_models =
robot_model_->getLinkModelsWithCollisionGeometry();
1046 for (
unsigned int i = 0; i < link_models.size(); i++)
1048 if (link_models[i]->getShapes().empty())
1051 <<
" since it contains no geometries");
1056 link_models[i]->getCollisionOriginTransforms(), resolution,
1061 if (link_spheres.find(link_models[i]->getName()) != link_spheres.end())
1063 bd->replaceCollisionSpheres(link_spheres.find(link_models[i]->getName())->second, Eigen::Affine3d::Identity());
1074 PosedBodySphereDecompositionPtr ret;
1079 PosedBodyPointDecompositionPtr
1082 PosedBodyPointDecompositionPtr ret;
1086 ROS_ERROR_NAMED(
"collision_distance_field",
"No link body decomposition for link %s.", ls->
getName().c_str());
1094 GroupStateRepresentationPtr& gsr)
const 1096 for (
unsigned int i = 0; i < gsr->dfce_->link_names_.size(); i++)
1099 if (gsr->dfce_->link_has_geometry_[i])
1103 gsr->gradients_[i].closest_distance = DBL_MAX;
1104 gsr->gradients_[i].collision =
false;
1105 gsr->gradients_[i].types.assign(gsr->link_body_decompositions_[i]->getCollisionSpheres().size(),
NONE);
1106 gsr->gradients_[i].distances.assign(gsr->link_body_decompositions_[i]->getCollisionSpheres().size(), DBL_MAX);
1107 gsr->gradients_[i].gradients.assign(gsr->link_body_decompositions_[i]->getCollisionSpheres().size(),
1108 Eigen::Vector3d(0.0, 0.0, 0.0));
1109 gsr->gradients_[i].sphere_locations = gsr->link_body_decompositions_[i]->getSphereCenters();
1113 for (
unsigned int i = 0; i < gsr->dfce_->attached_body_names_.size(); i++)
1118 ROS_WARN(
"Attached body discrepancy");
1123 if (gsr->attached_body_decompositions_.size() != att->
getShapes().size())
1125 ROS_WARN(
"Attached body size discrepancy");
1129 for (
unsigned int j = 0; j < att->
getShapes().size(); j++)
1134 gsr->gradients_[i + gsr->dfce_->link_names_.size()].closest_distance = DBL_MAX;
1135 gsr->gradients_[i + gsr->dfce_->link_names_.size()].collision =
false;
1136 gsr->gradients_[i + gsr->dfce_->link_names_.size()].types.assign(
1137 gsr->attached_body_decompositions_[i]->getCollisionSpheres().size(),
NONE);
1138 gsr->gradients_[i + gsr->dfce_->link_names_.size()].distances.assign(
1139 gsr->attached_body_decompositions_[i]->getCollisionSpheres().size(), DBL_MAX);
1140 gsr->gradients_[i + gsr->dfce_->link_names_.size()].gradients.assign(
1141 gsr->attached_body_decompositions_[i]->getCollisionSpheres().size(), Eigen::Vector3d(0.0, 0.0, 0.0));
1142 gsr->gradients_[i + gsr->dfce_->link_names_.size()].sphere_locations =
1143 gsr->attached_body_decompositions_[i]->getSphereCenters();
1149 GroupStateRepresentationPtr& gsr)
const 1151 if (!dfce->pregenerated_group_state_representation_)
1158 gsr->gradients_.resize(dfce->link_names_.size() + dfce->attached_body_names_.size());
1160 Eigen::Vector3d link_size;
1161 Eigen::Vector3d link_origin;
1162 for (
unsigned int i = 0; i < dfce->link_names_.size(); i++)
1165 if (dfce->link_has_geometry_[i])
1171 PosedBodySphereDecompositionPtr& link_bd = gsr->link_body_decompositions_.back();
1172 double diameter = 2 * link_bd->getBoundingSphereRadius();
1173 link_size = Eigen::Vector3d(diameter, diameter, diameter);
1174 link_origin = link_bd->getBoundingSphereCenter() - 0.5 * link_size;
1177 << dfce->link_names_[i] <<
" with size [" << link_size.x() <<
", " << link_size.y() <<
", " 1178 << link_size.z() <<
"] and origin " << link_origin.x() <<
", " << link_origin.y() <<
", " 1179 << link_origin.z());
1183 gsr->link_distance_fields_.back()->addPointsToField(link_bd->getCollisionPoints());
1184 ROS_DEBUG_STREAM(
"Created PosedDistanceField for link " << dfce->link_names_[i] <<
" with " 1185 << link_bd->getCollisionPoints().size() <<
" points");
1189 gsr->gradients_[i].types.resize(gsr->link_body_decompositions_.back()->getCollisionSpheres().size(),
NONE);
1190 gsr->gradients_[i].distances.resize(gsr->link_body_decompositions_.back()->getCollisionSpheres().size(),
1192 gsr->gradients_[i].gradients.resize(gsr->link_body_decompositions_.back()->getCollisionSpheres().size());
1193 gsr->gradients_[i].sphere_radii = gsr->link_body_decompositions_.back()->getSphereRadii();
1198 gsr->link_body_decompositions_.push_back(PosedBodySphereDecompositionPtr());
1199 gsr->link_distance_fields_.push_back(PosedDistanceFieldPtr());
1207 gsr->gradients_.resize(dfce->link_names_.size() + dfce->attached_body_names_.size());
1208 for (
unsigned int i = 0; i < dfce->link_names_.size(); i++)
1211 if (dfce->link_has_geometry_[i])
1215 gsr->gradients_[i].sphere_locations = gsr->link_body_decompositions_[i]->getSphereCenters();
1220 for (
unsigned int i = 0; i < dfce->attached_body_names_.size(); i++)
1222 int link_index = dfce->attached_body_link_state_indices_[i];
1229 gsr->attached_body_decompositions_.push_back(
1231 gsr->gradients_[i + dfce->link_names_.size()].types.resize(
1232 gsr->attached_body_decompositions_.back()->getCollisionSpheres().size(),
NONE);
1233 gsr->gradients_[i + dfce->link_names_.size()].distances.resize(
1234 gsr->attached_body_decompositions_.back()->getCollisionSpheres().size(), DBL_MAX);
1235 gsr->gradients_[i + dfce->link_names_.size()].gradients.resize(
1236 gsr->attached_body_decompositions_.back()->getCollisionSpheres().size());
1237 gsr->gradients_[i + dfce->link_names_.size()].sphere_locations =
1238 gsr->attached_body_decompositions_.back()->getSphereCenters();
1239 gsr->gradients_[i + dfce->link_names_.size()].sphere_radii =
1240 gsr->attached_body_decompositions_.back()->getSphereRadii();
1249 for (
unsigned int i = 0; i < new_state_values.size(); i++)
1254 if (dfce->state_values_.size() != new_state_values.size())
1260 for (
unsigned int i = 0; i < dfce->state_check_indices_.size(); i++)
1263 fabs(dfce->state_values_[dfce->state_check_indices_[i]] - new_state_values[dfce->state_check_indices_[i]]);
1267 <<
" has changed by " << diff <<
" radians");
1271 std::vector<const moveit::core::AttachedBody*> attached_bodies_dfce;
1272 std::vector<const moveit::core::AttachedBody*> attached_bodies_state;
1273 dfce->state_->getAttachedBodies(attached_bodies_dfce);
1275 if (attached_bodies_dfce.size() != attached_bodies_state.size())
1280 for (
unsigned int i = 0; i < attached_bodies_dfce.size(); i++)
1282 if (attached_bodies_dfce[i]->
getName() != attached_bodies_state[i]->getName())
1286 if (attached_bodies_dfce[i]->getTouchLinks() != attached_bodies_state[i]->getTouchLinks())
1290 if (attached_bodies_dfce[i]->getShapes().size() != attached_bodies_state[i]->getShapes().size())
1294 for (
unsigned int j = 0; j < attached_bodies_dfce[i]->getShapes().size(); j++)
1296 if (attached_bodies_dfce[i]->getShapes()[j] != attached_bodies_state[i]->getShapes()[j])
1308 if (dfce->acm_.getSize() != acm.
getSize())
1310 ROS_DEBUG(
"Allowed collision matrix size mismatch");
1313 std::vector<const moveit::core::AttachedBody*> attached_bodies;
1314 dfce->state_->getAttachedBodies(attached_bodies);
1315 for (
unsigned int i = 0; i < dfce->link_names_.size(); i++)
1317 std::string link_name = dfce->link_names_[i];
1318 if (dfce->link_has_geometry_[i])
1320 bool self_collision_enabled =
true;
1322 if (acm.
getEntry(link_name, link_name, t))
1326 self_collision_enabled =
false;
1329 if (self_collision_enabled != dfce->self_collision_enabled_[i])
1336 for (
unsigned int j = i; j < dfce->link_names_.size(); j++)
1340 if (dfce->link_has_geometry_[j])
1342 bool intra_collision_enabled =
true;
1343 if (acm.
getEntry(link_name, dfce->link_names_[j], t))
1347 intra_collision_enabled =
false;
1350 if (dfce->intra_group_collision_enabled_[i][j] != intra_collision_enabled)
const std::string & getName() const
The name of this link.
bool getIntraGroupProximityGradients(GroupStateRepresentationPtr &gsr) const
void getAttachedBodies(std::vector< const AttachedBody * > &attached_bodies) const
Get all bodies attached to the model corresponding to this state.
PosedBodySphereDecompositionVectorPtr getAttachedBodySphereDecomposition(const robot_state::AttachedBody *att, double resolution)
bool compareCacheEntryToState(const DistanceFieldCacheEntryConstPtr &dfce, const moveit::core::RobotState &state) const
const std::string & getName() const
Get the name of the joint.
void generateCollisionCheckingStructures(const std::string &group_name, const moveit::core::RobotState &state, const collision_detection::AllowedCollisionMatrix *acm, GroupStateRepresentationPtr &gsr, bool generate_distance_field) const
const std::vector< const LinkModel * > & getUpdatedLinkModels() const
Get the names of the links that are to be updated when the state of this group changes. This includes links that are in the kinematic model but outside this group, if those links are descendants of joints in this group that have their values updated. The order is the correct order for updating the corresponding states.
Representation of a collision checking request.
static const double DEFAULT_RESOLUTION
void addLinkBodyDecompositions(double resolution)
Collisions between the pair of bodies is never ok, i.e., if two bodies are in contact in a particular...
void createCollisionModelMarker(const moveit::core::RobotState &state, visualization_msgs::MarkerArray &model_markers) const
bool doBoundingSpheresIntersect(const PosedBodySphereDecompositionConstPtr &p1, const PosedBodySphereDecompositionConstPtr &p2)
std::vector< Eigen::Vector3d, Eigen::aligned_allocator< Eigen::Vector3d > > vector_Vector3d
const Eigen::Affine3d & getGlobalLinkTransform(const std::string &link_name)
bool getCollisionSphereGradients(const distance_field::DistanceField *distance_field, const std::vector< CollisionSphere > &sphere_list, const EigenSTL::vector_Vector3d &sphere_centers, GradientInfo &gradient, const CollisionType &type, double tolerance, bool subtract_radii, double maximum_value, bool stop_at_first_collision)
const JointModelGroup * getJointModelGroup(const std::string &group) const
Get the model of a particular joint group.
A body attached to a robot link.
const std::string & getName() const
Get the name of the joint group.
ContactMap contacts
A map returning the pairs of ids of the bodies in contact, plus information about the contacts themse...
IMETHOD Vector diff(const Vector &p_w_a, const Vector &p_w_b, double dt=1)
planning_scene::PlanningScenePtr planning_scene_
void setPadding(double padding)
Set the link padding (for every link)
const Eigen::Affine3d & getFrameTransform(const std::string &id)
Get the transformation matrix from the model frame to the frame identified by id. ...
static const double DEFAULT_SIZE_Z
std::string getName(void *handle)
const std::map< std::string, double > & getLinkPadding() const
Get the link paddings as a map (from link names to padding value)
Representation of a collision checking result.
void initialize(const std::map< std::string, std::vector< CollisionSphere >> &link_body_decompositions, const Eigen::Vector3d &size, const Eigen::Vector3d &origin, bool use_signed_distance_field, double resolution, double collision_tolerance, double max_propogation_distance)
std::map< std::string, unsigned int > link_body_decomposition_index_map_
bool getEntry(const std::string &name1, const std::string &name2, AllowedCollision::Type &allowed_collision_type) const
Get the type of the allowed collision between two elements. Return true if the entry is included in t...
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CollisionRobotDistanceField(const robot_model::RobotModelConstPtr &kmodel)
double collision_tolerance_
double max_propogation_distance_
static const double DEFAULT_MAX_PROPOGATION_DISTANCE
Generic interface to collision detection.
const AttachedBody * getAttachedBody(const std::string &name) const
Get the attached body named name. Return NULL if not found.
std::size_t getSize() const
Get the size of the allowed collision matrix (number of specified entries)
std::size_t contact_count
Number of contacts returned.
bool collision
True if collision was found, false otherwise.
robot_model::RobotModelConstPtr robot_model_
The kinematic model corresponding to this collision model.
const JointModel * getParentJointModel() const
Get the joint model whose child this link is. There will always be a parent joint.
const std::vector< shapes::ShapeConstPtr > & getShapes() const
Get the shapes that make up this attached body.
std::size_t max_contacts
Overall maximum number of contacts to compute.
PosedBodyPointDecompositionVectorPtr getAttachedBodyPointDecomposition(const robot_state::AttachedBody *att, double resolution)
static const double DEFAULT_COLLISION_TOLERANCE
bool compareCacheEntryToAllowedCollisionMatrix(const DistanceFieldCacheEntryConstPtr &dfce, const collision_detection::AllowedCollisionMatrix &acm) const
static const double resolution
std::map< std::string, std::map< std::string, bool > > in_group_update_map_
This class maintains the representation of the environment as seen by a planning instance. The environment geometry, the robot geometry and state are maintained.
bool use_signed_distance_field_
void updateGroupStateRepresentationState(const moveit::core::RobotState &state, GroupStateRepresentationPtr &gsr) const
Definition of a structure for the allowed collision matrix. All elements in the collision world are r...
PosedBodySphereDecompositionPtr getPosedLinkBodySphereDecomposition(const moveit::core::LinkModel *ls, unsigned int ind) const
#define ROS_ASSERT_MSG(cond,...)
static const double DEFAULT_SIZE_Y
This class represents a collision model of the robot and can be used for self collision checks (to ch...
std::string group_name
The group name to check collisions for (optional; if empty, assume the complete robot) ...
const std::vector< shapes::ShapeConstPtr > & getShapes() const
Get shape associated to the collision geometry for this link.
bool contacts
If true, compute contacts.
boost::mutex update_cache_lock_
bool getIntraGroupCollisions(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, GroupStateRepresentationPtr &gsr) const
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
const EigenSTL::vector_Affine3d & getGlobalCollisionBodyTransforms() const
Get the global transforms for the collision bodies.
DistanceFieldCacheEntryPtr generateDistanceFieldCacheEntry(const std::string &group_name, const moveit::core::RobotState &state, const collision_detection::AllowedCollisionMatrix *acm, bool generate_distance_field) const
void pointEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Point &m)
#define ROS_DEBUG_COND(cond,...)
const std::vector< std::string > & getUpdatedLinkModelNames() const
Get the names of the links returned by getUpdatedLinkModels()
std::size_t max_contacts_per_pair
Maximum number of contacts to compute per pair of bodies (multiple bodies may be in contact at differ...
static const double DEFAULT_SIZE_X
void getGroupStateRepresentation(const DistanceFieldCacheEntryConstPtr &dfce, const moveit::core::RobotState &state, GroupStateRepresentationPtr &gsr) const
std::vector< BodyDecompositionConstPtr > link_body_decomposition_vector_
const LinkModel * getLinkModel(const std::string &link) const
Get the model of a particular link.
static const bool DEFAULT_USE_SIGNED_DISTANCE_FIELD
#define ROS_ERROR_NAMED(name,...)
DistanceFieldCacheEntryConstPtr getDistanceFieldCacheEntry(const std::string &group_name, const moveit::core::RobotState &state, const collision_detection::AllowedCollisionMatrix *acm) const
Representation of a robot's state. This includes position, velocity, acceleration and effort...
Collisions between a particular pair of bodies does not imply that the robot configuration is in coll...
void updateLinkTransforms()
Update the reference frame transforms for links. This call is needed before using the transforms of l...
double getVariablePosition(const std::string &variable) const
Get the position of a particular variable. An exception is thrown if the variable is not known...
A link from the robot. Contains the constant transform applied to the link and its geometry...
const std::vector< std::string > & getUpdatedLinkModelsWithGeometryNames() const
Get the names of the links returned by getUpdatedLinkModels()
const std::vector< std::string > & getVariableNames() const
Get the names of the variables that make up this state, in the order they are stored in memory...
A DistanceField implementation that uses a vector propagation method. Distances propagate outward fro...
std::map< std::string, GroupStateRepresentationPtr > pregenerated_group_state_representation_map_
bool getSelfProximityGradients(GroupStateRepresentationPtr &gsr) const
DistanceFieldCacheEntryPtr distance_field_cache_entry_
std::size_t getVariableCount() const
Get the number of variables that make up this state.
Object defining bodies that can be attached to robot links. This is useful when handling objects pick...
void checkSelfCollisionHelper(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state, const collision_detection::AllowedCollisionMatrix *acm, GroupStateRepresentationPtr &gsr) const
PosedBodyPointDecompositionPtr getPosedLinkBodyPointDecomposition(const moveit::core::LinkModel *ls) const
bool getCollisionSphereCollision(const distance_field::DistanceField *distance_field, const std::vector< CollisionSphere > &sphere_list, const EigenSTL::vector_Vector3d &sphere_centers, double maximum_value, double tolerance)
virtual void checkSelfCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &state) const
Check for self collision. Any collision between any pair of links is checked for, NO collisions are i...
bool getSelfCollisions(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, GroupStateRepresentationPtr &gsr) const