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_with_approach.h"
00037
00038 #include "object_manipulator/tools/hand_description.h"
00039 #include "object_manipulator/tools/vector_tools.h"
00040
00041
00042
00043 using object_manipulation_msgs::GraspResult;
00044 using arm_navigation_msgs::ArmNavigationErrorCodes;
00045
00046 namespace object_manipulator {
00047
00049 arm_navigation_msgs::OrderedCollisionOperations
00050 GraspExecutorWithApproach::collisionOperationsForGrasp(const object_manipulation_msgs::PickupGoal &pickup_goal)
00051 {
00052 arm_navigation_msgs::OrderedCollisionOperations ord;
00053 arm_navigation_msgs::CollisionOperation coll;
00054 coll.object1 = handDescription().gripperCollisionName(pickup_goal.arm_name);
00055 coll.operation = arm_navigation_msgs::CollisionOperation::DISABLE;
00056 if (!pickup_goal.collision_object_name.empty())
00057 {
00058 coll.object2 = pickup_goal.collision_object_name;
00059 ord.collision_operations.push_back(coll);
00060 }
00061 if (pickup_goal.allow_gripper_support_collision)
00062 {
00063 coll.object2 = pickup_goal.collision_support_surface_name;
00064 ord.collision_operations.push_back(coll);
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 ord.collision_operations = concat(ord.collision_operations,
00077 pickup_goal.additional_collision_operations.collision_operations);
00078 return ord;
00079 }
00080
00082 std::vector<arm_navigation_msgs::LinkPadding>
00083 GraspExecutorWithApproach::linkPaddingForGrasp(const object_manipulation_msgs::PickupGoal &pickup_goal)
00084 {
00085
00086
00087 return concat(MechanismInterface::gripperPadding(pickup_goal.arm_name, 0.0),
00088 pickup_goal.additional_link_padding);
00089 }
00090
00091 GraspResult
00092 GraspExecutorWithApproach::getInterpolatedIKForGrasp(const object_manipulation_msgs::PickupGoal &pickup_goal,
00093 const object_manipulation_msgs::Grasp &grasp,
00094 trajectory_msgs::JointTrajectory &grasp_trajectory)
00095 {
00096
00097 geometry_msgs::PoseStamped grasp_pose_stamped;
00098 grasp_pose_stamped.pose = grasp.grasp_pose;
00099 grasp_pose_stamped.header.frame_id = pickup_goal.target.reference_frame_id;
00100 grasp_pose_stamped.header.stamp = ros::Time(0);
00101
00102
00103 geometry_msgs::Vector3Stamped direction;
00104 direction.header.stamp = ros::Time::now();
00105 direction.header.frame_id = handDescription().gripperFrame(pickup_goal.arm_name);
00106 direction.vector = mechInterface().negate( handDescription().approachDirection(pickup_goal.arm_name) );
00107
00108 std::vector<double> empty;
00109
00110 float actual_approach_distance;
00111 int error_code = mechInterface().getInterpolatedIK(pickup_goal.arm_name,
00112 grasp_pose_stamped,
00113 direction, grasp.desired_approach_distance,
00114 empty,
00115 grasp.pre_grasp_posture,
00116 collisionOperationsForGrasp(pickup_goal),
00117 linkPaddingForGrasp(pickup_goal),
00118 true, grasp_trajectory, actual_approach_distance);
00119 ROS_DEBUG_NAMED("manipulation"," Grasp executor approach distance: actual (%f), min(%f) and desired (%f)",
00120 actual_approach_distance, grasp.min_approach_distance, grasp.desired_approach_distance);
00121
00122 if ( actual_approach_distance < grasp.min_approach_distance)
00123 {
00124 ROS_DEBUG_NAMED("manipulation"," Grasp executor: interpolated IK for grasp below min threshold");
00125 if (grasp_trajectory.points.empty())
00126 {
00127 ROS_DEBUG_NAMED("manipulation"," Grasp executor: interpolated IK empty, problem is with grasp location");
00128 if (marker_publisher_) marker_publisher_->colorGraspMarker(marker_id_, 1.0, 1.0, 0.0);
00129 if (error_code == ArmNavigationErrorCodes::COLLISION_CONSTRAINTS_VIOLATED)
00130 return Result(GraspResult::GRASP_IN_COLLISION, true);
00131 else if (error_code == ArmNavigationErrorCodes::JOINT_LIMITS_VIOLATED)
00132 return Result(GraspResult::GRASP_OUT_OF_REACH, true);
00133 else return Result(GraspResult::GRASP_UNFEASIBLE, true);
00134 }
00135 if (marker_publisher_) marker_publisher_->colorGraspMarker(marker_id_, 0.0, 1.0, 1.0);
00136 if (error_code == ArmNavigationErrorCodes::COLLISION_CONSTRAINTS_VIOLATED)
00137 return Result(GraspResult::PREGRASP_IN_COLLISION, true);
00138 else if (error_code == ArmNavigationErrorCodes::JOINT_LIMITS_VIOLATED)
00139 return Result(GraspResult::PREGRASP_OUT_OF_REACH, true);
00140 else return Result(GraspResult::PREGRASP_UNFEASIBLE, true);
00141 }
00142
00143
00144
00145
00146
00147 return Result(GraspResult::SUCCESS, true);
00148 }
00149
00150
00151 GraspResult GraspExecutorWithApproach::prepareGrasp(const object_manipulation_msgs::PickupGoal &pickup_goal,
00152 const object_manipulation_msgs::Grasp &grasp)
00153 {
00154 if (marker_publisher_) marker_publisher_->colorGraspMarker(marker_id_, 1.0, 0.0, 0.0);
00155
00156
00157
00158
00159 GraspResult result = getInterpolatedIKForGrasp(pickup_goal, grasp, interpolated_grasp_trajectory_);
00160 if ( result.result_code != GraspResult::SUCCESS )
00161 {
00162 ROS_DEBUG_NAMED("manipulation"," Grasp executor: failed to generate grasp trajectory");
00163 return result;
00164 }
00165
00166
00167 std::vector<double> grasp_joint_angles = interpolated_grasp_trajectory_.points.back().positions;
00168 result = getInterpolatedIKForLift(pickup_goal, grasp, grasp_joint_angles, interpolated_lift_trajectory_);
00169 if (result.result_code != GraspResult::SUCCESS)
00170 {
00171 ROS_DEBUG_NAMED("manipulation"," Grasp executor: failed to generate lift trajectory");
00172 return result;
00173 }
00174
00175
00176
00177
00178
00179 if ( !mechInterface().checkStateValidity(pickup_goal.arm_name,
00180 interpolated_grasp_trajectory_.points.front().positions,
00181 pickup_goal.additional_collision_operations,
00182 pickup_goal.additional_link_padding) )
00183 {
00184 ROS_DEBUG_NAMED("manipulation"," Grasp executor: initial pose in grasp trajectory is unfeasible with default padding");
00185 return Result(GraspResult::PREGRASP_UNFEASIBLE, true);
00186 }
00187 ROS_DEBUG_NAMED("manipulation"," Grasp executor: goal pose for move arm passed validity test");
00188
00189
00190
00191
00192 if ( pickup_goal.lift.min_distance != 0 &&
00193 !mechInterface().checkStateValidity(pickup_goal.arm_name, interpolated_lift_trajectory_.points.back().positions,
00194 collisionOperationsForLift(pickup_goal),
00195 pickup_goal.additional_link_padding) )
00196 {
00197 ROS_DEBUG_NAMED("manipulation"," Grasp executor: last pose in lift trajectory is unfeasible with default padding");
00198 return Result(GraspResult::LIFT_UNFEASIBLE, true);
00199 }
00200
00201 return Result(GraspResult::SUCCESS, true);
00202 }
00203
00204 GraspResult
00205 GraspExecutorWithApproach::executeGrasp(const object_manipulation_msgs::PickupGoal &pickup_goal,
00206 const object_manipulation_msgs::Grasp &grasp)
00207 {
00208
00209
00210
00211 if ( !mechInterface().attemptMoveArmToGoal(pickup_goal.arm_name,
00212 interpolated_grasp_trajectory_.points.front().positions,
00213 pickup_goal.additional_collision_operations,
00214 pickup_goal.additional_link_padding) )
00215 {
00216 ROS_DEBUG_NAMED("manipulation"," Grasp executor: move_arm to pre-grasp reports failure");
00217 if (marker_publisher_) marker_publisher_->colorGraspMarker(marker_id_, 1.0, 0.5, 0.0);
00218 return Result(GraspResult::MOVE_ARM_FAILED, true);
00219 }
00220
00221 mechInterface().handPostureGraspAction(pickup_goal.arm_name, grasp,
00222 object_manipulation_msgs::GraspHandPostureExecutionGoal::PRE_GRASP, -1);
00223
00224
00225
00226
00227
00228 mechInterface().attemptTrajectory(pickup_goal.arm_name, interpolated_grasp_trajectory_, true);
00229
00230 mechInterface().handPostureGraspAction(pickup_goal.arm_name, grasp,
00231 object_manipulation_msgs::GraspHandPostureExecutionGoal::GRASP, pickup_goal.max_contact_force);
00232
00233 if (marker_publisher_) marker_publisher_->colorGraspMarker(marker_id_, 0.0, 1.0, 0.0);
00234 return Result(GraspResult::SUCCESS, true);
00235 }
00236
00241 GraspResult GraspExecutorWithApproach::retreat(const object_manipulation_msgs::PickupGoal &pickup_goal,
00242 const object_manipulation_msgs::Grasp &grasp)
00243 {
00244 arm_navigation_msgs::OrderedCollisionOperations ord;
00245 arm_navigation_msgs::CollisionOperation coll;
00246
00247 coll.object1 = handDescription().gripperCollisionName(pickup_goal.arm_name);
00248 coll.object2 = pickup_goal.collision_object_name;
00249 coll.operation = arm_navigation_msgs::CollisionOperation::DISABLE;
00250 ord.collision_operations.push_back(coll);
00251
00252 coll.object2 = pickup_goal.collision_support_surface_name;
00253 ord.collision_operations.push_back(coll);
00254 ord.collision_operations = concat(ord.collision_operations,
00255 pickup_goal.additional_collision_operations.collision_operations);
00256
00257 geometry_msgs::Vector3Stamped direction;
00258 direction.header.stamp = ros::Time::now();
00259 direction.header.frame_id = handDescription().gripperFrame(pickup_goal.arm_name);
00260 direction.vector = mechInterface().negate( handDescription().approachDirection(pickup_goal.arm_name) );
00261
00262
00263
00264 float retreat_distance = grasp.min_approach_distance;
00265 float actual_distance;
00266 if (!mechInterface().translateGripper(pickup_goal.arm_name, direction,
00267 ord, pickup_goal.additional_link_padding,
00268 retreat_distance, 0, actual_distance))
00269 {
00270 ROS_ERROR(" Grasp executor: failed to retreat gripper at all");
00271 return Result(GraspResult::RETREAT_FAILED, false);
00272 }
00273 if (actual_distance < retreat_distance)
00274 {
00275 ROS_WARN(" Grasp executor: only partial retreat (%f) succeeeded", actual_distance);
00276 return Result(GraspResult::RETREAT_FAILED, false);
00277 }
00278 return Result(GraspResult::SUCCESS, true);
00279 }
00280
00281 }