moveit2
The MoveIt Motion Planning Framework for ROS 2.
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 <rclcpp/rclcpp.hpp>
43 #include <geometry_msgs/msg/pose_stamped.hpp>
46 
47 namespace moveit_cpp
48 {
49 MOVEIT_CLASS_FORWARD(PlanningComponent); // Defines PlanningComponentPtr, ConstPtr, WeakPtr... etc
50 
52 {
53 public:
55 
56  using MoveItErrorCode [[deprecated("Use moveit::core::MoveItErrorCode")]] = moveit::core::MoveItErrorCode;
57 
59  struct PlanSolution
60  {
62  moveit_msgs::msg::RobotState start_state;
63 
65  robot_trajectory::RobotTrajectoryPtr trajectory;
66 
69 
70  explicit operator bool() const
71  {
72  return bool(error_code);
73  }
74  };
75 
78  {
79  std::string planner_id;
80  std::string planning_pipeline;
82  double planning_time;
85 
86  void load(const rclcpp::Node::SharedPtr& node)
87  {
88  std::string ns = "plan_request_params.";
89  node->get_parameter_or(ns + "planner_id", planner_id, std::string(""));
90  node->get_parameter_or(ns + "planning_pipeline", planning_pipeline, std::string(""));
91  node->get_parameter_or(ns + "planning_time", planning_time, 1.0);
92  node->get_parameter_or(ns + "planning_attempts", planning_attempts, 5);
93  node->get_parameter_or(ns + "max_velocity_scaling_factor", max_velocity_scaling_factor, 1.0);
94  node->get_parameter_or(ns + "max_acceleration_scaling_factor", max_acceleration_scaling_factor, 1.0);
95  }
96  };
97 
99  PlanningComponent(const std::string& group_name, const rclcpp::Node::SharedPtr& node);
100  PlanningComponent(const std::string& group_name, const MoveItCppPtr& moveit_cpp);
101 
109 
112 
114  ~PlanningComponent() = default;
115 
117  const std::string& getPlanningGroupName() const;
118 
120  const std::vector<std::string> getNamedTargetStates();
121 
123  std::map<std::string, double> getNamedTargetStateValues(const std::string& name);
124 
129  void setWorkspace(double minx, double miny, double minz, double maxx, double maxy, double maxz);
130 
132  void unsetWorkspace();
133 
135  moveit::core::RobotStatePtr getStartState();
136 
138  bool setStartState(const moveit::core::RobotState& start_state);
140  bool setStartState(const std::string& named_state);
141 
144 
146  bool setGoal(const std::vector<moveit_msgs::msg::Constraints>& goal_constraints);
148  bool setGoal(const moveit::core::RobotState& goal_state);
150  bool setGoal(const geometry_msgs::msg::PoseStamped& goal_pose, const std::string& link_name);
152  bool setGoal(const std::string& named_target);
153 
155  bool setPathConstraints(const moveit_msgs::msg::Constraints& path_constraints);
156 
159  PlanSolution plan();
162  PlanSolution plan(const PlanRequestParameters& parameters);
163 
166  bool execute(bool blocking = true);
167 
169  const PlanSolutionPtr getLastPlanSolution();
170 
171 private:
172  // Core properties and instances
173  rclcpp::Node::SharedPtr node_;
174  MoveItCppPtr moveit_cpp_;
175  const std::string group_name_;
176  // The robot_model_ member variable of MoveItCpp class will manually free the joint_model_group_ resources
177  const moveit::core::JointModelGroup* joint_model_group_;
178 
179  // Planning
180  std::set<std::string> planning_pipeline_names_;
181  // The start state used in the planning motion request
182  moveit::core::RobotStatePtr considered_start_state_;
183  std::vector<moveit_msgs::msg::Constraints> current_goal_constraints_;
184  moveit_msgs::msg::Constraints current_path_constraints_;
185  PlanRequestParameters plan_request_parameters_;
186  moveit_msgs::msg::WorkspaceParameters workspace_parameters_;
187  bool workspace_parameters_set_ = false;
188  PlanSolutionPtr last_plan_solution_;
189 
190  // common properties for goals
191  // TODO(henningkayser): support goal tolerances
192  // double goal_joint_tolerance_;
193  // double goal_position_tolerance_;
194  // double goal_orientation_tolerance_;
195  // TODO(henningkayser): implement path/trajectory constraints
196  // std::unique_ptr<moveit_msgs::msg::Constraints> path_constraints_;
197  // std::unique_ptr<moveit_msgs::msg::TrajectoryConstraints> trajectory_constraints_;
198 };
199 } // namespace moveit_cpp
200 
201 namespace moveit
202 {
203 namespace planning_interface
204 {
205 using PlanningComponent [[deprecated("use moveit_cpp")]] = moveit_cpp::PlanningComponent;
207 } // namespace planning_interface
208 } // namespace moveit
a wrapper around moveit_msgs::MoveItErrorCodes to make it easier to return an error code message from...
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Definition: robot_state.h:90
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
void unsetWorkspace()
Remove the workspace bounding box from planning.
PlanningComponent & operator=(PlanningComponent &&other)=delete
bool setGoal(const std::vector< moveit_msgs::msg::Constraints > &goal_constraints)
Set the goal constraints used for planning.
~PlanningComponent()=default
Destructor.
PlanSolution plan()
Run a plan from start or current state to fulfill the last goal constraints provided by setGoal() usi...
PlanningComponent & operator=(const PlanningComponent &)=delete
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....
MOVEIT_STRUCT_FORWARD(PlanSolution)
const PlanSolutionPtr getLastPlanSolution()
Return the last plan solution.
PlanningComponent(const std::string &group_name, const rclcpp::Node::SharedPtr &node)
Constructor.
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.
const std::vector< std::string > getNamedTargetStates()
Get the names of the named robot states available as targets.
bool execute(bool blocking=true)
Execute the latest computed solution trajectory computed by plan(). By default this function terminat...
moveit::core::RobotStatePtr getStartState()
Get the considered start state if defined, otherwise get the current state.
moveit_cpp::PlanningComponent PlanningComponent
moveit::core::MoveItErrorCode MoveItErrorCode
MOVEIT_DECLARE_PTR(MoveItCpp, moveit_cpp::MoveItCpp)
MOVEIT_CLASS_FORWARD(MoveItCpp)
Main namespace for MoveIt.
Definition: exceptions.h:43
This namespace includes the base class for MoveIt planners.
Planning pipeline.
name
Definition: setup.py:7
Planner parameters provided with the MotionPlanRequest.
void load(const rclcpp::Node::SharedPtr &node)
The representation of a plan solution.
robot_trajectory::RobotTrajectoryPtr trajectory
The trajectory of the robot (may not contain joints that are the same as for the start_state_)
moveit::core::MoveItErrorCode error_code
Reason why the plan failed.
moveit_msgs::msg::RobotState start_state
The full starting state used for planning.