43 #include <moveit_msgs/MotionPlanRequest.h>
48 namespace task_constructor {
53 using PlannerID = std::tuple<std::string, std::string>;
54 using PlannerMap = std::map<PlannerID, std::weak_ptr<planning_pipeline::PlanningPipeline> >;
55 using ModelList = std::list<std::pair<std::weak_ptr<const moveit::core::RobotModel>,
PlannerMap> >;
58 PlannerMap::mapped_type&
retrieve(
const moveit::core::RobotModelConstPtr& model,
const PlannerID&
id) {
60 ModelList::iterator model_it =
cache_.begin();
61 while (model_it !=
cache_.end()) {
62 if (model_it->first.expired()) {
63 model_it =
cache_.erase(model_it);
66 if (model_it->first.lock() == model)
70 if (model_it ==
cache_.end())
73 return model_it->second.insert(std::make_pair(
id, PlannerMap::mapped_type())).first->second;
78 static PlannerCache cache;
80 static constexpr
char const* PLUGIN_PARAMETER_NAME =
"planning_plugin";
82 std::string pipeline_ns = spec.ns +
"/planning_pipelines/" + spec.pipeline;
85 ROS_WARN(
"Failed to find '%s/%s'. %s", pipeline_ns.c_str(), PLUGIN_PARAMETER_NAME,
86 "Attempting to load pipeline from old parameter structure. Please update your MoveIt config.");
87 pipeline_ns = spec.ns;
92 std::weak_ptr<planning_pipeline::PlanningPipeline>& entry = cache.retrieve(spec.model,
id);
93 planning_pipeline::PlanningPipelinePtr planner = entry.lock();
96 planner = std::make_shared<planning_pipeline::PlanningPipeline>(spec.model,
ros::NodeHandle(pipeline_ns),
97 PLUGIN_PARAMETER_NAME, spec.adapter_param);
105 auto& p = properties();
106 p.declare<std::string>(
"planner",
"",
"planner id");
108 p.declare<uint>(
"num_planning_attempts", 1u,
"number of planning attempts");
109 p.declare<moveit_msgs::WorkspaceParameters>(
"workspace_parameters", moveit_msgs::WorkspaceParameters(),
110 "allowed workspace of mobile base?");
112 p.declare<
double>(
"goal_joint_tolerance", 1e-4,
"tolerance for reaching joint goals");
113 p.declare<
double>(
"goal_position_tolerance", 1e-4,
"tolerance for reaching position goals");
114 p.declare<
double>(
"goal_orientation_tolerance", 1e-4,
"tolerance for reaching orientation goals");
116 p.declare<
bool>(
"display_motion_plans",
false,
118 p.declare<
bool>(
"publish_planning_requests",
false,
119 "publish motion planning requests on topic " +
123 PipelinePlanner::PipelinePlanner(
const planning_pipeline::PlanningPipelinePtr&
planning_pipeline) : PipelinePlanner() {
127 void PipelinePlanner::init(
const core::RobotModelConstPtr& robot_model) {
130 spec.model = robot_model;
131 spec.pipeline = pipeline_name_;
133 }
else if (robot_model != planner_->getRobotModel()) {
134 throw std::runtime_error(
135 "The robot model of the planning pipeline isn't the same as the task's robot model -- "
136 "use Task::setRobotModel for setting the robot model when using custom planning pipeline");
138 planner_->displayComputedMotionPlans(properties().get<bool>(
"display_motion_plans"));
139 planner_->publishReceivedRequests(properties().get<bool>(
"publish_planning_requests"));
144 req.group_name = jmg->
getName();
145 req.planner_id = p.get<std::string>(
"planner");
146 req.allowed_planning_time = std::min(timeout, p.get<
double>(
"timeout"));
147 req.start_state.is_diff =
true;
149 req.num_planning_attempts = p.get<uint>(
"num_planning_attempts");
150 req.max_velocity_scaling_factor = p.get<
double>(
"max_velocity_scaling_factor");
151 req.max_acceleration_scaling_factor = p.get<
double>(
"max_acceleration_scaling_factor");
152 req.workspace_parameters = p.get<moveit_msgs::WorkspaceParameters>(
"workspace_parameters");
156 const planning_scene::PlanningSceneConstPtr& to,
158 robot_trajectory::RobotTrajectoryPtr& result,
159 const moveit_msgs::Constraints& path_constraints) {
160 const auto& props = properties();
161 moveit_msgs::MotionPlanRequest req;
164 req.goal_constraints.resize(1);
166 props.get<
double>(
"goal_joint_tolerance"));
167 req.path_constraints = path_constraints;
169 return plan(from, req, result);
172 PlannerInterface::Result PipelinePlanner::plan(
const planning_scene::PlanningSceneConstPtr& from,
174 const Eigen::Isometry3d& target_eigen,
176 robot_trajectory::RobotTrajectoryPtr& result,
177 const moveit_msgs::Constraints& path_constraints) {
178 const auto& props = properties();
179 moveit_msgs::MotionPlanRequest req;
182 geometry_msgs::PoseStamped target;
183 target.header.frame_id = from->getPlanningFrame();
186 req.goal_constraints.resize(1);
188 link.
getName(), target, props.get<
double>(
"goal_position_tolerance"),
189 props.get<
double>(
"goal_orientation_tolerance"));
190 req.path_constraints = path_constraints;
192 return plan(from, req, result);
196 const moveit_msgs::MotionPlanRequest& req,
197 robot_trajectory::RobotTrajectoryPtr& result) {
199 bool success = planner_->generatePlan(from, req, res);
201 return {
success,
success ? std::string() :
static_cast<std::string
>(
res.error_code_) };