moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
planning_component.h
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2019, 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: Henning Kayser
36 Desc: API for planning and execution capabilities of a JointModelGroup */
37
38#pragma once
39
40#include <geometry_msgs/msg/pose_stamped.hpp>
49#include <rclcpp/rclcpp.hpp>
50
51namespace moveit_cpp
52{
53MOVEIT_CLASS_FORWARD(PlanningComponent); // Defines PlanningComponentPtr, ConstPtr, WeakPtr... etc
54
56{
57public:
60 {
61 std::string planner_id;
62 std::string planning_pipeline;
67
68 template <typename T>
69 void declareOrGetParam(const rclcpp::Node::SharedPtr& node, const std::string& param_name, T& output_value,
70 T default_value)
71 {
72 // Try to get parameter or use default
73 if (!node->get_parameter_or(param_name, output_value, default_value))
74 {
75 RCLCPP_WARN(node->get_logger(),
76 "Parameter \'%s\' not found in config use default value instead, check parameter type and "
77 "namespace in YAML file",
78 (param_name).c_str());
79 }
80 }
81
82 void load(const rclcpp::Node::SharedPtr& node, const std::string& param_namespace = "")
83 {
84 // Set namespace
85 std::string ns = "plan_request_params.";
86 if (!param_namespace.empty())
87 {
88 ns = param_namespace + ".plan_request_params.";
89 }
90
91 // Declare parameters
92 declareOrGetParam<std::string>(node, ns + "planner_id", planner_id, std::string(""));
93 declareOrGetParam<std::string>(node, ns + "planning_pipeline", planning_pipeline, std::string(""));
94 declareOrGetParam<double>(node, ns + "planning_time", planning_time, 1.0);
95 declareOrGetParam<int>(node, ns + "planning_attempts", planning_attempts, 5);
96 declareOrGetParam<double>(node, ns + "max_velocity_scaling_factor", max_velocity_scaling_factor, 1.0);
97 declareOrGetParam<double>(node, ns + "max_acceleration_scaling_factor", max_acceleration_scaling_factor, 1.0);
98 }
99 };
100
103 {
108 MultiPipelinePlanRequestParameters(const rclcpp::Node::SharedPtr& node,
109 const std::vector<std::string>& planning_pipeline_names)
110 {
111 plan_request_parameter_vector.reserve(planning_pipeline_names.size());
112
113 for (const auto& planning_pipeline_name : planning_pipeline_names)
114 {
115 PlanRequestParameters parameters;
116 parameters.load(node, planning_pipeline_name);
117 plan_request_parameter_vector.push_back(parameters);
118 }
119 }
120
121 // Additional constructor to create an empty MultiPipelinePlanRequestParameters instance
125
126 // Plan request parameters for the individual planning pipelines which run concurrently
127 std::vector<PlanRequestParameters> plan_request_parameter_vector;
128 };
129
131 PlanningComponent(const std::string& group_name, const rclcpp::Node::SharedPtr& node);
132 PlanningComponent(const std::string& group_name, const MoveItCppPtr& moveit_cpp);
133
141
144
147
149 const std::string& getPlanningGroupName() const;
150
152 const std::vector<std::string> getNamedTargetStates();
153
155 std::map<std::string, double> getNamedTargetStateValues(const std::string& name);
156
161 void setWorkspace(double minx, double miny, double minz, double maxx, double maxy, double maxz);
162
164 void unsetWorkspace();
165
167 moveit::core::RobotStatePtr getStartState();
168
170 bool setStartState(const moveit::core::RobotState& start_state);
172 bool setStartState(const std::string& named_state);
173
176
178 bool setGoal(const std::vector<moveit_msgs::msg::Constraints>& goal_constraints);
180 bool setGoal(const moveit::core::RobotState& goal_state);
182 bool setGoal(const geometry_msgs::msg::PoseStamped& goal_pose, const std::string& link_name);
184 bool setGoal(const std::string& named_target);
185
187 bool setPathConstraints(const moveit_msgs::msg::Constraints& path_constraints);
188
190 bool setTrajectoryConstraints(const moveit_msgs::msg::TrajectoryConstraints& trajectory_constraints);
191
198 planning_scene::PlanningScenePtr planning_scene = nullptr);
199
205 const moveit::planning_pipeline_interfaces::SolutionSelectionFunction& solution_selection_function =
207 const moveit::planning_pipeline_interfaces::StoppingCriterionFunction& stopping_criterion_callback = nullptr,
208 planning_scene::PlanningScenePtr planning_scene = nullptr);
209
212 [[deprecated("Use MoveItCpp::execute()")]] bool execute(bool /*blocking */)
213 {
214 return false;
215 };
216
219 ::planning_interface::MotionPlanRequest getMotionPlanRequest(const PlanRequestParameters& plan_request_parameters);
220
223 std::vector<::planning_interface::MotionPlanRequest>
224 getMotionPlanRequestVector(const MultiPipelinePlanRequestParameters& multi_pipeline_plan_request_parameters);
225
226private:
227 // Core properties and instances
228 rclcpp::Node::SharedPtr node_;
229 MoveItCppPtr moveit_cpp_;
230 const std::string group_name_;
231 // The robot_model_ member variable of MoveItCpp class will manually free the joint_model_group_ resources
232 const moveit::core::JointModelGroup* joint_model_group_;
233
234 // Planning
235 // The start state used in the planning motion request
236 moveit::core::RobotStatePtr considered_start_state_;
237 std::vector<moveit_msgs::msg::Constraints> current_goal_constraints_;
238 moveit_msgs::msg::Constraints current_path_constraints_;
239 moveit_msgs::msg::TrajectoryConstraints current_trajectory_constraints_;
240 moveit_msgs::msg::WorkspaceParameters workspace_parameters_;
241 bool workspace_parameters_set_ = false;
242 rclcpp::Logger logger_;
243
244 // common properties for goals
245 // TODO(henningkayser): support goal tolerances
246 // double goal_joint_tolerance_;
247 // double goal_position_tolerance_;
248 // double goal_orientation_tolerance_;
249 // TODO(henningkayser): implement path/trajectory constraints
250 // std::unique_ptr<moveit_msgs::msg::Constraints> path_constraints_;
251 // std::unique_ptr<moveit_msgs::msg::TrajectoryConstraints> trajectory_constraints_;
252};
253} // namespace moveit_cpp
#define MOVEIT_CLASS_FORWARD(C)
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Definition robot_state.h:90
PlanningComponent & operator=(const PlanningComponent &)=delete
void setStartStateToCurrentState()
Set the start state for planning to be the current state of the robot.
bool setStartState(const moveit::core::RobotState &start_state)
Set the robot state that should be considered as start state for planning.
std::map< std::string, double > getNamedTargetStateValues(const std::string &name)
Get the joint values for targets specified by name.
PlanningComponent(PlanningComponent &&other)=delete
planning_interface::MotionPlanResponse plan()
Run a plan from start or current state to fulfill the last goal constraints provided by setGoal() usi...
void unsetWorkspace()
Remove the workspace bounding box from planning.
bool execute(bool)
Execute the latest computed solution trajectory computed by plan(). By default this function terminat...
bool setGoal(const std::vector< moveit_msgs::msg::Constraints > &goal_constraints)
Set the goal constraints used for planning.
~PlanningComponent()=default
Destructor.
const std::string & getPlanningGroupName() const
Get the name of the planning group.
PlanningComponent(const PlanningComponent &)=delete
This class owns unique resources (e.g. action clients, threads) and its not very meaningful to copy....
::planning_interface::MotionPlanRequest getMotionPlanRequest(const PlanRequestParameters &plan_request_parameters)
Utility function to get a MotionPlanRequest from PlanRequestParameters and the internal state of the ...
PlanningComponent & operator=(PlanningComponent &&other)=delete
bool setTrajectoryConstraints(const moveit_msgs::msg::TrajectoryConstraints &trajectory_constraints)
Set the trajectory constraints generated from a moveit msg Constraints.
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....
bool setPathConstraints(const moveit_msgs::msg::Constraints &path_constraints)
Set the path constraints generated from a moveit msg Constraints.
std::vector<::planning_interface::MotionPlanRequest > getMotionPlanRequestVector(const MultiPipelinePlanRequestParameters &multi_pipeline_plan_request_parameters)
Utility function to get a Vector of MotionPlanRequest from a vector of PlanRequestParameters and the ...
const std::vector< std::string > getNamedTargetStates()
Get the names of the named robot states available as targets.
moveit::core::RobotStatePtr getStartState()
Get the considered start state if defined, otherwise get the current state.
std::function< bool(const PlanResponsesContainer &plan_responses_container, const std::vector<::planning_interface::MotionPlanRequest > &plan_requests)> StoppingCriterionFunction
A stopping criterion callback function for the parallel planning API of planning component.
::planning_interface::MotionPlanResponse getShortestSolution(const std::vector<::planning_interface::MotionPlanResponse > &solutions)
Function that returns the shortest solution out of a vector of solutions based on robot_trajectory::p...
std::function<::planning_interface::MotionPlanResponse(const std::vector<::planning_interface::MotionPlanResponse > &solutions)> SolutionSelectionFunction
A solution callback function type for the parallel planning API of planning component.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
This namespace includes the central class for representing planning contexts.
Planner parameters provided with the MotionPlanRequest.
MultiPipelinePlanRequestParameters(const rclcpp::Node::SharedPtr &node, const std::vector< std::string > &planning_pipeline_names)
Planner parameters provided with the MotionPlanRequest.
void load(const rclcpp::Node::SharedPtr &node, const std::string &param_namespace="")
void declareOrGetParam(const rclcpp::Node::SharedPtr &node, const std::string &param_name, T &output_value, T default_value)
Response to a planning query.