00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "object_manipulator/grasp_execution/grasp_executor.h"
00037
00038 #include "object_manipulator/tools/exceptions.h"
00039 #include "object_manipulator/tools/hand_description.h"
00040 #include "object_manipulator/tools/vector_tools.h"
00041
00042 using object_manipulation_msgs::GraspResult;
00043 using motion_planning_msgs::ArmNavigationErrorCodes;
00044
00045 namespace object_manipulator {
00046
00048 motion_planning_msgs::OrderedCollisionOperations
00049 GraspExecutor::collisionOperationsForLift(const object_manipulation_msgs::PickupGoal &pickup_goal)
00050 {
00051 motion_planning_msgs::OrderedCollisionOperations ord;
00052 motion_planning_msgs::CollisionOperation coll;
00053 coll.object1 = handDescription().gripperCollisionName(pickup_goal.arm_name);
00054 coll.object2 = pickup_goal.collision_object_name;
00055 coll.operation = motion_planning_msgs::CollisionOperation::DISABLE;
00056 ord.collision_operations.push_back(coll);
00057 if (pickup_goal.allow_gripper_support_collision)
00058 {
00059 coll.object2 = pickup_goal.collision_support_surface_name;
00060 ord.collision_operations.push_back(coll);
00061 }
00062 ord.collision_operations = concat(ord.collision_operations,
00063 pickup_goal.additional_collision_operations.collision_operations);
00064 return ord;
00065 }
00066
00068 std::vector<motion_planning_msgs::LinkPadding>
00069 GraspExecutor::linkPaddingForLift(const object_manipulation_msgs::PickupGoal &pickup_goal)
00070 {
00071 return concat(MechanismInterface::fingertipPadding(pickup_goal.arm_name, 0.0),
00072 pickup_goal.additional_link_padding);
00073 }
00074
00075 GraspResult
00076 GraspExecutor::getInterpolatedIKForLift(const object_manipulation_msgs::PickupGoal &pickup_goal,
00077 const object_manipulation_msgs::Grasp &grasp,
00078 const std::vector<double> &grasp_joint_angles,
00079 trajectory_msgs::JointTrajectory &lift_trajectory)
00080 {
00081 geometry_msgs::PoseStamped grasp_pose;
00082 grasp_pose.pose = grasp.grasp_pose;
00083 grasp_pose.header.frame_id = pickup_goal.target.reference_frame_id;
00084 grasp_pose.header.stamp = ros::Time(0);
00085
00086 float actual_lift_distance;
00087 int error_code =
00088 mechInterface().getInterpolatedIK(pickup_goal.arm_name,
00089 grasp_pose,
00090 pickup_goal.lift.direction, pickup_goal.lift.desired_distance,
00091 grasp_joint_angles,
00092 grasp.grasp_posture,
00093 collisionOperationsForLift(pickup_goal), linkPaddingForLift(pickup_goal),
00094 false, lift_trajectory, actual_lift_distance);
00095 ROS_DEBUG(" Lift distance: actual %f, min %f and desired %f", actual_lift_distance, pickup_goal.lift.min_distance,
00096 pickup_goal.lift.desired_distance);
00097
00098 if (actual_lift_distance < pickup_goal.lift.min_distance)
00099 {
00100 ROS_DEBUG(" Lift trajectory below min. threshold");
00101 if (marker_publisher_) marker_publisher_->colorGraspMarker(marker_id_, 0.0, 0.0, 1.0);
00102 if (lift_trajectory.points.empty())
00103 {
00104 ROS_DEBUG(" Lift trajectory empty; problem is with grasp location");
00105 if (error_code == ArmNavigationErrorCodes::COLLISION_CONSTRAINTS_VIOLATED)
00106 return Result(GraspResult::GRASP_IN_COLLISION, true);
00107 else if (error_code == ArmNavigationErrorCodes::JOINT_LIMITS_VIOLATED)
00108 return Result(GraspResult::GRASP_OUT_OF_REACH, true);
00109 else return Result(GraspResult::GRASP_UNFEASIBLE, true);
00110 }
00111 if (error_code == ArmNavigationErrorCodes::COLLISION_CONSTRAINTS_VIOLATED)
00112 return Result(GraspResult::LIFT_IN_COLLISION, true);
00113 else if (error_code == ArmNavigationErrorCodes::JOINT_LIMITS_VIOLATED)
00114 return Result(GraspResult::LIFT_OUT_OF_REACH, true);
00115 else return Result(GraspResult::LIFT_UNFEASIBLE, true);
00116 }
00117
00118
00119
00120
00121 if ( pickup_goal.lift.min_distance != 0 &&
00122 !mechInterface().checkStateValidity(pickup_goal.arm_name, lift_trajectory.points.back().positions,
00123 collisionOperationsForLift(pickup_goal),
00124 pickup_goal.additional_link_padding) )
00125 {
00126 ROS_DEBUG(" Grasp executor: last pose in lift trajectory is unfeasible with default padding");
00127 return Result(GraspResult::LIFT_UNFEASIBLE, true);
00128 }
00129
00130 return Result(GraspResult::SUCCESS, true);
00131 }
00132
00133 GraspResult
00134 GraspExecutor::lift(const object_manipulation_msgs::PickupGoal &pickup_goal)
00135 {
00136 if (interpolated_lift_trajectory_.points.empty())
00137 {
00138 ROS_ERROR(" Grasp executor: lift trajectory not set");
00139 return Result(GraspResult::LIFT_FAILED, false);
00140 }
00141
00142
00143 mechInterface().attemptTrajectory(pickup_goal.arm_name, interpolated_lift_trajectory_, true);
00144 return Result(GraspResult::SUCCESS, true);
00145 }
00146
00147 GraspResult
00148 GraspExecutor::checkAndExecuteGrasp(const object_manipulation_msgs::PickupGoal &pickup_goal,
00149 const object_manipulation_msgs::Grasp &grasp)
00150 {
00151
00152 if (marker_publisher_)
00153 {
00154 geometry_msgs::PoseStamped marker_pose;
00155 marker_pose.pose = grasp.grasp_pose;
00156 marker_pose.header.frame_id = pickup_goal.target.reference_frame_id;
00157 marker_pose.header.stamp = ros::Time::now();
00158 marker_id_ = marker_publisher_->addGraspMarker(marker_pose);
00159 }
00160 GraspResult result = prepareGrasp(pickup_goal, grasp);
00161 if (result.result_code != GraspResult::SUCCESS) return result;
00162
00163 result = executeGrasp(pickup_goal, grasp);
00164 if (result.result_code != GraspResult::SUCCESS) return result;
00165
00166
00167 if (!mechInterface().graspPostureQuery(pickup_goal.arm_name))
00168 {
00169 ROS_DEBUG("Hand reports that grasp was not successfully executed; releasing object and retreating");
00170 mechInterface().handPostureGraspAction(pickup_goal.arm_name, grasp,
00171 object_manipulation_msgs::GraspHandPostureExecutionGoal::RELEASE);
00172 retreat(pickup_goal);
00173 return Result(GraspResult::GRASP_FAILED, false);
00174 }
00175
00176
00177 if (!pickup_goal.collision_object_name.empty())
00178 {
00179 mechInterface().attachObjectToGripper(pickup_goal.arm_name, pickup_goal.collision_object_name);
00180 }
00181
00182
00183 result = lift(pickup_goal);
00184 if (result.result_code != GraspResult::SUCCESS) return result;
00185
00186 return Result(GraspResult::SUCCESS, true);
00187 }
00188
00189 }