moveit2
The MoveIt Motion Planning Framework for ROS 2.
planning_scene.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, 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 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: Ioan Sucan, Acorn Pooley */
36 
37 #pragma once
38 
49 #include <moveit_msgs/msg/planning_scene.hpp>
50 #include <moveit_msgs/msg/robot_trajectory.hpp>
51 #include <moveit_msgs/msg/constraints.hpp>
52 #include <moveit_msgs/msg/planning_scene_components.hpp>
53 #include <octomap_msgs/msg/octomap_with_pose.hpp>
54 #include <memory>
55 #include <functional>
56 #include <optional>
57 #include <thread>
58 #include <variant>
59 #include <rclcpp/rclcpp.hpp>
60 
61 #include <moveit_planning_scene_export.h>
62 
64 namespace planning_scene
65 {
66 MOVEIT_CLASS_FORWARD(PlanningScene); // Defines PlanningScenePtr, ConstPtr, WeakPtr... etc
67 
72 typedef std::function<bool(const moveit::core::RobotState&, bool)> StateFeasibilityFn;
73 
79 using MotionFeasibilityFn = std::function<bool(const moveit::core::RobotState&, const moveit::core::RobotState&, bool)>;
80 
82 using ObjectColorMap = std::map<std::string, std_msgs::msg::ColorRGBA>;
83 
85 using ObjectTypeMap = std::map<std::string, object_recognition_msgs::msg::ObjectType>;
86 
90 class MOVEIT_PLANNING_SCENE_EXPORT PlanningScene : public std::enable_shared_from_this<PlanningScene>
91 {
92 public:
96  PlanningScene(const PlanningScene&) = delete;
97 
102 
104  PlanningScene(const moveit::core::RobotModelConstPtr& robot_model,
105  const collision_detection::WorldPtr& world = std::make_shared<collision_detection::World>());
106 
109  PlanningScene(const urdf::ModelInterfaceSharedPtr& urdf_model, const srdf::ModelConstSharedPtr& srdf_model,
110  const collision_detection::WorldPtr& world = std::make_shared<collision_detection::World>());
111 
112  static const std::string OCTOMAP_NS;
113  static const std::string DEFAULT_SCENE_NAME;
114 
115  ~PlanningScene();
116 
118  const std::string& getName() const
119  {
120  return name_;
121  }
122 
124  void setName(const std::string& name)
125  {
126  name_ = name;
127  }
128 
139  PlanningScenePtr diff() const;
140 
143  PlanningScenePtr diff(const moveit_msgs::msg::PlanningScene& msg) const;
144 
146  const PlanningSceneConstPtr& getParent() const
147  {
148  return parent_;
149  }
150 
152  const moveit::core::RobotModelConstPtr& getRobotModel() const
153  {
154  // the kinematic model does not change
155  return robot_model_;
156  }
157 
160  {
161  // if we have an updated state, return it; otherwise, return the parent one
162  return robot_state_ ? *robot_state_ : parent_->getCurrentState();
163  }
165  moveit::core::RobotState& getCurrentStateNonConst();
166 
168  moveit::core::RobotStatePtr getCurrentStateUpdated(const moveit_msgs::msg::RobotState& update) const;
169 
176  const std::string& getPlanningFrame() const
177  {
178  // if we have an updated set of transforms, return it; otherwise, return the parent one
179  return scene_transforms_ ? scene_transforms_->getTargetFrame() : parent_->getPlanningFrame();
180  }
181 
184  {
185  if (scene_transforms_ || !parent_)
186  {
187  return *scene_transforms_;
188  }
189 
190  // if this planning scene is a child of another, and doesn't have its own custom transforms
191  return parent_->getTransforms();
192  }
193 
196  const moveit::core::Transforms& getTransforms();
197 
199  moveit::core::Transforms& getTransformsNonConst();
200 
205  const Eigen::Isometry3d& getFrameTransform(const std::string& id) const;
206 
212  const Eigen::Isometry3d& getFrameTransform(const std::string& id);
213 
219  const Eigen::Isometry3d& getFrameTransform(moveit::core::RobotState& state, const std::string& id) const
220  {
221  state.updateLinkTransforms();
222  return getFrameTransform(static_cast<const moveit::core::RobotState&>(state), id);
223  }
224 
229  const Eigen::Isometry3d& getFrameTransform(const moveit::core::RobotState& state, const std::string& id) const;
230 
233  bool knowsFrameTransform(const std::string& id) const;
234 
237  bool knowsFrameTransform(const moveit::core::RobotState& state, const std::string& id) const;
238 
246  const std::string getCollisionDetectorName() const
247  {
248  // If no collision detector is allocated, return an empty string
249  return collision_detector_ ? (collision_detector_->alloc_->getName()) : "";
250  }
251 
253  const collision_detection::WorldConstPtr& getWorld() const
254  {
255  // we always have a world representation
256  return world_const_;
257  }
258 
260  const collision_detection::WorldPtr& getWorldNonConst()
261  {
262  // we always have a world representation
263  return world_;
264  }
265 
267  const collision_detection::CollisionEnvConstPtr& getCollisionEnv() const
268  {
269  return collision_detector_->getCollisionEnv();
270  }
271 
273  const collision_detection::CollisionEnvConstPtr& getCollisionEnvUnpadded() const
274  {
275  return collision_detector_->getCollisionEnvUnpadded();
276  }
277 
279  const collision_detection::CollisionEnvConstPtr& getCollisionEnv(const std::string& collision_detector_name) const;
280 
283  const collision_detection::CollisionEnvConstPtr&
284  getCollisionEnvUnpadded(const std::string& collision_detector_name) const;
285 
288  const collision_detection::CollisionEnvPtr& getCollisionEnvNonConst();
289 
292  {
293  return acm_ ? *acm_ : parent_->getAllowedCollisionMatrix();
294  }
295 
297  collision_detection::AllowedCollisionMatrix& getAllowedCollisionMatrixNonConst();
298 
300  void setAllowedCollisionMatrix(const collision_detection::AllowedCollisionMatrix& acm);
301 
312  bool isStateColliding(const std::string& group = "", bool verbose = false);
313 
318  bool isStateColliding(const std::string& group = "", bool verbose = false) const
319  {
320  return isStateColliding(getCurrentState(), group, verbose);
321  }
322 
327  bool isStateColliding(moveit::core::RobotState& state, const std::string& group = "", bool verbose = false) const
328  {
330  return isStateColliding(static_cast<const moveit::core::RobotState&>(state), group, verbose);
331  }
332 
336  bool isStateColliding(const moveit::core::RobotState& state, const std::string& group = "",
337  bool verbose = false) const;
338 
341  bool isStateColliding(const moveit_msgs::msg::RobotState& state, const std::string& group = "",
342  bool verbose = false) const;
343 
347 
350  {
351  checkCollision(req, res, getCurrentState());
352  }
353 
357  moveit::core::RobotState& robot_state) const
358  {
359  robot_state.updateCollisionBodyTransforms();
360  checkCollision(req, res, static_cast<const moveit::core::RobotState&>(robot_state));
361  }
362 
367  const moveit::core::RobotState& robot_state) const;
368 
373  moveit::core::RobotState& robot_state,
375  {
376  robot_state.updateCollisionBodyTransforms();
377  checkCollision(req, res, static_cast<const moveit::core::RobotState&>(robot_state), acm);
378  }
379 
383  const moveit::core::RobotState& robot_state,
385 
389  void checkCollisionUnpadded(const collision_detection::CollisionRequest& req,
391 
396  {
397  checkCollisionUnpadded(req, res, getCurrentState(), getAllowedCollisionMatrix());
398  }
399 
404  const moveit::core::RobotState& robot_state) const
405  {
406  checkCollisionUnpadded(req, res, robot_state, getAllowedCollisionMatrix());
407  }
408 
414  {
415  robot_state.updateCollisionBodyTransforms();
416  checkCollisionUnpadded(req, res, static_cast<const moveit::core::RobotState&>(robot_state),
417  getAllowedCollisionMatrix());
418  }
419 
426  {
427  robot_state.updateCollisionBodyTransforms();
428  checkCollisionUnpadded(req, res, static_cast<const moveit::core::RobotState&>(robot_state), acm);
429  }
430 
433  void checkCollisionUnpadded(const collision_detection::CollisionRequest& req,
436 
438  void checkSelfCollision(const collision_detection::CollisionRequest& req, collision_detection::CollisionResult& res);
439 
443  {
444  checkSelfCollision(req, res, getCurrentState());
445  }
446 
449  moveit::core::RobotState& robot_state) const
450  {
451  robot_state.updateCollisionBodyTransforms();
452  checkSelfCollision(req, res, static_cast<const moveit::core::RobotState&>(robot_state), getAllowedCollisionMatrix());
453  }
454 
457  const moveit::core::RobotState& robot_state) const
458  {
459  // do self-collision checking with the unpadded version of the robot
460  getCollisionEnvUnpadded()->checkSelfCollision(req, res, robot_state, getAllowedCollisionMatrix());
461  }
462 
466  moveit::core::RobotState& robot_state,
468  {
469  robot_state.updateCollisionBodyTransforms();
470  checkSelfCollision(req, res, static_cast<const moveit::core::RobotState&>(robot_state), acm);
471  }
472 
476  const moveit::core::RobotState& robot_state,
478  {
479  // do self-collision checking with the unpadded version of the robot
480  getCollisionEnvUnpadded()->checkSelfCollision(req, res, robot_state, acm);
481  }
482 
484  void getCollidingLinks(std::vector<std::string>& links);
485 
487  void getCollidingLinks(std::vector<std::string>& links) const
488  {
489  getCollidingLinks(links, getCurrentState(), getAllowedCollisionMatrix());
490  }
491 
494  void getCollidingLinks(std::vector<std::string>& links, moveit::core::RobotState& robot_state) const
495  {
496  robot_state.updateCollisionBodyTransforms();
497  getCollidingLinks(links, static_cast<const moveit::core::RobotState&>(robot_state), getAllowedCollisionMatrix());
498  }
499 
501  void getCollidingLinks(std::vector<std::string>& links, const moveit::core::RobotState& robot_state) const
502  {
503  getCollidingLinks(links, robot_state, getAllowedCollisionMatrix());
504  }
505 
508  void getCollidingLinks(std::vector<std::string>& links, moveit::core::RobotState& robot_state,
510  {
511  robot_state.updateCollisionBodyTransforms();
512  getCollidingLinks(links, static_cast<const moveit::core::RobotState&>(robot_state), acm);
513  }
514 
517  void getCollidingLinks(std::vector<std::string>& links, const moveit::core::RobotState& robot_state,
519 
522  void getCollidingPairs(collision_detection::CollisionResult::ContactMap& contacts);
523 
526  {
527  getCollidingPairs(contacts, getCurrentState(), getAllowedCollisionMatrix());
528  }
529 
533  const moveit::core::RobotState& robot_state, const std::string& group_name = "") const
534  {
535  getCollidingPairs(contacts, robot_state, getAllowedCollisionMatrix(), group_name);
536  }
537 
542  moveit::core::RobotState& robot_state, const std::string& group_name = "") const
543  {
544  robot_state.updateCollisionBodyTransforms();
545  getCollidingPairs(contacts, static_cast<const moveit::core::RobotState&>(robot_state), getAllowedCollisionMatrix(),
546  group_name);
547  }
548 
554  const std::string& group_name = "") const
555  {
556  robot_state.updateCollisionBodyTransforms();
557  getCollidingPairs(contacts, static_cast<const moveit::core::RobotState&>(robot_state), acm, group_name);
558  }
559 
562  void getCollidingPairs(collision_detection::CollisionResult::ContactMap& contacts,
563  const moveit::core::RobotState& robot_state,
565  const std::string& group_name = "") const;
566 
578  {
579  robot_state.updateCollisionBodyTransforms();
580  return distanceToCollision(static_cast<const moveit::core::RobotState&>(robot_state));
581  }
582 
586  double distanceToCollision(const moveit::core::RobotState& robot_state) const
587  {
588  return getCollisionEnv()->distanceRobot(robot_state, getAllowedCollisionMatrix());
589  }
590 
594  {
595  robot_state.updateCollisionBodyTransforms();
596  return distanceToCollisionUnpadded(static_cast<const moveit::core::RobotState&>(robot_state));
597  }
598 
601  double distanceToCollisionUnpadded(const moveit::core::RobotState& robot_state) const
602  {
603  return getCollisionEnvUnpadded()->distanceRobot(robot_state, getAllowedCollisionMatrix());
604  }
605 
611  {
612  robot_state.updateCollisionBodyTransforms();
613  return distanceToCollision(static_cast<const moveit::core::RobotState&>(robot_state), acm);
614  }
615 
621  {
622  return getCollisionEnv()->distanceRobot(robot_state, acm);
623  }
624 
630  {
631  robot_state.updateCollisionBodyTransforms();
632  return distanceToCollisionUnpadded(static_cast<const moveit::core::RobotState&>(robot_state), acm);
633  }
634 
640  {
641  return getCollisionEnvUnpadded()->distanceRobot(robot_state, acm);
642  }
643 
647  void saveGeometryToStream(std::ostream& out) const;
648 
650  bool loadGeometryFromStream(std::istream& in);
651 
653  bool loadGeometryFromStream(std::istream& in, const Eigen::Isometry3d& offset);
654 
659  void getPlanningSceneDiffMsg(moveit_msgs::msg::PlanningScene& scene) const;
660 
664  void getPlanningSceneMsg(moveit_msgs::msg::PlanningScene& scene) const;
665 
668  void getPlanningSceneMsg(moveit_msgs::msg::PlanningScene& scene,
669  const moveit_msgs::msg::PlanningSceneComponents& comp) const;
670 
673  bool getCollisionObjectMsg(moveit_msgs::msg::CollisionObject& collision_obj, const std::string& ns) const;
674 
677  void getCollisionObjectMsgs(std::vector<moveit_msgs::msg::CollisionObject>& collision_objs) const;
678 
681  bool getAttachedCollisionObjectMsg(moveit_msgs::msg::AttachedCollisionObject& attached_collision_obj,
682  const std::string& ns) const;
683 
686  void
687  getAttachedCollisionObjectMsgs(std::vector<moveit_msgs::msg::AttachedCollisionObject>& attached_collision_objs) const;
688 
690  bool getOctomapMsg(octomap_msgs::msg::OctomapWithPose& octomap) const;
691 
693  void getObjectColorMsgs(std::vector<moveit_msgs::msg::ObjectColor>& object_colors) const;
694 
700  bool setPlanningSceneDiffMsg(const moveit_msgs::msg::PlanningScene& scene);
701 
704  bool setPlanningSceneMsg(const moveit_msgs::msg::PlanningScene& scene);
705 
708  bool usePlanningSceneMsg(const moveit_msgs::msg::PlanningScene& scene);
709 
714  bool shapesAndPosesFromCollisionObjectMessage(const moveit_msgs::msg::CollisionObject& object,
715  Eigen::Isometry3d& object_pose_in_header_frame,
716  std::vector<shapes::ShapeConstPtr>& shapes,
717  EigenSTL::vector_Isometry3d& shape_poses);
718 
719  bool processCollisionObjectMsg(const moveit_msgs::msg::CollisionObject& object);
720  bool processAttachedCollisionObjectMsg(const moveit_msgs::msg::AttachedCollisionObject& object);
721 
722  bool processPlanningSceneWorldMsg(const moveit_msgs::msg::PlanningSceneWorld& world);
723 
724  void processOctomapMsg(const octomap_msgs::msg::OctomapWithPose& map);
725  void processOctomapMsg(const octomap_msgs::msg::Octomap& map);
726  void processOctomapPtr(const std::shared_ptr<const octomap::OcTree>& octree, const Eigen::Isometry3d& t);
727 
731  void removeAllCollisionObjects();
732 
736  void setCurrentState(const moveit_msgs::msg::RobotState& state);
737 
739  void setCurrentState(const moveit::core::RobotState& state);
740 
742  void setAttachedBodyUpdateCallback(const moveit::core::AttachedBodyCallback& callback);
743 
745  void setCollisionObjectUpdateCallback(const collision_detection::World::ObserverCallbackFn& callback);
746 
747  bool hasObjectColor(const std::string& id) const;
748 
754  const std_msgs::msg::ColorRGBA& getObjectColor(const std::string& id) const;
755 
761  std::optional<std_msgs::msg::ColorRGBA> getOriginalObjectColor(const std::string& id) const;
762 
763  void setObjectColor(const std::string& id, const std_msgs::msg::ColorRGBA& color);
764  void removeObjectColor(const std::string& id);
765  void getKnownObjectColors(ObjectColorMap& kc) const;
766 
767  bool hasObjectType(const std::string& id) const;
768 
769  const object_recognition_msgs::msg::ObjectType& getObjectType(const std::string& id) const;
770  void setObjectType(const std::string& id, const object_recognition_msgs::msg::ObjectType& type);
771  void removeObjectType(const std::string& id);
772  void getKnownObjectTypes(ObjectTypeMap& kc) const;
773 
778  void clearDiffs();
779 
783  void pushDiffs(const PlanningScenePtr& scene);
784 
788  void decoupleParent();
789 
794  {
795  state_feasibility_ = fn;
796  }
797 
801  {
802  return state_feasibility_;
803  }
804 
808  {
809  motion_feasibility_ = fn;
810  }
811 
815  {
816  return motion_feasibility_;
817  }
818 
821  bool isStateFeasible(const moveit_msgs::msg::RobotState& state, bool verbose = false) const;
822 
825  bool isStateFeasible(const moveit::core::RobotState& state, bool verbose = false) const;
826 
828  bool isStateConstrained(const moveit_msgs::msg::RobotState& state, const moveit_msgs::msg::Constraints& constr,
829  bool verbose = false) const;
830 
832  bool isStateConstrained(const moveit::core::RobotState& state, const moveit_msgs::msg::Constraints& constr,
833  bool verbose = false) const;
834 
836  bool isStateConstrained(const moveit_msgs::msg::RobotState& state,
837  const kinematic_constraints::KinematicConstraintSet& constr, bool verbose = false) const;
838 
840  bool isStateConstrained(const moveit::core::RobotState& state,
841  const kinematic_constraints::KinematicConstraintSet& constr, bool verbose = false) const;
842 
845  bool isStateValid(const moveit_msgs::msg::RobotState& state, const std::string& group = "",
846  bool verbose = false) const;
847 
850  bool isStateValid(const moveit::core::RobotState& state, const std::string& group = "", bool verbose = false) const;
851 
854  bool isStateValid(const moveit_msgs::msg::RobotState& state, const moveit_msgs::msg::Constraints& constr,
855  const std::string& group = "", bool verbose = false) const;
856 
859  bool isStateValid(const moveit::core::RobotState& state, const moveit_msgs::msg::Constraints& constr,
860  const std::string& group = "", bool verbose = false) const;
861 
864  bool isStateValid(const moveit::core::RobotState& state, const kinematic_constraints::KinematicConstraintSet& constr,
865  const std::string& group = "", bool verbose = false) const;
866 
869  bool isPathValid(const moveit_msgs::msg::RobotState& start_state, const moveit_msgs::msg::RobotTrajectory& trajectory,
870  const std::string& group = "", bool verbose = false,
871  std::vector<std::size_t>* invalid_index = nullptr) const;
872 
876  bool isPathValid(const moveit_msgs::msg::RobotState& start_state, const moveit_msgs::msg::RobotTrajectory& trajectory,
877  const moveit_msgs::msg::Constraints& path_constraints, const std::string& group = "",
878  bool verbose = false, std::vector<std::size_t>* invalid_index = nullptr) const;
879 
883  bool isPathValid(const moveit_msgs::msg::RobotState& start_state, const moveit_msgs::msg::RobotTrajectory& trajectory,
884  const moveit_msgs::msg::Constraints& path_constraints,
885  const moveit_msgs::msg::Constraints& goal_constraints, const std::string& group = "",
886  bool verbose = false, std::vector<std::size_t>* invalid_index = nullptr) const;
887 
891  bool isPathValid(const moveit_msgs::msg::RobotState& start_state, const moveit_msgs::msg::RobotTrajectory& trajectory,
892  const moveit_msgs::msg::Constraints& path_constraints,
893  const std::vector<moveit_msgs::msg::Constraints>& goal_constraints, const std::string& group = "",
894  bool verbose = false, std::vector<std::size_t>* invalid_index = nullptr) const;
895 
899  bool isPathValid(const robot_trajectory::RobotTrajectory& trajectory,
900  const moveit_msgs::msg::Constraints& path_constraints,
901  const std::vector<moveit_msgs::msg::Constraints>& goal_constraints, const std::string& group = "",
902  bool verbose = false, std::vector<std::size_t>* invalid_index = nullptr) const;
903 
907  bool isPathValid(const robot_trajectory::RobotTrajectory& trajectory,
908  const moveit_msgs::msg::Constraints& path_constraints,
909  const moveit_msgs::msg::Constraints& goal_constraints, const std::string& group = "",
910  bool verbose = false, std::vector<std::size_t>* invalid_index = nullptr) const;
911 
914  bool isPathValid(const robot_trajectory::RobotTrajectory& trajectory,
915  const moveit_msgs::msg::Constraints& path_constraints, const std::string& group = "",
916  bool verbose = false, std::vector<std::size_t>* invalid_index = nullptr) const;
917 
920  bool isPathValid(const robot_trajectory::RobotTrajectory& trajectory, const std::string& group = "",
921  bool verbose = false, std::vector<std::size_t>* invalid_index = nullptr) const;
922 
925  void getCostSources(const robot_trajectory::RobotTrajectory& trajectory, std::size_t max_costs,
926  std::set<collision_detection::CostSource>& costs, double overlap_fraction = 0.9) const;
927 
930  void getCostSources(const robot_trajectory::RobotTrajectory& trajectory, std::size_t max_costs,
931  const std::string& group_name, std::set<collision_detection::CostSource>& costs,
932  double overlap_fraction = 0.9) const;
933 
935  void getCostSources(const moveit::core::RobotState& state, std::size_t max_costs,
936  std::set<collision_detection::CostSource>& costs) const;
937 
940  void getCostSources(const moveit::core::RobotState& state, std::size_t max_costs, const std::string& group_name,
941  std::set<collision_detection::CostSource>& costs) const;
942 
944  void printKnownObjects(std::ostream& out = std::cout) const;
945 
947  static PlanningScenePtr clone(const PlanningSceneConstPtr& scene);
948 
962  void allocateCollisionDetector(const collision_detection::CollisionDetectorAllocatorPtr& allocator)
963  {
964  allocateCollisionDetector(allocator, nullptr /* no parent_detector */);
965  }
966 
967 private:
968  /* Private constructor used by the diff() methods. */
969  PlanningScene(const PlanningSceneConstPtr& parent);
970 
971  /* Initialize the scene. This should only be called by the constructors.
972  * Requires a valid robot_model_ */
973  void initialize();
974 
975  /* Helper functions for processing collision objects */
976  bool processCollisionObjectAdd(const moveit_msgs::msg::CollisionObject& object);
977  bool processCollisionObjectRemove(const moveit_msgs::msg::CollisionObject& object);
978  bool processCollisionObjectMove(const moveit_msgs::msg::CollisionObject& object);
979 
981 
982  /* Construct a new CollisionDector from allocator, copy-construct environments from parent_detector if not nullptr */
983  void allocateCollisionDetector(const collision_detection::CollisionDetectorAllocatorPtr& allocator,
984  const CollisionDetectorPtr& parent_detector);
985 
986  /* \brief A set of compatible collision detectors */
987  struct CollisionDetector
988  {
989  collision_detection::CollisionDetectorAllocatorPtr alloc_;
990  collision_detection::CollisionEnvPtr cenv_; // never nullptr
991  collision_detection::CollisionEnvConstPtr cenv_const_;
992 
993  collision_detection::CollisionEnvPtr cenv_unpadded_;
994  collision_detection::CollisionEnvConstPtr cenv_unpadded_const_;
995 
996  const collision_detection::CollisionEnvConstPtr& getCollisionEnv() const
997  {
998  return cenv_const_;
999  }
1000  const collision_detection::CollisionEnvConstPtr& getCollisionEnvUnpadded() const
1001  {
1002  return cenv_unpadded_const_;
1003  }
1004  void copyPadding(const CollisionDetector& src);
1005  };
1006  friend struct CollisionDetector;
1007 
1008  std::string name_; // may be empty
1009 
1010  PlanningSceneConstPtr parent_; // Null unless this is a diff scene
1011 
1012  moveit::core::RobotModelConstPtr robot_model_; // Never null (may point to same model as parent)
1013 
1014  moveit::core::RobotStatePtr robot_state_; // if nullptr use parent's
1015 
1016  // Called when changes are made to attached bodies
1017  moveit::core::AttachedBodyCallback current_state_attached_body_callback_;
1018 
1019  // This variable is not necessarily used by child planning scenes
1020  // This Transforms class is actually a SceneTransforms class
1021  moveit::core::TransformsPtr scene_transforms_; // if nullptr use parent's
1022 
1023  collision_detection::WorldPtr world_; // never nullptr, never shared with parent/child
1024  collision_detection::WorldConstPtr world_const_; // copy of world_
1025  collision_detection::WorldDiffPtr world_diff_; // nullptr unless this is a diff scene
1026  collision_detection::World::ObserverCallbackFn current_world_object_update_callback_;
1027  collision_detection::World::ObserverHandle current_world_object_update_observer_handle_;
1028 
1029  CollisionDetectorPtr collision_detector_; // Never nullptr.
1030 
1031  collision_detection::AllowedCollisionMatrixPtr acm_; // if nullptr use parent's
1032 
1033  StateFeasibilityFn state_feasibility_;
1034  MotionFeasibilityFn motion_feasibility_;
1035 
1036  // Maps of current and original object colors (to manage attaching/detaching objects)
1037  std::unique_ptr<ObjectColorMap> object_colors_;
1038  std::unique_ptr<ObjectColorMap> original_object_colors_;
1039 
1040  // a map of object types
1041  std::unique_ptr<ObjectTypeMap> object_types_;
1042 };
1043 } // namespace planning_scene
#define MOVEIT_STRUCT_FORWARD(C)
Definition: class_forward.h:55
Definition of a structure for the allowed collision matrix. All elements in the collision world are r...
std::function< void(const ObjectConstPtr &, Action)> ObserverCallbackFn
Definition: world.h:301
A class that contains many different constraints, and can check RobotState *versus the full set....
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Definition: robot_state.h:90
void updateLinkTransforms()
Update the reference frame transforms for links. This call is needed before using the transforms of l...
void updateCollisionBodyTransforms()
Update the transforms for the collision bodies. This call is needed before calling collision checking...
Provides an implementation of a snapshot of a transform tree that can be easily queried for transform...
Definition: transforms.h:59
This class maintains the representation of the environment as seen by a planning instance....
void checkSelfCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res) const
Check whether the current state is in self collision.
void setName(const std::string &name)
Set the name of the planning scene.
double distanceToCollisionUnpadded(const moveit::core::RobotState &robot_state) const
The distance between the robot model at state robot_state to the nearest collision (ignoring self-col...
void checkSelfCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm) const
Check whether a specified state (robot_state) is in self collision, with respect to a given allowed c...
double distanceToCollision(moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm) const
The distance between the robot model at state robot_state to the nearest collision,...
void getCollidingPairs(collision_detection::CollisionResult::ContactMap &contacts) const
Get the names of the links that are involved in collisions for the current state.
void getCollidingPairs(collision_detection::CollisionResult::ContactMap &contacts, moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm, const std::string &group_name="") const
Get the names of the links that are involved in collisions for the state robot_state given the allowe...
double distanceToCollision(moveit::core::RobotState &robot_state) const
The distance between the robot model at state robot_state to the nearest collision (ignoring self-col...
bool isStateColliding(moveit::core::RobotState &state, const std::string &group="", bool verbose=false) const
Check if a given state is in collision (with the environment or self collision) If a group name is sp...
const std::string & getName() const
Get the name of the planning scene. This is empty by default.
const std::string & getPlanningFrame() const
Get the frame in which planning is performed.
void getCollidingLinks(std::vector< std::string > &links, const moveit::core::RobotState &robot_state) const
Get the names of the links that are involved in collisions for the state robot_state.
const MotionFeasibilityFn & getMotionFeasibilityPredicate() const
Get the predicate that decides whether motion segments are considered valid or invalid for reasons be...
void getCollidingPairs(collision_detection::CollisionResult::ContactMap &contacts, const moveit::core::RobotState &robot_state, const std::string &group_name="") const
Get the names of the links that are involved in collisions for the state robot_state....
void setMotionFeasibilityPredicate(const MotionFeasibilityFn &fn)
Specify a predicate that decides whether motion segments are considered valid or invalid for reasons ...
void checkCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm) const
Check whether a specified state (robot_state) is in collision, with respect to a given allowed collis...
const collision_detection::CollisionEnvConstPtr & getCollisionEnvUnpadded() const
Get the active collision detector for the robot.
void getCollidingLinks(std::vector< std::string > &links, moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm) const
Get the names of the links that are involved in collisions for the state robot_state given the allowe...
void checkCollisionUnpadded(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res) const
Check whether the current state is in collision, but use a collision_detection::CollisionRobot instan...
const collision_detection::AllowedCollisionMatrix & getAllowedCollisionMatrix() const
Get the allowed collision matrix.
PlanningScene(const PlanningScene &)=delete
PlanningScene cannot be copy-constructed.
double distanceToCollisionUnpadded(moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm) const
The distance between the robot model at state robot_state to the nearest collision,...
double distanceToCollision(const moveit::core::RobotState &robot_state) const
The distance between the robot model at state robot_state to the nearest collision (ignoring self-col...
const std::string getCollisionDetectorName() const
void getCollidingPairs(collision_detection::CollisionResult::ContactMap &contacts, moveit::core::RobotState &robot_state, const std::string &group_name="") const
Get the names of the links that are involved in collisions for the state robot_state....
PlanningScene & operator=(const PlanningScene &)=delete
PlanningScene cannot be copy-assigned.
void checkCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, moveit::core::RobotState &robot_state) const
Check whether a specified state (robot_state) is in collision. This variant of the function takes a n...
void getCollidingLinks(std::vector< std::string > &links) const
Get the names of the links that are involved in collisions for the current state.
const StateFeasibilityFn & getStateFeasibilityPredicate() const
Get the predicate that decides whether states are considered valid or invalid for reasons beyond ones...
void getCollidingLinks(std::vector< std::string > &links, moveit::core::RobotState &robot_state) const
Get the names of the links that are involved in collisions for the state robot_state....
void allocateCollisionDetector(const collision_detection::CollisionDetectorAllocatorPtr &allocator)
Allocate a new collision detector and replace the previous one if there was any.
void checkSelfCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &robot_state) const
Check whether a specified state (robot_state) is in self collision.
double distanceToCollisionUnpadded(const moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm) const
The distance between the robot model at state robot_state to the nearest collision,...
const Eigen::Isometry3d & getFrameTransform(moveit::core::RobotState &state, const std::string &id) const
Get the transform corresponding to the frame id. This will be known if id is a link name,...
void checkCollisionUnpadded(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm) const
Check whether a specified state (robot_state) is in collision, with respect to a given allowed collis...
double distanceToCollision(const moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm) const
The distance between the robot model at state robot_state to the nearest collision,...
const moveit::core::RobotState & getCurrentState() const
Get the state at which the robot is assumed to be.
bool isStateColliding(const std::string &group="", bool verbose=false) const
Check if the current state is in collision (with the environment or self collision)....
void checkCollisionUnpadded(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, moveit::core::RobotState &robot_state) const
Check whether a specified state (robot_state) is in collision, but use a collision_detection::Collisi...
const collision_detection::WorldConstPtr & getWorld() const
Get the representation of the world.
const moveit::core::Transforms & getTransforms() const
Get the set of fixed transforms from known frames to the planning frame.
const collision_detection::WorldPtr & getWorldNonConst()
Get the representation of the world.
void checkCollisionUnpadded(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &robot_state) const
Check whether a specified state (robot_state) is in collision, but use a collision_detection::Collisi...
const PlanningSceneConstPtr & getParent() const
Get the parent scene (with respect to which the diffs are maintained). This may be empty.
void checkSelfCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, const moveit::core::RobotState &robot_state, const collision_detection::AllowedCollisionMatrix &acm) const
Check whether a specified state (robot_state) is in self collision, with respect to a given allowed c...
const moveit::core::RobotModelConstPtr & getRobotModel() const
Get the kinematic model for which the planning scene is maintained.
void checkCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res) const
Check whether the current state is in collision. The current state is expected to be updated.
void setStateFeasibilityPredicate(const StateFeasibilityFn &fn)
Specify a predicate that decides whether states are considered valid or invalid for reasons beyond on...
double distanceToCollisionUnpadded(moveit::core::RobotState &robot_state) const
The distance between the robot model at state robot_state to the nearest collision (ignoring self-col...
const collision_detection::CollisionEnvConstPtr & getCollisionEnv() const
Get the active collision environment.
static const std::string OCTOMAP_NS
static const std::string DEFAULT_SCENE_NAME
void checkSelfCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res, moveit::core::RobotState &robot_state) const
Check whether a specified state (robot_state) is in self collision.
Maintain a sequence of waypoints and the time durations between these waypoints.
CollisionDetector
Enumerates the available collision detectors.
std::function< void(AttachedBody *body, bool attached)> AttachedBodyCallback
Definition: attached_body.h:51
bool processAttachedCollisionObjectMsg(const planning_scene_monitor::PlanningSceneMonitorPtr &planning_scene_monitor, moveit_msgs::msg::AttachedCollisionObject &attached_collision_object_msg)
Eigen::MatrixXd getFrameTransform(std::shared_ptr< planning_scene::PlanningScene > &planning_scene, const std::string &id)
moveit_msgs::msg::PlanningScene getPlanningSceneMsg(std::shared_ptr< planning_scene::PlanningScene > &planning_scene)
void update(moveit::core::RobotState *self, bool force, std::string &category)
Definition: robot_state.cpp:47
bool isStateColliding(const bool test_for_self_collision, const planning_scene::PlanningSceneConstPtr &scene, moveit::core::RobotState *state, const moveit::core::JointModelGroup *const group, const double *const ik_solution)
Checks if current robot state is in self collision.
This namespace includes the central class for representing planning contexts.
std::function< bool(const moveit::core::RobotState &, bool)> StateFeasibilityFn
This is the function signature for additional feasibility checks to be imposed on states (in addition...
std::map< std::string, std_msgs::msg::ColorRGBA > ObjectColorMap
A map from object names (e.g., attached bodies, collision objects) to their colors.
std::function< bool(const moveit::core::RobotState &, const moveit::core::RobotState &, bool)> MotionFeasibilityFn
This is the function signature for additional feasibility checks to be imposed on motions segments be...
MOVEIT_CLASS_FORWARD(PlanningScene)
std::map< std::string, object_recognition_msgs::msg::ObjectType > ObjectTypeMap
A map from object names (e.g., attached bodies, collision objects) to their types.
name
Definition: setup.py:7
Definition: world.h:49
Representation of a collision checking request.
Representation of a collision checking result.
std::map< std::pair< std::string, std::string >, std::vector< Contact > > ContactMap
A map returning the pairs of body ids in contact, plus their contact details.