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 #ifndef _egplanner_h_
00027 #define _egplanner_h_
00028
00029 #include <vector>
00030 #include <list>
00031 #include <ostream>
00032 #include <time.h>
00033
00034 #include <QThread>
00035 #include <QMutex>
00036 #include <QObject>
00037
00038 #include "search.h"
00039
00040 class Hand;
00041 class Body;
00042 class GraspPlanningState;
00043 class SoSensor;
00044 class SearchEnergy;
00045
00046 namespace Profiling {
00047 class ProfileInstance;
00048 }
00049
00050 enum PlannerState{INIT, READY, RUNNING, DONE, EXITED, STARTING_THREAD};
00051
00067 class EGPlanner : public QThread
00068 {
00069 Q_OBJECT
00070 protected:
00071 EGPlanner(){}
00073
00074 void init();
00075
00077 Hand *mHand;
00078 bool mUsesClone;
00079
00081 mutable std::ostream *mOut;
00083 GraspPlanningState *mCurrentState;
00085 SearchEnergy *mEnergyCalculator;
00086
00088 int mCurrentStep;
00090 int mMaxSteps;
00092 bool mRepeat;
00093
00095 int mRenderType, mRenderCount;
00097 const GraspPlanningState *mLastRenderState;
00098
00100
00102 void render();
00103
00105 double mMaxTime;
00107 Profiling::ProfileInstance *mProfileInstance;
00108
00110 GraspPlanningState *mTargetState;
00112 unsigned char mInputType;
00114 virtual bool processInput();
00115
00117 virtual void resetParameters();
00118
00120 virtual bool checkTerminationConditions();
00121
00123 SoSensor *mIdleSensor;
00125 static void sensorCB(void *data,SoSensor*);
00126
00128 bool mMultiThread;
00130 QMutex mControlMutex;
00132 virtual void run();
00134 virtual void threadLoop();
00135
00137 PlannerState mState;
00139 void setState(PlannerState s);
00140
00142 std::list<GraspPlanningState*> mBestList;
00144 bool addToListOfUniqueSolutions(GraspPlanningState *s, std::list<GraspPlanningState*> *list, double distance);
00146 virtual double stateDistance(const GraspPlanningState *s1, const GraspPlanningState *s2);
00147
00149 virtual void mainLoop()=0;
00150
00151 signals:
00153 void update();
00155
00157 void complete();
00158
00159 public:
00161 EGPlanner(Hand *h);
00162 virtual ~EGPlanner();
00164 virtual PlannerType getType()=0;
00165
00167 virtual bool initialized(){return true;}
00168
00170 virtual bool resetPlanner();
00171
00173 virtual void startPlanner();
00175 virtual void pausePlanner();
00177 virtual void stopPlanner();
00178
00180 void createAndUseClone();
00181
00183 virtual void showClone(bool s);
00184
00186 void startThread();
00187
00189 PlannerState getState();
00190
00192 virtual bool isActive(){return getState()==RUNNING;}
00194 virtual bool isReady(){return getState()==READY;}
00195
00197 void invalidateReset(){if (isReady()) setState(INIT);}
00198
00200 virtual void setEnergyType(SearchEnergyType s);
00202 void setContactType(SearchContactType c);
00203
00204 void setRenderType(RenderType r){mRenderType = r;}
00205 void setMaxSteps(int s){mMaxSteps=s;}
00206 void setRepeat(bool r){mRepeat = r;}
00207 void setMaxTime(int t){mMaxTime=t;}
00208
00210 virtual const GraspPlanningState* getGrasp(int i);
00212 virtual void showGrasp(int i);
00214 virtual int getListSize(){return mBestList.size();}
00216 virtual void clearSolutions();
00217
00218 int getCurrentStep(){return mCurrentStep;}
00219 Hand *getHand(){return mHand;}
00220
00222 double getRunningTime();
00223
00225 bool setInput(unsigned char input, bool on = true);
00227 GraspPlanningState *getTargetState(){return mTargetState;}
00228 unsigned char getInputType(){return mInputType;}
00229
00231 void setStatStream(std::ostream *out) const;
00232 };
00233 #endif