49 pick_place_ = std::make_shared<pick_place::PickPlace>(context_->planning_pipeline_);
50 pick_place_->displayComputedMotionPlans(
true);
53 pick_place_->displayProcessedGrasps(
true);
56 pickup_action_server_ = std::make_unique<actionlib::SimpleActionServer<moveit_msgs::PickupAction>>(
57 root_node_handle_,
PICKUP_ACTION, [
this](
const auto& goal) { executePickupCallback(goal); },
false);
58 pickup_action_server_->registerPreemptCallback([
this] { preemptPickupCallback(); });
59 pickup_action_server_->start();
62 place_action_server_ = std::make_unique<actionlib::SimpleActionServer<moveit_msgs::PlaceAction>>(
63 root_node_handle_,
PLACE_ACTION, [
this](
const auto& goal) { executePlaceCallback(goal); },
false);
64 place_action_server_->registerPreemptCallback([
this] { preemptPlaceCallback(); });
65 place_action_server_->start();
89 moveit_msgs::PickupResult& action_res)
91 pick_place::PickPlanPtr plan;
95 plan = pick_place_->planPick(ps, *goal);
97 catch (std::exception& ex)
99 ROS_ERROR_NAMED(
"manipulation",
"Pick&place threw an exception: %s", ex.what());
104 const std::vector<pick_place::ManipulationPlanPtr>& success = plan->getSuccessfulManipulationPlans();
107 action_res.error_code = plan->getErrorCode();
111 const pick_place::ManipulationPlanPtr& result = success.back();
112 convertToMsg(result->trajectories_, action_res.trajectory_start, action_res.trajectory_stages);
113 action_res.trajectory_descriptions.resize(result->trajectories_.size());
114 for (std::size_t i = 0; i < result->trajectories_.size(); ++i)
115 action_res.trajectory_descriptions[i] = result->trajectories_[i].description_;
116 if (result->id_ < goal->possible_grasps.size())
117 action_res.grasp = goal->possible_grasps[result->id_];
118 action_res.error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
119 action_res.planning_time = plan->getLastPlanTime();
124 action_res.error_code.val = moveit_msgs::MoveItErrorCodes::FAILURE;
129 moveit_msgs::PlaceResult& action_res)
131 pick_place::PlacePlanPtr plan;
135 plan = pick_place_->planPlace(ps, *goal);
137 catch (std::exception& ex)
139 ROS_ERROR_NAMED(
"manipulation",
"Pick&place threw an exception: %s", ex.what());
144 const std::vector<pick_place::ManipulationPlanPtr>& success = plan->getSuccessfulManipulationPlans();
147 action_res.error_code = plan->getErrorCode();
151 const pick_place::ManipulationPlanPtr& result = success.back();
152 convertToMsg(result->trajectories_, action_res.trajectory_start, action_res.trajectory_stages);
153 action_res.trajectory_descriptions.resize(result->trajectories_.size());
154 for (std::size_t i = 0; i < result->trajectories_.size(); ++i)
155 action_res.trajectory_descriptions[i] = result->trajectories_[i].description_;
156 if (result->id_ < goal->place_locations.size())
157 action_res.place_location = goal->place_locations[result->id_];
158 action_res.error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
159 action_res.planning_time = plan->getLastPlanTime();
164 action_res.error_code.val = moveit_msgs::MoveItErrorCodes::FAILURE;
169 moveit_msgs::PickupResult* action_res,
176 pick_place::PickPlanPtr pick_plan;
181 catch (std::exception& ex)
183 ROS_ERROR_NAMED(
"manipulation",
"Pick&place threw an exception: %s", ex.what());
188 const std::vector<pick_place::ManipulationPlanPtr>& success = pick_plan->getSuccessfulManipulationPlans();
195 const pick_place::ManipulationPlanPtr& result = success.back();
197 if (result->id_ < goal.possible_grasps.size())
198 action_res->grasp = goal.possible_grasps[result->id_];
199 plan.
error_code_.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
200 action_res->planning_time = pick_plan->getLastPlanTime();
205 plan.
error_code_.val = moveit_msgs::MoveItErrorCodes::FAILURE;
208 return plan.
error_code_.val == moveit_msgs::MoveItErrorCodes::SUCCESS;
212 moveit_msgs::PlaceResult* action_res,
219 pick_place::PlacePlanPtr place_plan;
224 catch (std::exception& ex)
226 ROS_ERROR_NAMED(
"manipulation",
"Pick&place threw an exception: %s", ex.what());
231 const std::vector<pick_place::ManipulationPlanPtr>& success = place_plan->getSuccessfulManipulationPlans();
238 const pick_place::ManipulationPlanPtr& result = success.back();
240 if (result->id_ < goal.place_locations.size())
241 action_res->place_location = goal.place_locations[result->id_];
242 plan.
error_code_.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
243 action_res->planning_time = place_plan->getLastPlanTime();
248 plan.
error_code_.val = moveit_msgs::MoveItErrorCodes::FAILURE;
251 return plan.
error_code_.val == moveit_msgs::MoveItErrorCodes::SUCCESS;
255 const moveit_msgs::PickupGoalConstPtr& goal, moveit_msgs::PickupResult& action_res)
259 opt.
replan_ = goal->planning_options.replan;
265 return planUsingPickPlacePickup(g, result_ptr, plan);
267 if (goal->planning_options.look_around && context_->plan_with_sensing_)
270 attempts = goal->planning_options.look_around_attempts,
271 safe_execution_cost = goal->planning_options.max_safe_execution_cost](
273 return plan_with_sensing->computePlan(plan, planner, attempts, safe_execution_cost);
275 context_->plan_with_sensing_->setBeforeLookCallback([
this] { startPickupLookCallback(); });
279 context_->plan_execution_->planAndExecute(plan, goal->planning_options.planning_scene_diff, opt);
281 convertToMsg(plan.
plan_components_, action_res.trajectory_start, action_res.trajectory_stages);
284 action_res.trajectory_descriptions[i] = plan.
plan_components_[i].description_;
289 moveit_msgs::PlaceResult& action_res)
293 opt.
replan_ = goal->planning_options.replan;
298 return planUsingPickPlacePlace(g, result_ptr, plan);
300 if (goal->planning_options.look_around && context_->plan_with_sensing_)
303 attempts = goal->planning_options.look_around_attempts,
304 safe_execution_cost = goal->planning_options.max_safe_execution_cost](
306 return plan_with_sensing->computePlan(plan, planner, attempts, safe_execution_cost);
308 context_->plan_with_sensing_->setBeforeLookCallback([
this] { startPlaceLookCallback(); });
312 context_->plan_execution_->planAndExecute(plan, goal->planning_options.planning_scene_diff, opt);
314 convertToMsg(plan.
plan_components_, action_res.trajectory_start, action_res.trajectory_stages);
317 action_res.trajectory_descriptions[i] = plan.
plan_components_[i].description_;
326 context_->planning_scene_monitor_->waitForCurrentRobotState(
ros::Time::now());
327 context_->planning_scene_monitor_->updateFrameTransforms();
329 moveit_msgs::PickupGoalConstPtr goal;
330 if (input_goal->possible_grasps.empty())
332 moveit_msgs::PickupGoal* copy(
new moveit_msgs::PickupGoal(*input_goal));
339 moveit_msgs::PickupResult action_res;
341 if (goal->planning_options.plan_only || !context_->allow_trajectory_execution_)
343 if (!goal->planning_options.plan_only)
344 ROS_WARN_NAMED(
"manipulation",
"This instance of MoveGroup is not allowed to execute trajectories but the pick "
345 "goal request has plan_only set to false. Only a motion plan will be computed "
347 executePickupCallbackPlanOnly(goal, action_res);
350 executePickupCallbackPlanAndExecute(goal, action_res);
352 bool planned_trajectory_empty = action_res.trajectory_stages.empty();
354 getActionResultString(action_res.error_code, planned_trajectory_empty, goal->planning_options.plan_only);
355 if (action_res.error_code.val == moveit_msgs::MoveItErrorCodes::SUCCESS)
356 pickup_action_server_->setSucceeded(action_res,
response);
359 if (action_res.error_code.val == moveit_msgs::MoveItErrorCodes::PREEMPTED)
360 pickup_action_server_->setPreempted(action_res,
response);
362 pickup_action_server_->setAborted(action_res,
response);
365 setPickupState(
IDLE);
373 context_->planning_scene_monitor_->waitForCurrentRobotState(
ros::Time::now());
374 context_->planning_scene_monitor_->updateFrameTransforms();
376 moveit_msgs::PlaceResult action_res;
378 if (goal->planning_options.plan_only || !context_->allow_trajectory_execution_)
380 if (!goal->planning_options.plan_only)
381 ROS_WARN_NAMED(
"manipulation",
"This instance of MoveGroup is not allowed to execute trajectories but the place "
382 "goal request has plan_only set to false. Only a motion plan will be computed "
384 executePlaceCallbackPlanOnly(goal, action_res);
387 executePlaceCallbackPlanAndExecute(goal, action_res);
389 bool planned_trajectory_empty = action_res.trajectory_stages.empty();
391 getActionResultString(action_res.error_code, planned_trajectory_empty, goal->planning_options.plan_only);
392 if (action_res.error_code.val == moveit_msgs::MoveItErrorCodes::SUCCESS)
393 place_action_server_->setSucceeded(action_res,
response);
396 if (action_res.error_code.val == moveit_msgs::MoveItErrorCodes::PREEMPTED)
397 place_action_server_->setPreempted(action_res,
response);
399 place_action_server_->setAborted(action_res,
response);
415 pickup_state_ = state;
416 pickup_feedback_.state = stateToStr(state);
417 pickup_action_server_->publishFeedback(pickup_feedback_);
422 place_state_ = state;
423 place_feedback_.state = stateToStr(state);
424 place_action_server_->publishFeedback(place_feedback_);
432 goal.minimize_object_distance =
true;
436 moveit_msgs::Grasp g;
437 g.grasp_pose.header.frame_id = goal.target_name;
438 g.grasp_pose.pose.position.x = -0.2;
439 g.grasp_pose.pose.position.y = 0.0;
440 g.grasp_pose.pose.position.z = 0.0;
441 g.grasp_pose.pose.orientation.x = 0.0;
442 g.grasp_pose.pose.orientation.y = 0.0;
443 g.grasp_pose.pose.orientation.z = 0.0;
444 g.grasp_pose.pose.orientation.w = 1.0;
446 g.pre_grasp_approach.direction.header.frame_id = lscene->getPlanningFrame();
447 g.pre_grasp_approach.direction.vector.x = 1.0;
448 g.pre_grasp_approach.min_distance = 0.1;
449 g.pre_grasp_approach.desired_distance = 0.2;
451 g.post_grasp_retreat.direction.header.frame_id = lscene->getPlanningFrame();
452 g.post_grasp_retreat.direction.vector.z = 1.0;
453 g.post_grasp_retreat.min_distance = 0.1;
454 g.post_grasp_retreat.desired_distance = 0.2;
456 if (lscene->getRobotModel()->hasEndEffector(goal.end_effector))
458 g.pre_grasp_posture.joint_names = lscene->getRobotModel()->getEndEffector(goal.end_effector)->getJointModelNames();
459 g.pre_grasp_posture.points.resize(1);
460 g.pre_grasp_posture.points[0].positions.resize(g.pre_grasp_posture.joint_names.size(),
461 std::numeric_limits<double>::max());
463 g.grasp_posture.joint_names = g.pre_grasp_posture.joint_names;
464 g.grasp_posture.points.resize(1);
465 g.grasp_posture.points[0].positions.resize(g.grasp_posture.joint_names.size(), -std::numeric_limits<double>::max());
467 goal.possible_grasps.push_back(g);