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 #include <moveit_simple_grasps/simple_grasps.h>
00036
00037 namespace moveit_simple_grasps
00038 {
00039
00040
00041 SimpleGrasps::SimpleGrasps(moveit_visual_tools::MoveItVisualToolsPtr visual_tools, bool verbose) :
00042 visual_tools_(visual_tools),
00043 verbose_(verbose)
00044 {
00045 ROS_DEBUG_STREAM_NAMED("grasps","Loaded simple grasp generator");
00046 }
00047
00048
00049 SimpleGrasps::~SimpleGrasps()
00050 {
00051 }
00052
00053
00054 bool SimpleGrasps::generateBlockGrasps(const geometry_msgs::Pose& object_pose, const GraspData& grasp_data,
00055 std::vector<moveit_msgs::Grasp>& possible_grasps)
00056 {
00057
00058
00059 generateAxisGrasps( object_pose, X_AXIS, DOWN, HALF, 0, grasp_data, possible_grasps);
00060 generateAxisGrasps( object_pose, X_AXIS, UP, HALF, 0, grasp_data, possible_grasps);
00061 generateAxisGrasps( object_pose, Y_AXIS, DOWN, HALF, 0, grasp_data, possible_grasps);
00062 generateAxisGrasps( object_pose, Y_AXIS, UP, HALF, 0, grasp_data, possible_grasps);
00063
00064 return true;
00065 }
00066
00067
00068 bool SimpleGrasps::generateAxisGrasps(
00069 const geometry_msgs::Pose& object_pose,
00070 grasp_axis_t axis,
00071 grasp_direction_t direction,
00072 grasp_rotation_t rotation,
00073 double hand_roll,
00074 const GraspData& grasp_data,
00075 std::vector<moveit_msgs::Grasp>& possible_grasps)
00076 {
00077
00078
00079 tf::poseMsgToEigen(object_pose, object_global_transform_);
00080
00081
00082
00083
00084
00085 moveit_msgs::GripperTranslation pre_grasp_approach;
00086 pre_grasp_approach.direction.header.stamp = ros::Time::now();
00087 pre_grasp_approach.desired_distance = grasp_data.approach_retreat_desired_dist_;
00088 pre_grasp_approach.min_distance = grasp_data.approach_retreat_min_dist_;
00089
00090
00091 moveit_msgs::GripperTranslation post_grasp_retreat;
00092 post_grasp_retreat.direction.header.stamp = ros::Time::now();
00093 post_grasp_retreat.desired_distance = grasp_data.approach_retreat_desired_dist_;
00094 post_grasp_retreat.min_distance = grasp_data.approach_retreat_min_dist_;
00095
00096
00097 geometry_msgs::PoseStamped grasp_pose_msg;
00098 grasp_pose_msg.header.stamp = ros::Time::now();
00099 grasp_pose_msg.header.frame_id = grasp_data.base_link_;
00100
00101
00102
00103 double radius = grasp_data.grasp_depth_;
00104 double xb;
00105 double yb = 0.0;
00106 double zb;
00107 double theta1 = 0.0;
00108 double theta2 = 0.0;
00109
00110
00111 if( direction == DOWN )
00112 {
00113 theta2 = M_PI;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 for(int i = 0; i <= grasp_data.angle_resolution_; ++i)
00127 {
00128
00129 moveit_msgs::Grasp new_grasp;
00130
00131
00132 xb = radius*cos(theta1);
00133 zb = radius*sin(theta1);
00134
00135 Eigen::Affine3d grasp_pose;
00136
00137 switch(axis)
00138 {
00139 case X_AXIS:
00140 grasp_pose = Eigen::AngleAxisd(theta1, Eigen::Vector3d::UnitX())
00141 * Eigen::AngleAxisd(-0.5*M_PI, Eigen::Vector3d::UnitZ())
00142 * Eigen::AngleAxisd(theta2, Eigen::Vector3d::UnitX());
00143
00144 grasp_pose.translation() = Eigen::Vector3d( yb, xb ,zb);
00145
00146 break;
00147 case Y_AXIS:
00148 grasp_pose =
00149 Eigen::AngleAxisd(M_PI - theta1, Eigen::Vector3d::UnitY())
00150 *Eigen::AngleAxisd(theta2, Eigen::Vector3d::UnitX());
00151
00152 grasp_pose.translation() = Eigen::Vector3d( xb, yb ,zb);
00153
00154 break;
00155 case Z_AXIS:
00156 grasp_pose =
00157 Eigen::AngleAxisd(M_PI - theta1, Eigen::Vector3d::UnitZ())
00158 *Eigen::AngleAxisd(theta2, Eigen::Vector3d::UnitX());
00159
00160 grasp_pose.translation() = Eigen::Vector3d( xb, yb ,zb);
00161
00162 break;
00163 }
00164
00165
00166
00167
00168
00169 double score = sin(theta1);
00170 new_grasp.grasp_quality = std::max(score,0.1);
00171
00172
00173 if (rotation == HALF)
00174 theta1 += M_PI / grasp_data.angle_resolution_;
00175 else
00176 {
00177 theta1 += 2*M_PI / grasp_data.angle_resolution_;
00178 }
00179
00180
00181 static int grasp_id = 0;
00182 new_grasp.id = "Grasp" + boost::lexical_cast<std::string>(grasp_id);
00183 ++grasp_id;
00184
00185
00186
00187
00188 new_grasp.pre_grasp_posture = grasp_data.pre_grasp_posture_;
00189
00190
00191 new_grasp.grasp_posture = grasp_data.grasp_posture_;
00192
00193
00194
00195
00196
00197 if( verbose_ )
00198 {
00199 tf::poseEigenToMsg(object_global_transform_ * grasp_pose, grasp_pose_msg.pose);
00200 visual_tools_->publishArrow(grasp_pose_msg.pose, rviz_visual_tools::GREEN);
00201 }
00202
00203
00204
00205 Eigen::Affine3d roll_gripper;
00206 roll_gripper = Eigen::AngleAxisd(hand_roll, Eigen::Vector3d::UnitX());
00207 grasp_pose = grasp_pose * roll_gripper;
00208
00209
00210
00211
00212
00213 Eigen::Affine3d eef_conversion_pose;
00214 tf::poseMsgToEigen(grasp_data.grasp_pose_to_eef_pose_, eef_conversion_pose);
00215
00216
00217 grasp_pose = grasp_pose * eef_conversion_pose;
00218
00219
00220
00221 tf::poseEigenToMsg(object_global_transform_ * grasp_pose, grasp_pose_msg.pose);
00222
00223
00224 new_grasp.grasp_pose = grasp_pose_msg;
00225
00226
00227
00228
00229 new_grasp.max_contact_force = 0;
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 pre_grasp_approach.direction.header.frame_id = grasp_data.base_link_;
00242 pre_grasp_approach.direction.vector.x = 0;
00243 pre_grasp_approach.direction.vector.y = 0;
00244 pre_grasp_approach.direction.vector.z = -1;
00245 new_grasp.pre_grasp_approach = pre_grasp_approach;
00246
00247
00248 post_grasp_retreat.direction.header.frame_id = grasp_data.base_link_;
00249 post_grasp_retreat.direction.vector.x = 0;
00250 post_grasp_retreat.direction.vector.y = 0;
00251 post_grasp_retreat.direction.vector.z = 1;
00252 new_grasp.post_grasp_retreat = post_grasp_retreat;
00253
00254
00255 possible_grasps.push_back(new_grasp);
00256
00257
00258
00259
00260
00261 pre_grasp_approach.direction.header.frame_id = grasp_data.ee_parent_link_;
00262 pre_grasp_approach.direction.vector.x = 0;
00263 pre_grasp_approach.direction.vector.y = 0;
00264 pre_grasp_approach.direction.vector.z = 1;
00265 new_grasp.pre_grasp_approach = pre_grasp_approach;
00266
00267
00268 post_grasp_retreat.direction.header.frame_id = grasp_data.ee_parent_link_;
00269 post_grasp_retreat.direction.vector.x = 0;
00270 post_grasp_retreat.direction.vector.y = 0;
00271 post_grasp_retreat.direction.vector.z = -1;
00272 new_grasp.post_grasp_retreat = post_grasp_retreat;
00273
00274
00275 possible_grasps.push_back(new_grasp);
00276
00277 }
00278
00279 ROS_INFO_STREAM_NAMED("grasp", "Generated " << possible_grasps.size() << " grasps." );
00280
00281 return true;
00282 }
00283
00284 geometry_msgs::PoseStamped SimpleGrasps::getPreGraspPose(const moveit_msgs::Grasp &grasp, const std::string &ee_parent_link)
00285 {
00286
00287 geometry_msgs::PoseStamped grasp_pose = grasp.grasp_pose;
00288 Eigen::Affine3d grasp_pose_eigen;
00289 tf::poseMsgToEigen(grasp_pose.pose, grasp_pose_eigen);
00290
00291
00292 geometry_msgs::PoseStamped pre_grasp_pose;
00293 Eigen::Affine3d pre_grasp_pose_eigen = grasp_pose_eigen;
00294
00295
00296 Eigen::Vector3d pre_grasp_approach_direction_local;
00297
00298
00299
00300 Eigen::Vector3d pre_grasp_approach_direction = Eigen::Vector3d(
00301 -1 * grasp.pre_grasp_approach.direction.vector.x * grasp.pre_grasp_approach.desired_distance,
00302 -1 * grasp.pre_grasp_approach.direction.vector.y * grasp.pre_grasp_approach.desired_distance,
00303 -1 * grasp.pre_grasp_approach.direction.vector.z * grasp.pre_grasp_approach.desired_distance
00304 );
00305
00306
00307 if( grasp.pre_grasp_approach.direction.header.frame_id == ee_parent_link )
00308 {
00309
00310 pre_grasp_approach_direction_local = grasp_pose_eigen.rotation() * pre_grasp_approach_direction;
00311 }
00312 else
00313 {
00314 pre_grasp_approach_direction_local = pre_grasp_approach_direction;
00315 }
00316
00317
00318 pre_grasp_pose_eigen.translation() += pre_grasp_approach_direction_local;
00319
00320
00321 tf::poseEigenToMsg(pre_grasp_pose_eigen, pre_grasp_pose.pose);
00322
00323
00324 pre_grasp_pose.header = grasp_pose.header;
00325
00326 return pre_grasp_pose;
00327 }
00328
00329
00330
00331 }