planning_component.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2019, PickNik LLC
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 LLC 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: Henning Kayser
36  Desc: API for planning and execution capabilities of a JointModelGroup */
37 
38 #pragma once
39 
40 #include <ros/ros.h>
42 #include <moveit_msgs/MoveItErrorCodes.h>
45 #include <mutex>
46 
47 namespace moveit_cpp
48 {
49 MOVEIT_CLASS_FORWARD(PlanningComponent); // Defines PlanningComponentPtr, ConstPtr, WeakPtr... etc
50 
53 getShortestSolution(std::vector<planning_interface::MotionPlanResponse> const& solutions);
54 
56 {
57 public:
58  using MoveItErrorCode [[deprecated("Use moveit::core::MoveItErrorCode")]] = moveit::core::MoveItErrorCode;
59 
60  class PlanSolutions
61  {
62  public:
64  PlanSolutions(const size_t expected_size = 0)
65  {
66  solutions_.reserve(expected_size);
67  }
68 
73  void pushBack(const planning_interface::MotionPlanResponse& plan_solution)
74  {
75  std::lock_guard<std::mutex> lock_guard(solutions_mutex_);
76  solutions_.push_back(plan_solution);
77  }
78 
80  std::vector<planning_interface::MotionPlanResponse> const& getSolutions() const
81  {
82  return solutions_;
83  }
84 
85  private:
86  std::vector<planning_interface::MotionPlanResponse> solutions_;
87  std::mutex solutions_mutex_;
88  };
89 
91  struct PlanRequestParameters
92  {
93  std::string planner_id;
94  std::string planning_pipeline;
96  double planning_time;
99 
100  void load(const ros::NodeHandle& nh, const std::string& param_namespace = "")
101  {
102  std::string ns = "plan_request_params/";
103  if (!param_namespace.empty())
104  {
105  ns = param_namespace + "/plan_request_params/";
106  }
107 
108  nh.param(ns + "planner_id", planner_id, std::string(""));
109  nh.param(ns + "planning_pipeline", planning_pipeline, std::string(""));
110  nh.param(ns + "planning_time", planning_time, 1.0);
111  nh.param(ns + "planning_attempts", planning_attempts, 5);
112  nh.param(ns + "max_velocity_scaling_factor", max_velocity_scaling_factor, 1.0);
113  nh.param(ns + "max_acceleration_scaling_factor", max_acceleration_scaling_factor, 1.0);
114  }
115  };
116 
119  {
121  const std::vector<std::string>& planning_pipeline_names)
122  {
123  multi_plan_request_parameters.reserve(planning_pipeline_names.size());
124 
125  for (auto const& planning_pipeline_name : planning_pipeline_names)
126  {
128  parameters.load(nh, planning_pipeline_name);
129  multi_plan_request_parameters.push_back(parameters);
130  }
131  }
132  // Plan request parameters for the individual planning pipelines which run concurrently
133  std::vector<PlanRequestParameters> multi_plan_request_parameters;
134  };
135 
137  typedef std::function<planning_interface::MotionPlanResponse(
138  std::vector<planning_interface::MotionPlanResponse> const& solutions)>
141  typedef std::function<bool(PlanSolutions const& solutions,
142  MultiPipelinePlanRequestParameters const& plan_request_parameters)>
144 
146  PlanningComponent(const std::string& group_name, const ros::NodeHandle& nh);
147  PlanningComponent(const std::string& group_name, const MoveItCppPtr& moveit_cpp);
148 
154  PlanningComponent(const PlanningComponent&) = delete;
156 
157  PlanningComponent(PlanningComponent&& other) = default;
158  PlanningComponent& operator=(PlanningComponent&& other) = delete;
159 
162 
164  const std::string& getPlanningGroupName() const;
165 
167  const std::vector<std::string> getNamedTargetStates();
168 
170  std::map<std::string, double> getNamedTargetStateValues(const std::string& name);
171 
176  void setWorkspace(double minx, double miny, double minz, double maxx, double maxy, double maxz);
177 
179  void unsetWorkspace();
180 
182  moveit::core::RobotStatePtr getStartState();
183 
185  bool setStartState(const moveit::core::RobotState& start_state);
187  bool setStartState(const std::string& named_state);
188 
191 
193  bool setGoal(const std::vector<moveit_msgs::Constraints>& goal_constraints);
195  bool setGoal(const moveit::core::RobotState& goal_state);
197  bool setGoal(const geometry_msgs::PoseStamped& goal_pose, const std::string& link_name);
199  bool setGoal(const std::string& named_target);
200 
202  bool setPathConstraints(const moveit_msgs::Constraints& path_constraints);
203 
205  bool setTrajectoryConstraints(const moveit_msgs::TrajectoryConstraints& trajectory_constraints);
206 
212  planning_interface::MotionPlanResponse plan(const PlanRequestParameters& parameters, const bool store_solution = true);
213 
217  plan(const MultiPipelinePlanRequestParameters& parameters,
218  const SolutionCallbackFunction& solution_selection_callback = &getShortestSolution,
219  const StoppingCriterionFunction& stopping_criterion_callback = StoppingCriterionFunction());
220 
223  bool execute(bool blocking = true);
224 
227 
228 private:
229  // Core properties and instances
231  MoveItCppPtr moveit_cpp_;
232  const std::string group_name_;
233  // The robot_model_ member variable of MoveItCpp class will manually free the joint_model_group_ resources
235 
236  // Planning
237  // The start state used in the planning motion request
238  moveit::core::RobotStatePtr considered_start_state_;
239  std::vector<moveit_msgs::Constraints> current_goal_constraints_;
240  moveit_msgs::TrajectoryConstraints current_trajectory_constraints_;
241  moveit_msgs::Constraints current_path_constraints_;
243  moveit_msgs::WorkspaceParameters workspace_parameters_;
244  bool workspace_parameters_set_ = false;
246 
247  // common properties for goals
248  // TODO(henningkayser): support goal tolerances
249  // double goal_joint_tolerance_;
250  // double goal_position_tolerance_;
251  // double goal_orientation_tolerance_;
252  // TODO(henningkayser): implment path/trajectory constraints
253  // std::unique_ptr<moveit_msgs::Constraints> path_constraints_;
254  // std::unique_ptr<moveit_msgs::TrajectoryConstraints> trajectory_constraints_;
255 
257  void clearContents();
258 };
259 } // namespace moveit_cpp
260 
261 namespace moveit
262 {
264 {
265 using PlanningComponent [[deprecated("use moveit_cpp")]] = moveit_cpp::PlanningComponent;
267 } // namespace planning_interface
268 } // namespace moveit
moveit_cpp::PlanningComponent::PlanSolutions::solutions_mutex_
std::mutex solutions_mutex_
Definition: planning_component.h:119
moveit_cpp::PlanningComponent::MoveItErrorCode
moveit::core::MoveItErrorCode MoveItErrorCode
Definition: planning_component.h:90
moveit_cpp::PlanningComponent::PlanSolutions::solutions_
std::vector< planning_interface::MotionPlanResponse > solutions_
Definition: planning_component.h:118
moveit_cpp::PlanningComponent::setStartState
bool setStartState(const moveit::core::RobotState &start_state)
Set the robot state that should be considered as start state for planning.
Definition: planning_component.cpp:334
moveit_cpp::PlanningComponent::MultiPipelinePlanRequestParameters::MultiPipelinePlanRequestParameters
MultiPipelinePlanRequestParameters(const ros::NodeHandle &nh, const std::vector< std::string > &planning_pipeline_names)
Definition: planning_component.h:152
moveit_cpp::PlanningComponent::getLastMotionPlanResponse
planning_interface::MotionPlanResponse const & getLastMotionPlanResponse()
Return the last plan solution.
Definition: planning_component.cpp:446
moveit_cpp::PlanningComponent::PlanRequestParameters::planning_attempts
int planning_attempts
Definition: planning_component.h:127
moveit_cpp::PlanningComponent::MultiPipelinePlanRequestParameters::multi_plan_request_parameters
std::vector< PlanRequestParameters > multi_plan_request_parameters
Definition: planning_component.h:165
moveit_cpp::PlanningComponent::group_name_
const std::string group_name_
Definition: planning_component.h:264
moveit_cpp::PlanningComponent::plan
planning_interface::MotionPlanResponse plan()
Run a plan from start or current state to fulfill the last goal constraints provided by setGoal() usi...
Definition: planning_component.cpp:329
moveit_cpp::PlanningComponent::PlanSolutions::pushBack
void pushBack(const planning_interface::MotionPlanResponse &plan_solution)
Thread safe method to add PlanSolutions to this data structure TODO(sjahr): Refactor this method to a...
Definition: planning_component.h:105
planning_interface::MotionPlanResponse
moveit_cpp::PlanningComponent::setWorkspace
void setWorkspace(double minx, double miny, double minz, double maxx, double maxy, double maxz)
Specify the workspace bounding box. The box is specified in the planning frame (i....
Definition: planning_component.cpp:378
moveit_cpp::PlanningComponent::execute
bool execute(bool blocking=true)
Execute the latest computed solution trajectory computed by plan(). By default this function terminat...
Definition: planning_component.cpp:427
ros.h
moveit_cpp::PlanningComponent::setTrajectoryConstraints
bool setTrajectoryConstraints(const moveit_msgs::TrajectoryConstraints &trajectory_constraints)
Set the trajectory constraints generated from a moveit msg Constraints.
Definition: planning_component.cpp:140
moveit_cpp::PlanningComponent::PlanRequestParameters::max_acceleration_scaling_factor
double max_acceleration_scaling_factor
Definition: planning_component.h:130
moveit_cpp::PlanningComponent::PlanSolutions
Definition: planning_component.h:92
moveit_cpp::PlanningComponent::PlanRequestParameters::load
void load(const ros::NodeHandle &nh, const std::string &param_namespace="")
Definition: planning_component.h:132
moveit_cpp::PlanningComponent::SolutionCallbackFunction
std::function< planning_interface::MotionPlanResponse(std::vector< planning_interface::MotionPlanResponse > const &solutions)> SolutionCallbackFunction
A solution callback function type for the parallel planning API of planning component.
Definition: planning_component.h:171
moveit_cpp::PlanningComponent::unsetWorkspace
void unsetWorkspace()
Remove the workspace bounding box from planning.
Definition: planning_component.cpp:391
moveit_cpp::PlanningComponent
Definition: planning_component.h:87
moveit_cpp::PlanningComponent::getNamedTargetStateValues
std::map< std::string, double > getNamedTargetStateValues(const std::string &name)
Get the joint values for targets specified by name.
Definition: planning_component.cpp:370
moveit::core::RobotState
moveit_cpp::PlanningComponent::clearContents
void clearContents()
Reset all member variables.
Definition: planning_component.cpp:484
moveit_cpp::PlanningComponent::PlanSolutions::getSolutions
std::vector< planning_interface::MotionPlanResponse > const & getSolutions() const
Get solutions.
Definition: planning_component.h:112
moveit_cpp::PlanningComponent::nh_
ros::NodeHandle nh_
Definition: planning_component.h:262
moveit_cpp::PlanningComponent::PlanRequestParameters::planning_pipeline
std::string planning_pipeline
Definition: planning_component.h:126
moveit_cpp::PlanningComponent::moveit_cpp_
MoveItCppPtr moveit_cpp_
Definition: planning_component.h:263
moveit_cpp
Definition: moveit_cpp.h:50
moveit_cpp::PlanningComponent::PlanRequestParameters::planner_id
std::string planner_id
Definition: planning_component.h:125
moveit_cpp::PlanningComponent::current_path_constraints_
moveit_msgs::Constraints current_path_constraints_
Definition: planning_component.h:273
moveit::core::MoveItErrorCode
moveit::planning_interface::MOVEIT_DECLARE_PTR
MOVEIT_DECLARE_PTR(MoveItCpp, moveit_cpp::MoveItCpp)
moveit_cpp::PlanningComponent::PlanRequestParameters
Planner parameters provided with the MotionPlanRequest.
Definition: planning_component.h:123
moveit_cpp::PlanningComponent::PlanRequestParameters::planning_time
double planning_time
Definition: planning_component.h:128
moveit_cpp::PlanningComponent::setStartStateToCurrentState
void setStartStateToCurrentState()
Set the start state for planning to be the current state of the robot.
Definition: planning_component.cpp:365
moveit_cpp::PlanningComponent::getStartState
moveit::core::RobotStatePtr getStartState()
Get the considered start state if defined, otherwise get the current state.
Definition: planning_component.cpp:340
moveit_cpp::PlanningComponent::current_goal_constraints_
std::vector< moveit_msgs::Constraints > current_goal_constraints_
Definition: planning_component.h:271
moveit_cpp::PlanningComponent::MultiPipelinePlanRequestParameters
Planner parameters provided with the MotionPlanRequest.
Definition: planning_component.h:150
moveit_cpp::PlanningComponent::~PlanningComponent
~PlanningComponent()
Destructor.
Definition: planning_component.cpp:108
moveit_cpp::PlanningComponent::PlanRequestParameters::max_velocity_scaling_factor
double max_velocity_scaling_factor
Definition: planning_component.h:129
moveit_cpp.h
planning_pipeline
Planning pipeline.
Definition: planning_pipeline.h:48
moveit_cpp::getShortestSolution
planning_interface::MotionPlanResponse getShortestSolution(std::vector< planning_interface::MotionPlanResponse > const &solutions)
A function to choose the solution with the shortest path from a vector of solutions.
Definition: planning_component.cpp:452
planning_response.h
moveit_cpp::PlanningComponent::joint_model_group_
const moveit::core::JointModelGroup * joint_model_group_
Definition: planning_component.h:266
moveit_cpp::PlanningComponent::workspace_parameters_
moveit_msgs::WorkspaceParameters workspace_parameters_
Definition: planning_component.h:275
moveit
moveit_cpp::PlanningComponent::getPlanningGroupName
const std::string & getPlanningGroupName() const
Get the name of the planning group.
Definition: planning_component.cpp:129
moveit_cpp::PlanningComponent::StoppingCriterionFunction
std::function< bool(PlanSolutions const &solutions, MultiPipelinePlanRequestParameters const &plan_request_parameters)> StoppingCriterionFunction
A stopping criterion callback function for the parallel planning API of planning component.
Definition: planning_component.h:175
moveit_cpp::PlanningComponent::considered_start_state_
moveit::core::RobotStatePtr considered_start_state_
Definition: planning_component.h:270
planning_interface
moveit_cpp::PlanningComponent::setGoal
bool setGoal(const std::vector< moveit_msgs::Constraints > &goal_constraints)
Set the goal constraints used for planning.
Definition: planning_component.cpp:396
moveit_cpp::PlanningComponent::PlanSolutions::PlanSolutions
PlanSolutions(const size_t expected_size=0)
Constructor.
Definition: planning_component.h:96
moveit::core::JointModelGroup
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
moveit_cpp::PlanningComponent::getNamedTargetStates
const std::vector< std::string > getNamedTargetStates()
Get the names of the named robot states available as targets.
Definition: planning_component.cpp:114
moveit_cpp::PlanningComponent::setPathConstraints
bool setPathConstraints(const moveit_msgs::Constraints &path_constraints)
Set the path constraints used for planning.
Definition: planning_component.cpp:134
moveit_cpp::PlanningComponent::current_trajectory_constraints_
moveit_msgs::TrajectoryConstraints current_trajectory_constraints_
Definition: planning_component.h:272
moveit_cpp::PlanningComponent::workspace_parameters_set_
bool workspace_parameters_set_
Definition: planning_component.h:276
moveit_cpp::PlanningComponent::PlanningComponent
PlanningComponent(const std::string &group_name, const ros::NodeHandle &nh)
Constructor.
Definition: planning_component.cpp:103
moveit_cpp::PlanningComponent::last_plan_solution_
planning_interface::MotionPlanResponse last_plan_solution_
Definition: planning_component.h:277
moveit_error_code.h
ros::NodeHandle
moveit::planning_interface::PlanningComponent
moveit_cpp::PlanningComponent PlanningComponent
Definition: planning_component.h:265
moveit_cpp::MOVEIT_CLASS_FORWARD
MOVEIT_CLASS_FORWARD(MoveItCpp)
moveit_cpp::PlanningComponent::plan_request_parameters_
PlanRequestParameters plan_request_parameters_
Definition: planning_component.h:274
moveit_cpp::PlanningComponent::operator=
PlanningComponent & operator=(const PlanningComponent &)=delete


planning
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Thu Apr 18 2024 02:24:19