53 , group_name_(group_name)
54 , logger_(
moveit::getLogger(
"moveit.ros.planning_component"))
56 joint_model_group_ = moveit_cpp_->getRobotModel()->getJointModelGroup(group_name);
57 if (!joint_model_group_)
59 std::string error =
"Could not find joint model group '" + group_name +
"'.";
60 RCLCPP_FATAL_STREAM(logger_, error);
61 throw std::runtime_error(error);
68 joint_model_group_ = moveit_cpp_->getRobotModel()->getJointModelGroup(group_name);
69 if (!joint_model_group_)
71 std::string error =
"Could not find joint model group '" + group_name +
"'.";
72 RCLCPP_FATAL_STREAM(logger_, error);
73 throw std::runtime_error(error);
79 if (joint_model_group_)
85 RCLCPP_WARN(logger_,
"Unable to find joint group with name '%s'.", group_name_.c_str());
88 std::vector<std::string> empty;
99 current_path_constraints_ = path_constraints;
105 current_trajectory_constraints_ = trajectory_constraints;
115 if (!joint_model_group_)
117 RCLCPP_ERROR(logger_,
"Failed to retrieve joint model group for name '%s'.", group_name_.c_str());
118 plan_solution.error_code = moveit::core::MoveItErrorCode::INVALID_GROUP_NAME;
119 return plan_solution;
123 if (current_goal_constraints_.empty())
125 RCLCPP_ERROR(logger_,
"No goal constraints set for planning request");
126 plan_solution.error_code = moveit::core::MoveItErrorCode::INVALID_GOAL_CONSTRAINTS;
127 return plan_solution;
144 moveit_cpp_->getPlanningPipelines());
156 if (!joint_model_group_)
158 RCLCPP_ERROR(logger_,
"Failed to retrieve joint model group for name '%s'.", group_name_.c_str());
159 plan_solution.error_code = moveit::core::MoveItErrorCode::INVALID_GROUP_NAME;
160 return plan_solution;
164 if (current_goal_constraints_.empty())
166 RCLCPP_ERROR(logger_,
"No goal constraints set for planning request");
167 plan_solution.error_code = moveit::core::MoveItErrorCode::INVALID_GOAL_CONSTRAINTS;
168 return plan_solution;
174 moveit_cpp_->getPlanningSceneMonitorNonConst();
186 for (
const auto& request : requests)
192 requests,
planning_scene, moveit_cpp_->getPlanningPipelines(), stopping_criterion_callback,
193 solution_selection_function);
199 plan_solution = motion_plan_response_vector.at(0);
201 catch (std::out_of_range&)
203 RCLCPP_ERROR(logger_,
"MotionPlanResponse vector was empty after parallel planning");
204 plan_solution.error_code = moveit::core::MoveItErrorCode::INVALID_GOAL_CONSTRAINTS;
207 return plan_solution;
213 plan_request_parameters.
load(node_);
215 logger_,
"Default plan request parameters loaded with --"
217 <<
" planner_id: " << plan_request_parameters.
planner_id <<
','
218 <<
" planning_time: " << plan_request_parameters.
planning_time <<
','
222 return plan(plan_request_parameters);
227 considered_start_state_ = std::make_shared<moveit::core::RobotState>(start_state);
233 if (considered_start_state_)
235 return considered_start_state_;
239 moveit::core::RobotStatePtr s;
240 moveit_cpp_->getCurrentState(s, 1.0);
248 if (std::find(named_targets.begin(), named_targets.end(), start_state_name) == named_targets.end())
250 RCLCPP_ERROR(logger_,
"No predefined joint state found for target name '%s'", start_state_name.c_str());
261 considered_start_state_.reset();
267 std::map<std::string, double> positions;
274 workspace_parameters_.header.frame_id = moveit_cpp_->getRobotModel()->getModelFrame();
275 workspace_parameters_.header.stamp = node_->now();
276 workspace_parameters_.min_corner.x = minx;
277 workspace_parameters_.min_corner.y = miny;
278 workspace_parameters_.min_corner.z = minz;
279 workspace_parameters_.max_corner.x = maxx;
280 workspace_parameters_.max_corner.y = maxy;
281 workspace_parameters_.max_corner.z = maxz;
282 workspace_parameters_set_ =
true;
287 workspace_parameters_set_ =
false;
292 current_goal_constraints_ = goal_constraints;
311 if (std::find(named_targets.begin(), named_targets.end(), goal_state_name) == named_targets.end())
313 RCLCPP_ERROR(logger_,
"No predefined joint state found for target name '%s'", goal_state_name.c_str());
325 request.group_name = group_name_;
327 request.planner_id = plan_request_parameters.
planner_id;
328 request.num_planning_attempts = std::max(1, plan_request_parameters.
planning_attempts);
329 request.allowed_planning_time = plan_request_parameters.
planning_time;
332 if (workspace_parameters_set_)
334 request.workspace_parameters = workspace_parameters_;
336 request.goal_constraints = current_goal_constraints_;
337 request.path_constraints = current_path_constraints_;
338 request.trajectory_constraints = current_trajectory_constraints_;
341 moveit::core::RobotStatePtr start_state = considered_start_state_;
344 start_state = moveit_cpp_->getCurrentState();
346 start_state->update();
354 std::vector<::planning_interface::MotionPlanRequest> motion_plan_requests;
360 return motion_plan_requests;
bool getVariableDefaultPositions(const std::string &name, std::map< std::string, double > &values) const
Get the values that correspond to a named state as read from the URDF. Return false on failure.
const std::vector< std::string > & getDefaultStateNames() const
Get the names of the known default states (as specified in the SRDF)
Representation of a robot's state. This includes position, velocity, acceleration and effort.
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
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.
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 setGoal(const std::vector< moveit_msgs::msg::Constraints > &goal_constraints)
Set the goal constraints used for planning.
const std::string & getPlanningGroupName() const
Get the name of the planning group.
::planning_interface::MotionPlanRequest getMotionPlanRequest(const PlanRequestParameters &plan_request_parameters)
Utility function to get a MotionPlanRequest from PlanRequestParameters and the internal state of the ...
bool setTrajectoryConstraints(const moveit_msgs::msg::TrajectoryConstraints &trajectory_constraints)
Set the trajectory constraints generated from a moveit msg Constraints.
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.
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.
static PlanningScenePtr clone(const PlanningSceneConstPtr &scene)
Clone a planning scene. Even if the scene scene depends on a parent, the cloned scene will not.
This is a convenience class for obtaining access to an instance of a locked PlanningScene.
moveit_msgs::msg::Constraints constructGoalConstraints(const moveit::core::RobotState &state, const moveit::core::JointModelGroup *jmg, double tolerance_below, double tolerance_above)
Generates a constraint message intended to be used as a goal constraint for a joint group....
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::msg::RobotState &robot_state, bool copy_attached_bodies=true)
Convert a MoveIt robot state to a robot state message.
::planning_interface::MotionPlanResponse planWithSinglePipeline(const ::planning_interface::MotionPlanRequest &motion_plan_request, const ::planning_scene::PlanningSceneConstPtr &planning_scene, const std::unordered_map< std::string, planning_pipeline::PlanningPipelinePtr > &planning_pipelines)
Function to calculate the MotionPlanResponse for a given MotionPlanRequest and a PlanningScene.
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.
const std::vector<::planning_interface::MotionPlanResponse > planWithParallelPipelines(const std::vector<::planning_interface::MotionPlanRequest > &motion_plan_requests, const ::planning_scene::PlanningSceneConstPtr &planning_scene, const std::unordered_map< std::string, planning_pipeline::PlanningPipelinePtr > &planning_pipelines, const StoppingCriterionFunction &stopping_criterion_callback=nullptr, const SolutionSelectionFunction &solution_selection_function=nullptr)
Function to solve multiple planning problems in parallel threads with multiple planning pipelines at ...
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.
Main namespace for MoveIt.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
This namespace includes the central class for representing planning contexts.
Planner parameters provided with the MotionPlanRequest.
std::vector< PlanRequestParameters > plan_request_parameter_vector
Planner parameters provided with the MotionPlanRequest.
void load(const rclcpp::Node::SharedPtr &node, const std::string ¶m_namespace="")
double max_velocity_scaling_factor
double max_acceleration_scaling_factor
std::string planning_pipeline
Response to a planning query.