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;
148 moveit_cpp_->getPlanningPipelines());
160 if (!joint_model_group_)
162 RCLCPP_ERROR(logger_,
"Failed to retrieve joint model group for name '%s'.", group_name_.c_str());
163 plan_solution.error_code = moveit::core::MoveItErrorCode::INVALID_GROUP_NAME;
164 return plan_solution;
168 if (current_goal_constraints_.empty())
170 RCLCPP_ERROR(logger_,
"No goal constraints set for planning request");
171 plan_solution.error_code = moveit::core::MoveItErrorCode::INVALID_GOAL_CONSTRAINTS;
172 return plan_solution;
178 moveit_cpp_->getPlanningSceneMonitorNonConst();
190 for (
const auto& request : requests)
196 requests,
planning_scene, moveit_cpp_->getPlanningPipelines(), stopping_criterion_callback,
197 solution_selection_function);
203 plan_solution = motion_plan_response_vector.at(0);
205 catch (std::out_of_range&)
207 RCLCPP_ERROR(logger_,
"MotionPlanResponse vector was empty after parallel planning");
208 plan_solution.error_code = moveit::core::MoveItErrorCode::INVALID_GOAL_CONSTRAINTS;
211 return plan_solution;
217 plan_request_parameters.
load(node_);
219 logger_,
"Default plan request parameters loaded with --"
221 <<
" planner_id: " << plan_request_parameters.
planner_id <<
','
222 <<
" planning_time: " << plan_request_parameters.
planning_time <<
','
226 return plan(plan_request_parameters);
231 considered_start_state_ = std::make_shared<moveit::core::RobotState>(start_state);
237 if (considered_start_state_)
239 return considered_start_state_;
243 moveit::core::RobotStatePtr s;
244 moveit_cpp_->getCurrentState(s, 1.0);
252 if (std::find(named_targets.begin(), named_targets.end(), start_state_name) == named_targets.end())
254 RCLCPP_ERROR(logger_,
"No predefined joint state found for target name '%s'", start_state_name.c_str());
265 considered_start_state_.reset();
271 std::map<std::string, double> positions;
278 workspace_parameters_.header.frame_id = moveit_cpp_->getRobotModel()->getModelFrame();
279 workspace_parameters_.header.stamp = node_->now();
280 workspace_parameters_.min_corner.x = minx;
281 workspace_parameters_.min_corner.y = miny;
282 workspace_parameters_.min_corner.z = minz;
283 workspace_parameters_.max_corner.x = maxx;
284 workspace_parameters_.max_corner.y = maxy;
285 workspace_parameters_.max_corner.z = maxz;
286 workspace_parameters_set_ =
true;
291 workspace_parameters_set_ =
false;
296 current_goal_constraints_ = goal_constraints;
315 if (std::find(named_targets.begin(), named_targets.end(), goal_state_name) == named_targets.end())
317 RCLCPP_ERROR(logger_,
"No predefined joint state found for target name '%s'", goal_state_name.c_str());
329 request.group_name = group_name_;
331 request.planner_id = plan_request_parameters.
planner_id;
332 request.num_planning_attempts = std::max(1, plan_request_parameters.
planning_attempts);
333 request.allowed_planning_time = plan_request_parameters.
planning_time;
336 if (workspace_parameters_set_)
338 request.workspace_parameters = workspace_parameters_;
340 request.goal_constraints = current_goal_constraints_;
341 request.path_constraints = current_path_constraints_;
342 request.trajectory_constraints = current_trajectory_constraints_;
345 moveit::core::RobotStatePtr start_state = considered_start_state_;
348 start_state = moveit_cpp_->getCurrentState();
350 start_state->update();
358 std::vector<::planning_interface::MotionPlanRequest> motion_plan_requests;
364 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.