17 #ifndef __POWER_GRASP_MODULE_H__ 18 #define __POWER_GRASP_MODULE_H__ 25 #include <pcl/io/ply_io.h> 26 #include <pcl/filters/statistical_outlier_removal.h> 28 #include <yarp/os/all.h> 30 #include <iCub/learningMachine/FixedRangeScaler.h> 31 #include <iCub/learningMachine/LSSVMLearner.h> 32 #include <iCub/data3D/SurfaceMeshWithBoundingBox.h> 34 #include "visualizationThread.h" 35 #include "orientationThread.h" 38 #include "custom/dirent.h" 41 #define similarity 0.005 43 #define STATE_ESTIMATE 1 45 #define RIGHT_HAND "right" 46 #define LEFT_HAND "left" 47 #define NO_HAND "no_hand" 50 #define MODALITY_RIGHT 0 51 #define MODALITY_LEFT 1 52 #define MODALITY_TOP 2 53 #define MODALITY_CENTER 3 54 #define MODALITY_AUTO 4 56 class PowerGrasp:
public yarp::os::RFModule
61 int numberOfBestPoints;
70 bool fromFileFinished;
75 bool testWithLearning;
82 bool graspSpecificPoint;
85 bool testWithLearningEnabled;
98 float currentCurvature;
99 std::string chosenHand;
101 std::string outputDir;
103 VisualizationThread *visualizationThread;
104 OrientationThread* orientationThreadRight;
105 OrientationThread* orientationThreadLeft;
108 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
109 pcl::PointCloud<pcl::PointXYZ>::Ptr cloudxyz;
110 pcl::PointCloud <pcl::Normal>::Ptr normals;
112 yarp::sig::Vector offsetR;
113 yarp::sig::Vector offsetL;
114 yarp::sig::Vector chosenPoint;
115 yarp::sig::Vector chosenNormal;
116 yarp::sig::Vector chosenPixel;
117 yarp::sig::Matrix chosenOrientation;
119 yarp::os::Port reconstructionPort;
120 yarp::os::Port areCmdPort;
121 yarp::os::Port depth2kin;
122 yarp::os::BufferedPort<iCub::data3D::SurfaceMeshWithBoundingBox> meshPort;
125 yarp::os::Mutex mutex;
126 yarp::os::Event eventRpc;
128 std::vector<double> rankScores;
129 std::vector<int> rankIndices;
133 iCub::learningmachine::FixedRangeScaler scalerIn,scalerOut;
134 iCub::learningmachine::LSSVMLearner machine;
136 double min(
const double a,
const double b) {
return (a>b)?b:a;};
137 double max(
const double a,
const double b) {
return (a<b)?b:a;};
139 void addPointCloud(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_in);
140 void addPlanePoints();
141 void configureSVM(yarp::os::Bottle &bottleSVM);
142 void configureGeneralInfo(yarp::os::ResourceFinder &rf);
143 void normalEstimation();
144 void filter(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_in,pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_in_filtered);
145 void write(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_in,
const int nFile);
146 void insertElement(
const double score,
const int index);
147 void fromSurfaceMesh(
const iCub::data3D::SurfaceMeshWithBoundingBox& msg);
150 void manageModality();
151 void chooseCandidatePoints();
153 void startVisualization();
155 int findIndexFromCloud(
const yarp::sig::Vector &point);
156 double scoreFunction(
const int index);
157 bool normalPointingOut(
const int index,
const yarp::sig::Vector ¢er);
158 bool respond(
const yarp::os::Bottle& command, yarp::os::Bottle& reply);
159 bool fillCloudFromFile();
160 bool get3DPoint(
const yarp::sig::Vector &point2D, yarp::sig::Vector &point3D);
161 std::string chooseBestPointAndOrientation(
int &winnerIndex, yarp::sig::Matrix &designedOrientation);
162 yarp::sig::Vector vectorFromNormal(
const int index);
163 yarp::sig::Vector vectorFromCloud(
const int index);
164 yarp::sig::Vector pointFromBottle(
const yarp::os::Bottle &bot,
const int index);
165 yarp::sig::Vector assignIndexToAxes(
double &anglez);
166 yarp::sig::Vector findBiggestAxis(
int &ind);
167 yarp::sig::Vector computeApproachVector(
const yarp::sig::Vector &chosenPoint);
168 std::vector<pcl::PointIndices> selectBigClusters(
const std::vector<pcl::PointIndices> &clusters);
173 bool configure(yarp::os::ResourceFinder &rf);
175 bool interruptModule();
The Definition of the BoundingBox class.