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
00029 #ifndef GRASP_HXX
00030
00031 #include <list>
00032 #include <vector>
00033 #include <set>
00034 #include <QObject>
00035
00036
00037 #include <Inventor/nodes/SoSeparator.h>
00038 #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
00039 class SoTransform;
00040 class SoCoordinate3;
00041 class SoIndexedFaceSet;
00042
00043 class vec3;
00044 class transf;
00045 class position;
00046 class Hand;
00047 class GraspableBody;
00048 class Contact;
00049 class VirtualContact;
00050 class Link;
00051 class GWS;
00052 class QualityMeasure;
00053 class QMDlg;
00054 class GWSprojection;
00055 class Matrix;
00056 class Joint;
00057
00059 #define MAX_FEAS_LOOPS 100
00060
00061 #define MAX_OPTM_LOOPS 100
00062
00063 extern bool saveSetup;
00064 extern int saveCounter;
00065
00067
00094 class Grasp : public QObject{
00095 Q_OBJECT
00096
00097 public:
00099 static const std::vector<int> ALL_DIMENSIONS;
00100
00101 protected:
00102 friend class LMIOptimizer;
00103
00105 Hand *hand;
00106
00108 GraspableBody *object;
00109
00111 bool valid;
00112
00114 std::list<GWS *> gwsList;
00115
00117 std::list<QualityMeasure *> qmList;
00118
00120 std::list<GWSprojection *> projectionList;
00121
00123 int numQM;
00124
00126 std::vector<Contact *> contactVec;
00127
00129 int numContacts;
00130
00132 double minWrench[6];
00133
00135 bool useGravity;
00136
00138 double *getLinkJacobian(int f, int l);
00139
00141 void setVirtualCentroid();
00142
00144 vec3 virtualCentroid();
00145
00147 void setRealCentroid(GraspableBody *body);
00148
00149 friend class QMDlg;
00150
00151 signals:
00153 void graspUpdated();
00154
00155 public:
00156 Grasp(Hand *h);
00157
00158 ~Grasp();
00159
00162 bool isValid() const {return valid;}
00163
00165
00166
00168 int getNumQM() const {return numQM;}
00169
00171 GraspableBody * getObject() const {return object;}
00172
00174 int getNumContacts() const {return numContacts;}
00175
00177 Contact * getContact(int i) const {return contactVec[i];}
00178
00179 void getMinWrench(double *w) const
00180 {
00181 if (w) memcpy(w,minWrench,6*sizeof(double));
00182 }
00183
00184 void setMinWrench(double *w)
00185 {
00186 if (w) memcpy(minWrench,w,6*sizeof(double));
00187 }
00188
00191 void setObject(GraspableBody *g) {object = g; update();}
00192
00193
00194 void setObjectNoUpdate(GraspableBody *g) {object = g;}
00195
00197 void collectContacts();
00199 void collectVirtualContacts();
00201 void collectVirtualContactsOnObject();
00202
00204 void update(std::vector<int> useDimensions = ALL_DIMENSIONS);
00206 void updateWrenchSpaces(std::vector<int> useDimensions = ALL_DIMENSIONS);
00207
00209 double getMaxRadius();
00211 position getCoG();
00212
00214 GWS *addGWS(const char *type);
00215 GWS *getGWS(const char *type);
00217 void removeGWS(GWS *gws);
00219 void addQM(QualityMeasure *qm);
00221 void replaceQM(int which,QualityMeasure *qm);
00223 QualityMeasure *getQM(int which);
00225 void removeQM(int which);
00226
00227 void addProjection(GWSprojection *gp);
00228 void removeProjection(GWSprojection *gp);
00229 static void destroyProjection(void * user, SoQtComponent * component);
00230
00232 void setGravity(bool g){useGravity = g;}
00233 bool isGravitySet(){return useGravity;}
00234
00235
00236
00237 static const int CONTACT_FORCE_EXISTENCE;
00238 static const int CONTACT_FORCE_OPTIMIZATION;
00239 static const int GRASP_FORCE_EXISTENCE;
00240 static const int GRASP_FORCE_OPTIMIZATION;
00241
00243 int computeQuasistaticForcesAndTorques(Matrix *robotTau, int computation);
00244
00246 int computeQuasistaticForces(const Matrix &robotTau);
00247
00249 std::list<Joint*> getJointsOnContactChains();
00250
00252 Matrix contactJacobian(const std::list<Joint*> &joints,
00253 const std::list< std::pair<transf, Link*> > &contact_locations);
00254
00256 Matrix contactJacobian(const std::list<Joint*> &joints,
00257 const std::list<Contact*> &contacts);
00258
00260 Matrix contactJacobian(const std::list<Joint*> &joints,
00261 const std::list<VirtualContact*> &contacts);
00262
00264 static Matrix graspMapMatrix(const Matrix &R, const Matrix &D);
00265
00267 void displayContactWrenches(std::list<Contact*> *contacts, const Matrix &contactWrenches);
00269 void accumulateAndDisplayObjectWrenches(std::list<Contact*> *contacts,
00270 const Matrix &objectWrenches);
00271 };
00272
00273 #define GRASP_HXX
00274 #endif