Go to the documentation of this file.00001 #ifndef GRASP_PLANNING_GRASPIT_EIGENGRASPPLANNER_H
00002 #define GRASP_PLANNING_GRASPIT_EIGENGRASPPLANNER_H
00003
00025 #include <grasp_planning_graspit/GraspItSceneManager.h>
00026 #include <grasp_planning_graspit/EigenGraspResult.h>
00027 #include <grasp_planning_graspit/GraspItAccessor.h>
00028
00029 #include <vector>
00030 #include <string>
00031
00032 #include <QObject>
00033
00034 #define DEFAULT_MAX_PLANNING_STEPS 70000
00035 #define DEFAULT_MAX_RESULTS_PER_REPEAT 10
00036 #define DEFAULT_FINISH_WITH_AUTOGRASP false
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 class GraspPlanningState;
00047 class GraspableBody;
00048 class EGPlanner;
00049 class SearchEnergy;
00050 class GraspPlanningState;
00051 class GraspItAccessor;
00052
00053 namespace GraspIt
00054 {
00055
00078 class EigenGraspPlanner: public QObject, public GraspItAccessor
00079 {
00080 Q_OBJECT
00081
00082 public:
00083
00084
00085 enum GraspItStateType {AxisAngle};
00086
00087
00088
00089
00090
00091
00092 enum GraspItSearchEnergyType {EnergyContact};
00093
00094
00095
00096
00097
00098 enum PlannerType {SimAnn};
00099
00106 EigenGraspPlanner(const std::string& name, const SHARED_PTR<GraspItSceneManager>& i);
00107 virtual ~EigenGraspPlanner();
00108
00119 bool plan(const int maxPlanningSteps,
00120 const int repeatPlanning,
00121 const int maxResultsPerRepeat,
00122 const bool finishWithAutograsp,
00123 const PlannerType& planType = SimAnn);
00124
00154 bool plan(const std::string& handName, const std::string& objectName,
00155 const EigenTransform * objectPose,
00156 const int maxPlanningSteps,
00157 const int repeatPlanning,
00158 const int maxResultsPerRepeat,
00159 const bool finishWithAutograsp,
00160 const PlannerType& planType = SimAnn);
00161
00174 bool saveResultsAsWorldFiles(const std::string& inDirectory, const std::string& fileNamePrefix,
00175 bool asGraspIt = true, bool asInventor = false, bool createDir = true,
00176 bool saveSeparatePoseIV = false);
00177
00181 void getResults(std::vector<EigenGraspResult>& allGrasps) const;
00182
00183 protected:
00184 virtual void idleEventFromSceneManager();
00185
00186 virtual void onSceneManagerShutdown();
00187
00188 private:
00193 void deleteResults();
00194
00199 bool copyResult(const GraspPlanningState * s, EigenGraspResult& result) const;
00200
00205 void ivIdleCallback();
00206
00214 bool initPlanner(const int maxPlanningSteps, const PlannerType& planType = SimAnn);
00215
00219
00220
00221
00229 void initSearchType(GraspPlanningState& stateTemplate, const GraspItStateType& st);
00230
00235 void initPlannerType(const GraspPlanningState& stateTemplate, const PlannerType& pt);
00236
00237
00241 void updateResults();
00242
00247 void plannerUpdate();
00248
00249
00254 void plannerComplete();
00255
00256
00262 void setPlanningParameters();
00263
00267 void printPlanningResults();
00268
00272 void plannerReset();
00273
00279
00280
00285 void printResult(int i, bool detailed = false);
00286
00287
00288
00292 EigenTransform getHandTransform(const GraspPlanningState * s) const;
00296 EigenTransform getObjectTransform(const GraspPlanningState * s) const;
00297
00301 bool checkStateValidity(const GraspPlanningState * s) const;
00302
00306 void getGraspJointDOFs(const GraspPlanningState * s, std::vector<double>& dofs) const;
00307
00312 void getPregraspJointDOFs(const GraspPlanningState * s, std::vector<double>& dofs) const;
00313
00317 void getEigenGraspValues(const GraspPlanningState * s, std::vector<double>& egVals) const;
00318
00319
00320 #ifdef USE_SEPARATE_SOSENSOR
00321
00324 static void sensorCB(void *data, SoSensor *);
00325 #endif
00326
00327 public slots:
00332 void plannerUpdateSlot();
00337 void plannerCompleteSlot();
00338
00339 private:
00340 enum PlannerCommand {NONE, START, STOP};
00341
00345 PlannerCommand getPlannerCommand();
00349 void setPlannerCommand(const PlannerCommand c);
00350
00351 PlannerCommand planCommand;
00352 MUTEX planCommandMtx;
00353
00354
00355
00356
00357 EGPlanner * graspitEgPlanner;
00358 RECURSIVE_MUTEX graspitEgPlannerMtx;
00359
00360
00361 GraspItStateType graspitStateType;
00362
00363
00364
00365
00366
00367
00368
00369 GraspItSearchEnergyType graspitSearchEnergyType;
00370
00371
00372 bool useContacts;
00373
00374 std::vector<const GraspPlanningState*> results;
00375
00376 #ifdef USE_SEPARATE_SOSENSOR
00377 SoSensor *mIdleSensor;
00378 #endif
00379 };
00380
00381 }
00382 #endif // GRASP_PLANNING_GRASPIT_EIGENGRASPPLANNER_H