00001 //###################################################################### 00002 // 00003 // GraspIt! 00004 // Copyright (C) 2002-2009 Columbia University in the City of New York. 00005 // All rights reserved. 00006 // 00007 // GraspIt! is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // GraspIt! is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with GraspIt!. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // Author(s): Matei T. Ciocarlie 00021 // 00022 // $Id: onLinePlanner.h,v 1.22 2009/05/07 19:57:46 cmatei Exp $ 00023 // 00024 //###################################################################### 00025 00026 #include <QObject> 00027 #include <time.h> 00028 #include <list> 00029 00030 #include "simAnnPlanner.h" 00031 00032 class Hand; 00033 class GraspTester; 00034 class OnLineGraspInterface; 00035 class transf; 00036 00037 /* An online planner has the following characteristics: 00038 <ul> 00039 <li> runs FAST simulated annealing planning again and again 00040 <li> runs a tester in a separate thread that takes the solutions 00041 and tests them for F-C 00042 </ul> 00043 Right now it uses a SimulatedAnnealing optimization. Might use 00044 others in the future (Gradient Descent, Sampling etc). This 00045 planner ALWAYS uses a clone to perform the search. However, it 00046 also keeps a pointer to the initial hand (as mRefHand) in order 00047 to use it to receive input. 00048 00049 Nothing in its structure actually defines the use of on-line 00050 input. However, since it always uses a clone, the initial 00051 reference hand is free to be controlled by the user and as a 00052 source of input. Wrist position input is taken into account by 00053 repeatedly setting the REFERENCE transform of the mCurrentState 00054 to the transform of the reference hand. (see the mainLoop() 00055 fctn). Then, as the variables in the HandObjectState will define 00056 OFFSETS from this state, we can use a mInputState with all 00057 the relevant variables set to 0. A mCurrentState with 0 00058 translation and 0 rotation is identical to the state of the 00059 mRefHand. 00060 00061 For hand posture input, we process the CyberGlove - this is 00062 actually done up in the processInput() of the EGPlanner class. 00063 */ 00064 00065 class OnLinePlanner : public SimAnnPlanner 00066 { 00067 private: 00071 Hand *mRefHand; 00072 00074 Hand *mSolutionClone; 00076 bool mMarkSolutions; 00078 00079 double mSolutionDistance; 00081 double mObjectDistance; 00083 GraspPlanningState *mCurrentBest; 00085 GraspTester *mGraspTester; 00087 std::list<GraspPlanningState*> mCandidateList; 00089 00092 OnLineGraspInterface *mInterface; 00093 00094 int mSolutionCount; 00095 00096 OnLinePlanner(){} 00098 void createSolutionClone(); 00100 00103 double stateDistance(const GraspPlanningState *s1, const GraspPlanningState *s2); 00104 double distanceOutsideApproach(const transf &solTran, const transf &handTran); 00105 void updateSolutionList(); 00106 00107 void resetParameters(); 00111 void mainLoop(); 00114 void graspLoop(); 00115 00116 public: 00117 OnLinePlanner(Hand *h); 00118 ~OnLinePlanner(); 00119 virtual PlannerType getType(){return PLANNER_ONLINE;} 00120 00121 void startPlanner(); 00122 void pausePlanner(); 00123 bool resetPlanner(); 00124 00125 double getSolutionDistance() const {return mSolutionDistance;} 00126 double getObjectDistance() const {return mObjectDistance;} 00127 int getSABufferSize() const {return (int)mCandidateList.size();} 00128 int getFCBufferSize() const; 00130 void showSolutionClone(bool s); 00132 void showClone(bool s); 00133 00134 //these just relay the actions to the OnLineGraspInterface. As actions have nothing to do with planning, this 00135 //shouldn't theoretically be here at all, but it was easier to interface with the action class through here 00136 void action(ActionType a); 00137 void useRealBarrettHand(bool s); 00138 ActionType getAction(); 00139 };