antipodal.cpp
Go to the documentation of this file.
00001 #include <agile_grasp/antipodal.h>
00002 
00003 const int Antipodal::NO_GRASP = 0; // normals point not toward any finger
00004 const int Antipodal::HALF_GRASP = 1; // normals point towards one finger
00005 const int Antipodal::FULL_GRASP = 2; // normals point towards both fingers
00006 
00007 Antipodal::Antipodal(const Eigen::Matrix3Xd& normals) : normals_(normals)
00008 {
00009 
00010 }
00011 
00012 int Antipodal::evaluateGrasp(double thresh_half, double thresh_full)
00013 {
00014   int num_thresh = 6;
00015   int grasp = 0;
00016   double cos_thresh = cos(thresh_half * M_PI / 180.0);
00017   int numl = 0;
00018   int numr = 0;
00019   Eigen::Vector3d l, r;
00020   l << -1, 0, 0;
00021   r << 1, 0, 0;
00022   bool is_half_grasp = false;
00023   bool is_full_grasp = false;
00024 
00025   // check whether this is a half grasp
00026   for (int i = 0; i < normals_.cols(); i++)
00027   {
00028     if (l.dot(normals_.col(i)) > cos_thresh)
00029     {
00030       numl++;
00031       if (numl > num_thresh)
00032       {
00033         is_half_grasp = true;
00034         break;
00035       }
00036     }
00037 
00038     if (r.dot(normals_.col(i)) > cos_thresh)
00039     {
00040       numr++;
00041       if (numr > num_thresh)
00042       {
00043         is_half_grasp = true;
00044         break;
00045       }
00046     }
00047   }
00048 
00049   // check whether this is a full grasp
00050   cos_thresh = cos(thresh_full * M_PI / 180.0);
00051   numl = 0;
00052   numr = 0;
00053 //  std::cout << "cos_thresh: " << cos_thresh << std::endl;
00054   for (int i = 0; i < normals_.cols(); i++)
00055   {
00056 //      std::cout << "normals_.col(" << i << "): " << normals_.col(i) << ", ldot: " << l.dot(normals_.col(i)) << std::endl;
00057     if (l.dot(normals_.col(i)) > cos_thresh)
00058     {
00059       numl++;
00060 //      std::cout << "numl: " << numl << std::endl;
00061       if (numl > num_thresh && numr > num_thresh)
00062       {
00063         is_full_grasp = true;
00064         break;
00065       }
00066     }
00067 
00068     if (r.dot(normals_.col(i)) > cos_thresh)
00069     {
00070       numr++;
00071 //      std::cout << "numr: " << numr << std::endl;
00072       if (numl > num_thresh && numr > num_thresh)
00073       {
00074         is_full_grasp = true;
00075         break;
00076       }
00077     }
00078   }
00079 
00080   if (is_full_grasp)
00081     return FULL_GRASP;
00082   else if (is_half_grasp)
00083     return HALF_GRASP;
00084 
00085   return NO_GRASP;
00086 }


agile_grasp
Author(s): Andreas ten Pas
autogenerated on Sat Jun 8 2019 20:08:27