moveit2
The MoveIt Motion Planning Framework for ROS 2.
check_for_stacked_constraints.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2023, PickNik 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 PickNik Inc. 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: Felix von Drigalski, Sebastian Jahr
36  * Desc: A planning request adapter that checks if the motion plan request contains stacked path or goal constraints. If
37  * that is the case, a warning is created but the planning process is not interrupted.
38  */
39 
41 #include <class_loader/class_loader.hpp>
42 #include <rclcpp/logging.hpp>
43 #include <rclcpp/node.hpp>
44 #include <moveit/utils/logger.hpp>
45 
46 #include <default_request_adapter_parameters.hpp>
47 
49 {
50 
53 {
54 public:
55  CheckForStackedConstraints() : logger_(moveit::getLogger("check_for_stacked_constraints"))
56  {
57  }
58 
59  [[nodiscard]] std::string getDescription() const override
60  {
61  return std::string("CheckForStackedConstraints");
62  }
63 
64  [[nodiscard]] moveit::core::MoveItErrorCode adapt(const planning_scene::PlanningSceneConstPtr& /*planning_scene*/,
65  planning_interface::MotionPlanRequest& req) const override
66  {
67  // This should alert the user if planning failed because of contradicting constraints.
68  // Could be checked more thoroughly, but it is probably not worth going to that length.
69  if (req.path_constraints.position_constraints.size() > 1 || req.path_constraints.orientation_constraints.size() > 1)
70  {
71  RCLCPP_WARN(logger_, "More than one PATH constraint is set. If your planning group does not have multiple end "
72  "effectors/arms, this is "
73  "unusual. Are you using a move_group_interface and forgetting to call clearPoseTargets() or "
74  "equivalent?");
75  }
76  for (const auto& constraint : req.goal_constraints)
77  {
78  if (constraint.position_constraints.size() > 1 || constraint.orientation_constraints.size() > 1)
79  {
80  RCLCPP_WARN(logger_,
81  "More than one GOAL constraint is set. If your move_group does not have multiple end "
82  "effectors/arms, this is "
83  "unusual. Are you using a move_group_interface and forgetting to call clearPoseTargets() or "
84  "equivalent?");
85  break;
86  }
87  }
88  return moveit::core::MoveItErrorCode(moveit_msgs::msg::MoveItErrorCodes::SUCCESS, std::string(""), getDescription());
89  }
90 
91 private:
92  std::unique_ptr<default_request_adapter_parameters::ParamListener> param_listener_;
93  rclcpp::Logger logger_;
94 };
95 } // namespace default_planning_request_adapters
96 
Check if the motion plan request contains stacked path or goal constraints.
moveit::core::MoveItErrorCode adapt(const planning_scene::PlanningSceneConstPtr &, planning_interface::MotionPlanRequest &req) const override
Adapt the planning request.
std::string getDescription() const override
Get a description of this adapter.
a wrapper around moveit_msgs::MoveItErrorCodes to make it easier to return an error code message from...
Concept in MoveIt which can be used to modify the planning problem(pre-processing) in a planning pipe...
Main namespace for MoveIt.
Definition: exceptions.h:43
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
CLASS_LOADER_REGISTER_CLASS(default_planning_request_adapters::ResolveConstraintFrames, planning_interface::PlanningRequestAdapter)