EigenGraspPlanner.h
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 // To use  during beta phase, until decided which implementation
00039 // is better.
00040 // If this is defined, the implementation uses its own local
00041 // SoIdleSensor to repeatedly call ivIdleCallback(). If
00042 // this is not defined, the GraspItSceneManager event loop
00043 // callback is used to call ivIdleCallback().
00044 // #define USE_SEPARATE_SOSENSOR
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     // So far, only AxisAngle supported, as others not tested yet.
00084     // Later will be: enum  GraspItStateType{Complete, AxisAngle, Ellipsoid, Approach};
00085     enum GraspItStateType  {AxisAngle};
00086 
00087     // Mapping to GraspIt! search energy type. For now only
00088     // supports CONTACT_ENERGY. All other types still to be added:
00089     // CONTACT_ENERGY, POTENTIAL_QUALITY_ENERGY, CONTACT_QUALITY_ENERGY,
00090     // AUTOGRASP_QUALITY_ENERGY, GUIDED_AUTOGRASP_ENERGY, STRICT_AUTOGRASP_ENERGY,
00091     // COMPLIANT_ENERGY, DYNAMIC_ENERGY
00092     enum GraspItSearchEnergyType  {EnergyContact};
00093 
00094     // Type of planner ot use. So far, only simulated annealing supported, as
00095     // others are not tested.
00096     // TODO: implement other planner types as well.
00097     // Later this should be: enum PlannerType {SimAnn, Loop, MultiThreaded };
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,// = DEFAULT_MAX_PLANNING_STEPS,
00120               const int repeatPlanning,// = 1,
00121               const int maxResultsPerRepeat,// = DEFAULT_MAX_RESULTS_PER_REPEAT,
00122               const bool finishWithAutograsp,// = DEFAULT_FINISH_WITH_AUTOGRASP,
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,//  = DEFAULT_MAX_PLANNING_STEPS,
00157               const int repeatPlanning,//   = 1
00158               const int maxResultsPerRepeat,// = DEFAULT_MAX_RESULTS_PER_REPEAT,
00159               const bool finishWithAutograsp,// = DEFAULT_FINISH_WITH_AUTOGRASP,
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     // void stopPlanner();
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     // void inputLoad(const std::string& inputGraspFile);
00280 
00285     void printResult(int i, bool detailed = false);
00286 
00287     // double getEnergy(const GraspPlanningState * s);
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     // for test purposes: to separately calculate energy of grasps
00355     // SearchEnergy * mEnergyCalculator;
00356 
00357     EGPlanner * graspitEgPlanner;
00358     RECURSIVE_MUTEX graspitEgPlannerMtx;
00359 
00360     // The state type to use for GraspIt. Default is STATE_AXIS_ANGLE.
00361     GraspItStateType graspitStateType;
00362 
00363     // The search energy type to use. Is ENERGY_CONTACT by default.
00364     // Important: ENERGY_CONTACT_QUALITY doesn't work properly at the moment,
00365     // at least not with the Jaco hand, also not in the original simulator.... the energy
00366     // drops to -0. Reason to be found in SearchEnergy::potentialQualityEnergy, variable gq
00367     // gets 0. So far, only successfully tested method was ENERGY_CONTACT, though I didn't
00368     // test all others except ENERGY_CONTACT_QUALITY
00369     GraspItSearchEnergyType graspitSearchEnergyType;
00370 
00371     // whether to use contacts information in the planner or not
00372     bool useContacts;
00373 
00374     std::vector<const GraspPlanningState*> results;
00375 
00376 #ifdef USE_SEPARATE_SOSENSOR
00377     SoSensor *mIdleSensor;
00378 #endif
00379 };
00380 
00381 }  // namespace GraspIt
00382 #endif  //  GRASP_PLANNING_GRASPIT_EIGENGRASPPLANNER_H


grasp_planning_graspit
Author(s): Jennifer Buehler
autogenerated on Wed May 8 2019 02:53:36