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>
59 #include <rclcpp/rclcpp.hpp>
61 #include <moveit_planning_scene_export.h>
85 using ObjectTypeMap = std::map<std::string, object_recognition_msgs::msg::ObjectType>;
90 class MOVEIT_PLANNING_SCENE_EXPORT
PlanningScene :
public std::enable_shared_from_this<PlanningScene>
104 PlanningScene(
const moveit::core::RobotModelConstPtr& robot_model,
105 const collision_detection::WorldPtr& world = std::make_shared<collision_detection::World>());
109 PlanningScene(
const urdf::ModelInterfaceSharedPtr& urdf_model,
const srdf::ModelConstSharedPtr& srdf_model,
110 const collision_detection::WorldPtr& world = std::make_shared<collision_detection::World>());
139 PlanningScenePtr diff()
const;
143 PlanningScenePtr diff(
const moveit_msgs::msg::PlanningScene& msg)
const;
162 return robot_state_ ? *robot_state_ : parent_->getCurrentState();
168 moveit::core::RobotStatePtr getCurrentStateUpdated(
const moveit_msgs::msg::RobotState&
update)
const;
179 return scene_transforms_ ? scene_transforms_->getTargetFrame() : parent_->getPlanningFrame();
185 if (scene_transforms_ || !parent_)
187 return *scene_transforms_;
191 return parent_->getTransforms();
233 bool knowsFrameTransform(
const std::string&
id)
const;
249 return collision_detector_ ? (collision_detector_->alloc_->getName()) :
"";
253 const collision_detection::WorldConstPtr&
getWorld()
const
269 return collision_detector_->getCollisionEnv();
275 return collision_detector_->getCollisionEnvUnpadded();
279 const collision_detection::CollisionEnvConstPtr& getCollisionEnv(
const std::string& collision_detector_name)
const;
283 const collision_detection::CollisionEnvConstPtr&
284 getCollisionEnvUnpadded(
const std::string& collision_detector_name)
const;
288 const collision_detection::CollisionEnvPtr& getCollisionEnvNonConst();
293 return acm_ ? *acm_ : parent_->getAllowedCollisionMatrix();
337 bool verbose =
false)
const;
341 bool isStateColliding(
const moveit_msgs::msg::RobotState& state,
const std::string& group =
"",
342 bool verbose =
false)
const;
351 checkCollision(req, res, getCurrentState());
397 checkCollisionUnpadded(req, res, getCurrentState(), getAllowedCollisionMatrix());
406 checkCollisionUnpadded(req, res, robot_state, getAllowedCollisionMatrix());
417 getAllowedCollisionMatrix());
444 checkSelfCollision(req, res, getCurrentState());
452 checkSelfCollision(req, res,
static_cast<const moveit::core::RobotState&
>(robot_state), getAllowedCollisionMatrix());
460 getCollisionEnvUnpadded()->checkSelfCollision(req, res, robot_state, getAllowedCollisionMatrix());
480 getCollisionEnvUnpadded()->checkSelfCollision(req, res, robot_state, acm);
484 void getCollidingLinks(std::vector<std::string>& links);
489 getCollidingLinks(links, getCurrentState(), getAllowedCollisionMatrix());
503 getCollidingLinks(links, robot_state, getAllowedCollisionMatrix());
527 getCollidingPairs(contacts, getCurrentState(), getAllowedCollisionMatrix());
535 getCollidingPairs(contacts, robot_state, getAllowedCollisionMatrix(), group_name);
554 const std::string& group_name =
"")
const
565 const std::string& group_name =
"")
const;
588 return getCollisionEnv()->distanceRobot(robot_state, getAllowedCollisionMatrix());
603 return getCollisionEnvUnpadded()->distanceRobot(robot_state, getAllowedCollisionMatrix());
622 return getCollisionEnv()->distanceRobot(robot_state, acm);
641 return getCollisionEnvUnpadded()->distanceRobot(robot_state, acm);
647 void saveGeometryToStream(std::ostream& out)
const;
650 bool loadGeometryFromStream(std::istream& in);
653 bool loadGeometryFromStream(std::istream& in,
const Eigen::Isometry3d& offset);
659 void getPlanningSceneDiffMsg(moveit_msgs::msg::PlanningScene& scene)
const;
669 const moveit_msgs::msg::PlanningSceneComponents& comp)
const;
673 bool getCollisionObjectMsg(moveit_msgs::msg::CollisionObject& collision_obj,
const std::string& ns)
const;
677 void getCollisionObjectMsgs(std::vector<moveit_msgs::msg::CollisionObject>& collision_objs)
const;
681 bool getAttachedCollisionObjectMsg(moveit_msgs::msg::AttachedCollisionObject& attached_collision_obj,
682 const std::string& ns)
const;
687 getAttachedCollisionObjectMsgs(std::vector<moveit_msgs::msg::AttachedCollisionObject>& attached_collision_objs)
const;
690 bool getOctomapMsg(octomap_msgs::msg::OctomapWithPose&
octomap)
const;
693 void getObjectColorMsgs(std::vector<moveit_msgs::msg::ObjectColor>& object_colors)
const;
700 bool setPlanningSceneDiffMsg(
const moveit_msgs::msg::PlanningScene& scene);
704 bool setPlanningSceneMsg(
const moveit_msgs::msg::PlanningScene& scene);
708 bool usePlanningSceneMsg(
const moveit_msgs::msg::PlanningScene& scene);
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);
719 bool processCollisionObjectMsg(
const moveit_msgs::msg::CollisionObject&
object);
722 bool processPlanningSceneWorldMsg(
const moveit_msgs::msg::PlanningSceneWorld& world);
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);
731 void removeAllCollisionObjects();
736 void setCurrentState(
const moveit_msgs::msg::RobotState& state);
747 bool hasObjectColor(
const std::string&
id)
const;
754 const std_msgs::msg::ColorRGBA& getObjectColor(
const std::string&
id)
const;
761 std::optional<std_msgs::msg::ColorRGBA> getOriginalObjectColor(
const std::string&
id)
const;
763 void setObjectColor(
const std::string&
id,
const std_msgs::msg::ColorRGBA& color);
764 void removeObjectColor(
const std::string&
id);
767 bool hasObjectType(
const std::string&
id)
const;
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);
783 void pushDiffs(
const PlanningScenePtr& scene);
788 void decoupleParent();
795 state_feasibility_ = fn;
802 return state_feasibility_;
809 motion_feasibility_ = fn;
816 return motion_feasibility_;
821 bool isStateFeasible(
const moveit_msgs::msg::RobotState& state,
bool verbose =
false)
const;
828 bool isStateConstrained(
const moveit_msgs::msg::RobotState& state,
const moveit_msgs::msg::Constraints& constr,
829 bool verbose =
false)
const;
833 bool verbose =
false)
const;
836 bool isStateConstrained(
const moveit_msgs::msg::RobotState& state,
845 bool isStateValid(
const moveit_msgs::msg::RobotState& state,
const std::string& group =
"",
846 bool verbose =
false)
const;
850 bool isStateValid(
const moveit::core::RobotState& state,
const std::string& group =
"",
bool verbose =
false)
const;
854 bool isStateValid(
const moveit_msgs::msg::RobotState& state,
const moveit_msgs::msg::Constraints& constr,
855 const std::string& group =
"",
bool verbose =
false)
const;
860 const std::string& group =
"",
bool verbose =
false)
const;
865 const std::string& group =
"",
bool verbose =
false)
const;
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;
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;
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;
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;
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;
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;
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;
921 bool verbose =
false, std::vector<std::size_t>* invalid_index =
nullptr)
const;
926 std::set<collision_detection::CostSource>& costs,
double overlap_fraction = 0.9)
const;
931 const std::string& group_name, std::set<collision_detection::CostSource>& costs,
932 double overlap_fraction = 0.9)
const;
936 std::set<collision_detection::CostSource>& costs)
const;
941 std::set<collision_detection::CostSource>& costs)
const;
944 void printKnownObjects(std::ostream& out = std::cout)
const;
947 static PlanningScenePtr clone(
const PlanningSceneConstPtr& scene);
964 allocateCollisionDetector(allocator,
nullptr );
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);
983 void allocateCollisionDetector(
const collision_detection::CollisionDetectorAllocatorPtr& allocator,
984 const CollisionDetectorPtr& parent_detector);
989 collision_detection::CollisionDetectorAllocatorPtr alloc_;
990 collision_detection::CollisionEnvPtr cenv_;
991 collision_detection::CollisionEnvConstPtr cenv_const_;
993 collision_detection::CollisionEnvPtr cenv_unpadded_;
994 collision_detection::CollisionEnvConstPtr cenv_unpadded_const_;
996 const collision_detection::CollisionEnvConstPtr& getCollisionEnv()
const
1000 const collision_detection::CollisionEnvConstPtr& getCollisionEnvUnpadded()
const
1002 return cenv_unpadded_const_;
1010 PlanningSceneConstPtr parent_;
1012 moveit::core::RobotModelConstPtr robot_model_;
1014 moveit::core::RobotStatePtr robot_state_;
1021 moveit::core::TransformsPtr scene_transforms_;
1023 collision_detection::WorldPtr world_;
1024 collision_detection::WorldConstPtr world_const_;
1025 collision_detection::WorldDiffPtr world_diff_;
1029 CollisionDetectorPtr collision_detector_;
1031 collision_detection::AllowedCollisionMatrixPtr acm_;
1037 std::unique_ptr<ObjectColorMap> object_colors_;
1038 std::unique_ptr<ObjectColorMap> original_object_colors_;
1041 std::unique_ptr<ObjectTypeMap> object_types_;
#define MOVEIT_STRUCT_FORWARD(C)
Definition of a structure for the allowed collision matrix. All elements in the collision world are r...
std::function< void(const ObjectConstPtr &, Action)> ObserverCallbackFn
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.
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...
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
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)
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.
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.