moveit2
The MoveIt Motion Planning Framework for ROS 2.
collision_distance_field_types.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: E. Gil Jones */
36 
38 #include <geometric_shapes/body_operations.h>
41 #include <rclcpp/clock.hpp>
42 #include <rclcpp/logger.hpp>
43 #include <rclcpp/time.hpp>
44 #include <memory>
45 
46 const static double EPSILON = 0.0001;
47 
48 namespace collision_detection
49 {
50 static const rclcpp::Logger LOGGER =
51  rclcpp::get_logger("moveit_collision_distance_field.collision_distance_field_types");
52 
53 std::vector<CollisionSphere> determineCollisionSpheres(const bodies::Body* body, Eigen::Isometry3d& relative_transform)
54 {
55  std::vector<CollisionSphere> css;
56 
57  if (body->getType() == shapes::ShapeType::SPHERE)
58  {
59  collision_detection::CollisionSphere cs(body->getPose().translation(), body->getDimensions()[0]);
60  css.push_back(cs);
61  }
62  else
63  {
64  bodies::BoundingCylinder cyl;
65  body->computeBoundingCylinder(cyl);
66  unsigned int num_points = ceil(cyl.length / (cyl.radius / 2.0));
67  double spacing = cyl.length / ((num_points * 1.0) - 1.0);
68  relative_transform = cyl.pose;
69 
70  for (unsigned int i = 1; i < num_points - 1; i++)
71  {
73  relative_transform * Eigen::Vector3d(0, 0, (-cyl.length / 2.0) + i * spacing), cyl.radius);
74  css.push_back(cs);
75  }
76  }
77 
78  return css;
79 }
80 
81 bool PosedDistanceField::getCollisionSphereGradients(const std::vector<CollisionSphere>& sphere_list,
82  const EigenSTL::vector_Vector3d& sphere_centers,
83  GradientInfo& gradient, const CollisionType& type,
84  double tolerance, bool subtract_radii, double maximum_value,
85  bool stop_at_first_collision)
86 {
87  // assumes gradient is properly initialized
88 
89  bool in_collision = false;
90  for (unsigned int i = 0; i < sphere_list.size(); ++i)
91  {
92  Eigen::Vector3d p = sphere_centers[i];
93  Eigen::Vector3d grad(0, 0, 0);
94  bool in_bounds;
95  double dist = this->getDistanceGradient(p.x(), p.y(), p.z(), grad.x(), grad.y(), grad.z(), in_bounds);
96  if (!in_bounds && grad.norm() > 0)
97  {
98  // out of bounds
99  return true;
100  }
101 
102  if (dist < maximum_value)
103  {
104  if (subtract_radii)
105  {
106  dist -= sphere_list[i].radius_;
107 
108  if ((dist < 0) && (-dist >= tolerance))
109  {
110  in_collision = true;
111  }
112 
113  dist = std::abs(dist);
114  }
115  else
116  {
117  if (sphere_list[i].radius_ - dist > tolerance)
118  {
119  in_collision = true;
120  }
121  }
122 
123  if (dist < gradient.closest_distance)
124  {
125  gradient.closest_distance = dist;
126  }
127 
128  if (dist < gradient.distances[i])
129  {
130  gradient.types[i] = type;
131  gradient.distances[i] = dist;
132  gradient.gradients[i] = grad;
133  }
134  }
135 
136  if (stop_at_first_collision && in_collision)
137  {
138  return true;
139  }
140  }
141  return in_collision;
142 }
143 
145  const std::vector<CollisionSphere>& sphere_list,
146  const EigenSTL::vector_Vector3d& sphere_centers, GradientInfo& gradient,
147  const CollisionType& type, double tolerance, bool subtract_radii, double maximum_value,
148  bool stop_at_first_collision)
149 {
150  // assumes gradient is properly initialized
151 
152  bool in_collision = false;
153  for (unsigned int i = 0; i < sphere_list.size(); ++i)
154  {
155  Eigen::Vector3d p = sphere_centers[i];
156  Eigen::Vector3d grad;
157  bool in_bounds;
158  double dist = distance_field->getDistanceGradient(p.x(), p.y(), p.z(), grad.x(), grad.y(), grad.z(), in_bounds);
159  if (!in_bounds && grad.norm() > EPSILON)
160  {
161  RCLCPP_DEBUG(LOGGER, "Collision sphere point is out of bounds %lf, %lf, %lf", p.x(), p.y(), p.z());
162  return true;
163  }
164 
165  if (dist < maximum_value)
166  {
167  if (subtract_radii)
168  {
169  dist -= sphere_list[i].radius_;
170 
171  if ((dist < 0) && (-dist >= tolerance))
172  {
173  in_collision = true;
174  }
175  }
176  else
177  {
178  if (sphere_list[i].radius_ - dist > tolerance)
179  {
180  in_collision = true;
181  }
182  }
183 
184  if (dist < gradient.closest_distance)
185  {
186  gradient.closest_distance = dist;
187  }
188 
189  if (dist < gradient.distances[i])
190  {
191  gradient.types[i] = type;
192  gradient.distances[i] = dist;
193  gradient.gradients[i] = grad;
194  }
195  }
196 
197  if (stop_at_first_collision && in_collision)
198  {
199  return true;
200  }
201  }
202  return in_collision;
203 }
204 
206  const std::vector<CollisionSphere>& sphere_list,
207  const EigenSTL::vector_Vector3d& sphere_centers, double maximum_value,
208  double tolerance)
209 {
210  for (unsigned int i = 0; i < sphere_list.size(); ++i)
211  {
212  Eigen::Vector3d p = sphere_centers[i];
213  Eigen::Vector3d grad;
214  bool in_bounds = true;
215  double dist = distance_field->getDistanceGradient(p.x(), p.y(), p.z(), grad.x(), grad.y(), grad.z(), in_bounds);
216 
217  if (!in_bounds && grad.norm() > 0)
218  {
219  RCLCPP_DEBUG(LOGGER, "Collision sphere point is out of bounds");
220  return true;
221  }
222 
223  if ((maximum_value > dist) && (sphere_list[i].radius_ - dist > tolerance))
224  {
225  return true;
226  }
227  }
228 
229  return false;
230 }
231 
233  const std::vector<CollisionSphere>& sphere_list,
234  const EigenSTL::vector_Vector3d& sphere_centers, double maximum_value,
235  double tolerance, unsigned int num_coll, std::vector<unsigned int>& colls)
236 {
237  colls.clear();
238  for (unsigned int i = 0; i < sphere_list.size(); ++i)
239  {
240  Eigen::Vector3d p = sphere_centers[i];
241  Eigen::Vector3d grad;
242  bool in_bounds = true;
243  double dist = distance_field->getDistanceGradient(p.x(), p.y(), p.z(), grad.x(), grad.y(), grad.z(), in_bounds);
244  if (!in_bounds && (grad.norm() > 0))
245  {
246  RCLCPP_DEBUG(LOGGER, "Collision sphere point is out of bounds");
247  return true;
248  }
249  if (maximum_value > dist && (sphere_list[i].radius_ - dist > tolerance))
250  {
251  if (num_coll == 0)
252  {
253  return true;
254  }
255 
256  colls.push_back(i);
257  if (colls.size() >= num_coll)
258  {
259  return true;
260  }
261  }
262  }
263 
264  return !colls.empty();
265 }
266 
270 
271 BodyDecomposition::BodyDecomposition(const shapes::ShapeConstPtr& shape, double resolution, double padding)
272 {
273  std::vector<shapes::ShapeConstPtr> shapes;
274  EigenSTL::vector_Isometry3d poses(1, Eigen::Isometry3d::Identity());
275 
276  shapes.push_back(shape);
277  init(shapes, poses, resolution, padding);
278 }
279 
280 BodyDecomposition::BodyDecomposition(const std::vector<shapes::ShapeConstPtr>& shapes,
281  const EigenSTL::vector_Isometry3d& poses, double resolution, double padding)
282 {
283  init(shapes, poses, resolution, padding);
284 }
285 
286 void BodyDecomposition::init(const std::vector<shapes::ShapeConstPtr>& shapes, const EigenSTL::vector_Isometry3d& poses,
287  double resolution, double padding)
288 {
289  bodies_.clear();
290  for (unsigned int i = 0; i < shapes.size(); ++i)
291  {
292  bodies_.addBody(shapes[i].get(), poses[i], padding);
293  }
294 
295  // collecting collision spheres
296  collision_spheres_.clear();
298  std::vector<CollisionSphere> body_spheres;
299  EigenSTL::vector_Vector3d body_collision_points;
300  for (unsigned int i = 0; i < bodies_.getCount(); ++i)
301  {
302  body_spheres.clear();
303  body_collision_points.clear();
304 
305  body_spheres = determineCollisionSpheres(bodies_.getBody(i), relative_cylinder_pose_);
306  collision_spheres_.insert(collision_spheres_.end(), body_spheres.begin(), body_spheres.end());
307 
308  distance_field::findInternalPointsConvex(*bodies_.getBody(i), resolution, body_collision_points);
309  relative_collision_points_.insert(relative_collision_points_.end(), body_collision_points.begin(),
310  body_collision_points.end());
311  }
312 
313  sphere_radii_.resize(collision_spheres_.size());
314  for (unsigned int i = 0; i < collision_spheres_.size(); ++i)
315  {
316  sphere_radii_[i] = collision_spheres_[i].radius_;
317  }
318 
319  // computing bounding sphere
320  std::vector<bodies::BoundingSphere> bounding_spheres(bodies_.getCount());
321  for (unsigned int i = 0; i < bodies_.getCount(); ++i)
322  {
323  bodies_.getBody(i)->computeBoundingSphere(bounding_spheres[i]);
324  }
325  bodies::mergeBoundingSpheres(bounding_spheres, relative_bounding_sphere_);
326 
327  RCLCPP_DEBUG(LOGGER, "BodyDecomposition generated %zu collision spheres out of %zu shapes", collision_spheres_.size(),
328  shapes.size());
329 }
330 
332 {
333  bodies_.clear();
334 }
335 
336 PosedBodyPointDecomposition::PosedBodyPointDecomposition(const BodyDecompositionConstPtr& body_decomposition)
337  : body_decomposition_(body_decomposition)
338 {
339  posed_collision_points_ = body_decomposition_->getCollisionPoints();
340 }
341 
342 PosedBodyPointDecomposition::PosedBodyPointDecomposition(const BodyDecompositionConstPtr& body_decomposition,
343  const Eigen::Isometry3d& trans)
344  : body_decomposition_(body_decomposition)
345 {
346  updatePose(trans);
347 }
348 
349 PosedBodyPointDecomposition::PosedBodyPointDecomposition(const std::shared_ptr<const octomap::OcTree>& octree)
350  : body_decomposition_()
351 {
352  int num_nodes = octree->getNumLeafNodes();
353  posed_collision_points_.reserve(num_nodes);
354  for (octomap::OcTree::tree_iterator tree_iter = octree->begin_tree(); tree_iter != octree->end_tree(); ++tree_iter)
355  {
356  Eigen::Vector3d p = Eigen::Vector3d(tree_iter.getX(), tree_iter.getY(), tree_iter.getZ());
357  posed_collision_points_.push_back(p);
358  }
359 }
360 
361 void PosedBodyPointDecomposition::updatePose(const Eigen::Isometry3d& trans)
362 {
364  {
365  posed_collision_points_.resize(body_decomposition_->getCollisionPoints().size());
366 
367  for (unsigned int i = 0; i < body_decomposition_->getCollisionPoints().size(); ++i)
368  {
369  posed_collision_points_[i] = trans * body_decomposition_->getCollisionPoints()[i];
370  }
371  }
372 }
373 
374 PosedBodySphereDecomposition::PosedBodySphereDecomposition(const BodyDecompositionConstPtr& body_decomposition)
375  : body_decomposition_(body_decomposition)
376 {
377  posed_bounding_sphere_center_ = body_decomposition_->getRelativeBoundingSphere().center;
378  sphere_centers_.resize(body_decomposition_->getCollisionSpheres().size());
379  updatePose(Eigen::Isometry3d::Identity());
380 }
381 
382 void PosedBodySphereDecomposition::updatePose(const Eigen::Isometry3d& trans)
383 {
384  // updating sphere centers
385  posed_bounding_sphere_center_ = trans * body_decomposition_->getRelativeBoundingSphere().center;
386  for (unsigned int i = 0; i < body_decomposition_->getCollisionSpheres().size(); ++i)
387  {
388  sphere_centers_[i] = trans * body_decomposition_->getCollisionSpheres()[i].relative_vec_;
389  }
390 
391  // updating collision points
392  if (!body_decomposition_->getCollisionPoints().empty())
393  {
394  posed_collision_points_.resize(body_decomposition_->getCollisionPoints().size());
395  for (unsigned int i = 0; i < body_decomposition_->getCollisionPoints().size(); ++i)
396  {
397  posed_collision_points_[i] = trans * body_decomposition_->getCollisionPoints()[i];
398  }
399  }
400 }
401 
402 bool doBoundingSpheresIntersect(const PosedBodySphereDecompositionConstPtr& p1,
403  const PosedBodySphereDecompositionConstPtr& p2)
404 {
405  Eigen::Vector3d p1_sphere_center = p1->getBoundingSphereCenter();
406  Eigen::Vector3d p2_sphere_center = p2->getBoundingSphereCenter();
407  double p1_radius = p1->getBoundingSphereRadius();
408  double p2_radius = p2->getBoundingSphereRadius();
409 
410  double dist = (p1_sphere_center - p2_sphere_center).squaredNorm();
411  return dist < (p1_radius + p2_radius);
412 }
413 
414 void getCollisionSphereMarkers(const std_msgs::msg::ColorRGBA& color, const std::string& frame_id,
415  const std::string& ns, const rclcpp::Duration& dur,
416  const std::vector<PosedBodySphereDecompositionPtr>& posed_decompositions,
417  visualization_msgs::msg::MarkerArray& arr)
418 {
419  unsigned int count = 0;
420  rclcpp::Clock ros_clock;
421  for (const auto& posed_decomposition : posed_decompositions)
422  {
423  if (posed_decomposition)
424  {
425  for (unsigned int j = 0; j < posed_decomposition->getCollisionSpheres().size(); ++j)
426  {
427  visualization_msgs::msg::Marker sphere;
428  sphere.type = visualization_msgs::msg::Marker::SPHERE;
429  sphere.header.stamp = ros_clock.now();
430  sphere.header.frame_id = frame_id;
431  sphere.ns = ns;
432  sphere.id = count++;
433  sphere.lifetime = dur;
434  sphere.color = color;
435  sphere.scale.x = sphere.scale.y = sphere.scale.z = posed_decomposition->getCollisionSpheres()[j].radius_ * 2.0;
436  sphere.pose.position.x = posed_decomposition->getSphereCenters()[j].x();
437  sphere.pose.position.y = posed_decomposition->getSphereCenters()[j].y();
438  sphere.pose.position.z = posed_decomposition->getSphereCenters()[j].z();
439  arr.markers.push_back(sphere);
440  }
441  }
442  }
443 }
444 
445 void getProximityGradientMarkers(const std::string& frame_id, const std::string& ns, const rclcpp::Duration& /*dur*/,
446  const std::vector<PosedBodySphereDecompositionPtr>& posed_decompositions,
447  const std::vector<PosedBodySphereDecompositionVectorPtr>& posed_vector_decompositions,
448  const std::vector<GradientInfo>& gradients, visualization_msgs::msg::MarkerArray& arr)
449 {
450  rclcpp::Clock ros_clock;
451  if (gradients.size() != posed_decompositions.size() + posed_vector_decompositions.size())
452  {
453  RCLCPP_WARN(LOGGER, "Size mismatch between gradients %u and decompositions %u", (unsigned int)gradients.size(),
454  (unsigned int)(posed_decompositions.size() + posed_vector_decompositions.size()));
455  return;
456  }
457  for (unsigned int i = 0; i < gradients.size(); ++i)
458  {
459  for (unsigned int j = 0; j < gradients[i].distances.size(); ++j)
460  {
461  visualization_msgs::msg::Marker arrow_mark;
462  arrow_mark.header.frame_id = frame_id;
463  arrow_mark.header.stamp = rclcpp::Clock(RCL_ROS_TIME).now();
464  if (ns.empty())
465  {
466  arrow_mark.ns = "self_coll_gradients";
467  }
468  else
469  {
470  arrow_mark.ns = ns;
471  }
472  arrow_mark.id = i * 1000 + j;
473  double xscale = 0.0;
474  double yscale = 0.0;
475  double zscale = 0.0;
476  if (gradients[i].distances[j] > 0.0 && gradients[i].distances[j] != DBL_MAX)
477  {
478  if (gradients[i].gradients[j].norm() > 0.0)
479  {
480  xscale = gradients[i].gradients[j].x() / gradients[i].gradients[j].norm();
481  yscale = gradients[i].gradients[j].y() / gradients[i].gradients[j].norm();
482  zscale = gradients[i].gradients[j].z() / gradients[i].gradients[j].norm();
483  }
484  else
485  {
486  RCLCPP_DEBUG(LOGGER, "Negative length for %u %d %lf", i, arrow_mark.id, gradients[i].gradients[j].norm());
487  }
488  }
489  else
490  {
491  RCLCPP_DEBUG(LOGGER, "Negative dist %lf for %u %d", gradients[i].distances[j], i, arrow_mark.id);
492  }
493  arrow_mark.points.resize(2);
494  if (i < posed_decompositions.size())
495  {
496  arrow_mark.points[1].x = posed_decompositions[i]->getSphereCenters()[j].x();
497  arrow_mark.points[1].y = posed_decompositions[i]->getSphereCenters()[j].y();
498  arrow_mark.points[1].z = posed_decompositions[i]->getSphereCenters()[j].z();
499  }
500  else
501  {
502  arrow_mark.points[1].x =
503  posed_vector_decompositions[i - posed_decompositions.size()]->getSphereCenters()[j].x();
504  arrow_mark.points[1].y =
505  posed_vector_decompositions[i - posed_decompositions.size()]->getSphereCenters()[j].y();
506  arrow_mark.points[1].z =
507  posed_vector_decompositions[i - posed_decompositions.size()]->getSphereCenters()[j].z();
508  }
509  arrow_mark.points[0] = arrow_mark.points[1];
510  arrow_mark.points[0].x -= xscale * gradients[i].distances[j];
511  arrow_mark.points[0].y -= yscale * gradients[i].distances[j];
512  arrow_mark.points[0].z -= zscale * gradients[i].distances[j];
513  arrow_mark.scale.x = 0.01;
514  arrow_mark.scale.y = 0.03;
515  arrow_mark.color.a = 1.0;
516  if (gradients[i].types[j] == SELF)
517  {
518  arrow_mark.color.r = 1.0;
519  arrow_mark.color.g = 0.2;
520  arrow_mark.color.b = .5;
521  }
522  else if (gradients[i].types[j] == INTRA)
523  {
524  arrow_mark.color.r = .2;
525  arrow_mark.color.g = 1.0;
526  arrow_mark.color.b = .5;
527  }
528  else if (gradients[i].types[j] == ENVIRONMENT)
529  {
530  arrow_mark.color.r = .2;
531  arrow_mark.color.g = .5;
532  arrow_mark.color.b = 1.0;
533  }
534  else if (gradients[i].types[j] == NONE)
535  {
536  arrow_mark.color.r = 1.0;
537  arrow_mark.color.g = .2;
538  arrow_mark.color.b = 1.0;
539  }
540  arr.markers.push_back(arrow_mark);
541  }
542  }
543 }
544 
545 void getCollisionMarkers(const std::string& frame_id, const std::string& ns, const rclcpp::Duration& /*dur*/,
546  const std::vector<PosedBodySphereDecompositionPtr>& posed_decompositions,
547  const std::vector<PosedBodySphereDecompositionVectorPtr>& posed_vector_decompositions,
548  const std::vector<GradientInfo>& gradients, visualization_msgs::msg::MarkerArray& arr)
549 {
550  rclcpp::Clock ros_clock;
551  if (gradients.size() != posed_decompositions.size() + posed_vector_decompositions.size())
552  {
553  RCLCPP_WARN(LOGGER, "Size mismatch between gradients %zu and decompositions %zu", gradients.size(),
554  posed_decompositions.size() + posed_vector_decompositions.size());
555  return;
556  }
557  for (unsigned int i = 0; i < gradients.size(); ++i)
558  {
559  for (unsigned int j = 0; j < gradients[i].types.size(); ++j)
560  {
561  visualization_msgs::msg::Marker sphere_mark;
562  sphere_mark.type = visualization_msgs::msg::Marker::SPHERE;
563  sphere_mark.header.frame_id = frame_id;
564  sphere_mark.header.stamp = rclcpp::Clock(RCL_ROS_TIME).now();
565  if (ns.empty())
566  {
567  sphere_mark.ns = "distance_collisions";
568  }
569  else
570  {
571  sphere_mark.ns = ns;
572  }
573  sphere_mark.id = i * 1000 + j;
574  if (i < posed_decompositions.size())
575  {
576  sphere_mark.scale.x = sphere_mark.scale.y = sphere_mark.scale.z =
577  posed_decompositions[i]->getCollisionSpheres()[j].radius_ * 2.0;
578  sphere_mark.pose.position.x = posed_decompositions[i]->getSphereCenters()[j].x();
579  sphere_mark.pose.position.y = posed_decompositions[i]->getSphereCenters()[j].y();
580  sphere_mark.pose.position.z = posed_decompositions[i]->getSphereCenters()[j].z();
581  }
582  else
583  {
584  sphere_mark.scale.x = sphere_mark.scale.y = sphere_mark.scale.z =
585  posed_vector_decompositions[i - posed_decompositions.size()]->getCollisionSpheres()[j].radius_ * 2.0;
586  sphere_mark.pose.position.x =
587  posed_vector_decompositions[i - posed_decompositions.size()]->getSphereCenters()[j].x();
588  sphere_mark.pose.position.y =
589  posed_vector_decompositions[i - posed_decompositions.size()]->getSphereCenters()[j].y();
590  sphere_mark.pose.position.z =
591  posed_vector_decompositions[i - posed_decompositions.size()]->getSphereCenters()[j].z();
592  }
593  sphere_mark.pose.orientation.w = 1.0;
594  sphere_mark.color.a = 1.0;
595  if (gradients[i].types[j] == SELF)
596  {
597  sphere_mark.color.r = 1.0;
598  sphere_mark.color.g = 0.2;
599  sphere_mark.color.b = .5;
600  }
601  else if (gradients[i].types[j] == INTRA)
602  {
603  sphere_mark.color.r = .2;
604  sphere_mark.color.g = 1.0;
605  sphere_mark.color.b = .5;
606  }
607  else if (gradients[i].types[j] == ENVIRONMENT)
608  {
609  sphere_mark.color.r = .2;
610  sphere_mark.color.g = .5;
611  sphere_mark.color.b = 1.0;
612  }
613  else
614  {
615  sphere_mark.color.r = 1.0;
616  sphere_mark.color.g = .2;
617  sphere_mark.color.b = 1.0;
618  }
619  arr.markers.push_back(sphere_mark);
620  }
621  }
622 }
623 } // namespace collision_detection
624 const rclcpp::Logger collision_detection::PosedBodyPointDecompositionVector::LOGGER = collision_detection::LOGGER;
625 const rclcpp::Logger collision_detection::PosedBodySphereDecompositionVector::LOGGER = collision_detection::LOGGER;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW BodyDecomposition(const shapes::ShapeConstPtr &shape, double resolution, double padding=0.01)
void init(const std::vector< shapes::ShapeConstPtr > &shapes, const EigenSTL::vector_Isometry3d &poses, double resolution, double padding)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW PosedBodyPointDecomposition(const BodyDecompositionConstPtr &body_decomposition)
void updatePose(const Eigen::Isometry3d &linkTransform)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW PosedBodySphereDecomposition(const BodyDecompositionConstPtr &body_decomposition)
void updatePose(const Eigen::Isometry3d &linkTransform)
double getDistanceGradient(double x, double y, double z, double &gradient_x, double &gradient_y, double &gradient_z, bool &in_bounds) const
Gets not only the distance to the nearest cell but the gradient direction. The point defined by the x...
bool getCollisionSphereGradients(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)
DistanceField is an abstract base class for computing distances from sets of 3D obstacle points....
void getProximityGradientMarkers(const std::string &frame_id, const std::string &ns, const rclcpp::Duration &dur, const std::vector< PosedBodySphereDecompositionPtr > &posed_decompositions, const std::vector< PosedBodySphereDecompositionVectorPtr > &posed_vector_decompositions, const std::vector< GradientInfo > &gradients, visualization_msgs::msg::MarkerArray &arr)
std::vector< CollisionSphere > determineCollisionSpheres(const bodies::Body *body, Eigen::Isometry3d &relativeTransform)
void getCollisionMarkers(const std::string &frame_id, const std::string &ns, const rclcpp::Duration &dur, const std::vector< PosedBodySphereDecompositionPtr > &posed_decompositions, const std::vector< PosedBodySphereDecompositionVectorPtr > &posed_vector_decompositions, const std::vector< GradientInfo > &gradients, visualization_msgs::msg::MarkerArray &arr)
void getCollisionSphereMarkers(const std_msgs::msg::ColorRGBA &color, const std::string &frame_id, const std::string &ns, const rclcpp::Duration &dur, const std::vector< PosedBodySphereDecompositionPtr > &posed_decompositions, visualization_msgs::msg::MarkerArray &arr)
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)
bool doBoundingSpheresIntersect(const PosedBodySphereDecompositionConstPtr &p1, const PosedBodySphereDecompositionConstPtr &p2)
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)
Namespace for holding classes that generate distance fields.
void findInternalPointsConvex(const bodies::Body &body, double resolution, EigenSTL::vector_Vector3d &points)
Find all points on a regular grid that are internal to the body, assuming the body is a convex shape....
Vec3fX< details::Vec3Data< double > > Vector3d
Definition: fcl_compat.h:89
frame_id
Definition: pick.py:63
p
Definition: pick.py:62
Definition: world.h:49
EIGEN_MAKE_ALIGNED_OPERATOR_NEW double closest_distance