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 CONTACT_HXX
00030
00031 #include <Inventor/nodes/SoSeparator.h>
00032 #include <list>
00033 #include <vector>
00034
00035 #include "collisionStructures.h"
00036
00037 class transf;
00038 class Body;
00039 class SoSeparator;
00040 class SoMaterial;
00041 class Matrix;
00042
00043 #ifdef ARIZONA_PROJECT_ENABLED
00044 #include <arizona/Arizona_Raw_Exp.h>
00045 #endif
00046
00047 #define DISPLAY_CONE_SCALE 20.0
00048 #define MAX_FRICTION_EDGES 100
00049
00050
00052 enum frictionT {FL,PCWF,SFCE,SFCL};
00053
00055 struct Wrench {
00056 vec3 force;
00057 vec3 torque;
00058 };
00059
00061
00095 class Contact
00096 {
00097 friend class VirtualContact;
00098
00099 protected:
00101 Body *body1;
00102
00104 Body *body2;
00105
00107 Contact *mate;
00108
00110 double cof;
00111
00113 double kcof;
00114
00116 frictionT frictionType;
00117
00119 int contactDim;
00120
00122 int lmiDim;
00123
00125 position loc;
00126
00128 vec3 normal;
00129
00131 transf frame;
00132
00134 transf body1Tran;
00135
00137 transf body2Tran;
00138
00140 SoSeparator *contactForcePointers;
00141
00143 double normalForceLimit;
00144
00146 double *optimalCoeffs;
00147
00149 double dynamicForce[6];
00150
00152 double prevCn;
00154 double prevLambda;
00156 double *prevBetas;
00158 bool inheritanceInfo;
00159
00161 bool mSlip;
00162
00164 void wrenchFromFrictionEdge(double *edge, const vec3 &radius, Wrench *wr);
00165
00167 int setUpFrictionEllipsoid(int numLatitudes,int numDirs[], double phi[],double eccen[]);
00168
00169 public:
00170
00172
00177 double frictionEdges[6*MAX_FRICTION_EDGES];
00178
00180 int numFrictionEdges;
00181
00183
00188 Wrench *wrench;
00189
00191 int numFCWrenches;
00192
00194 Contact() : body1(NULL),body2(NULL),mate(NULL),cof(0.0),
00195 contactForcePointers(NULL), optimalCoeffs(NULL), prevBetas(NULL), wrench(NULL) {}
00196
00198 Contact(Body *b1,Body *b2, position pos, vec3 norm);
00199
00201 virtual ~Contact();
00202
00204 virtual void computeWrenches();
00205
00207 virtual int setUpFrictionEdges(bool dynamicsOn = false)=0;
00208
00210 void setMate(Contact *m) {mate = m;}
00211
00213 position getPosition(){return loc;}
00214
00216 vec3 getNormal(){return normal;}
00217
00219 Contact *getMate() const {return mate;}
00220
00222 Body *getBody1() const {return body1;}
00223
00225 Body *getBody2() const {return body2;}
00226
00228 transf getBody1Tran() const {return body1Tran;}
00229
00231 transf getBody2Tran() const {return body2Tran;}
00232
00234 double getCof() const;
00235
00237 position getLocation() const {return loc;}
00238
00240 transf getFrame() const { return frame;}
00241
00243 void updateCof();
00244
00246 frictionT getFrictionType() const {return frictionType;}
00247
00249 transf getContactFrame() const {return frame;}
00250
00252 double *getDynamicContactWrench() {return dynamicForce;}
00253
00255 SoSeparator *getContactForcePointers() const {return contactForcePointers;}
00256
00258 bool preventsMotion(const transf& motion) const;
00259
00261 void setContactForce(double *optmx);
00262
00264 int getContactDim() const {return contactDim;}
00265
00267 int getLmiDim() const {return lmiDim;}
00268
00270 void setNormalForceLimit(double nfl) {normalForceLimit = nfl;}
00271
00273 double getNormalForceLimit() const {return normalForceLimit;}
00274
00275
00276
00278 Matrix frictionConstraintsMatrix() const;
00280 static Matrix frictionConstraintsBlockMatrix(const std::list<Contact*> &contacts);
00281
00283 Matrix frictionForceMatrix() const;
00285 static Matrix frictionForceBlockMatrix(const std::list<Contact*> &contacts);
00286
00288 Matrix localToWorldWrenchMatrix() const;
00290 static Matrix localToWorldWrenchBlockMatrix(const std::list<Contact*> &contacts);
00291
00293 static Matrix normalForceSumMatrix(const std::list<Contact*> &contacts);
00294
00295
00296
00298 void setDynamicContactWrench(double f[6])
00299 {memcpy(dynamicForce,f,6*sizeof(double));}
00300
00302 void setDynamicContactForce(const vec3 &force) {
00303 dynamicForce[0] = force.x(); dynamicForce[1] = force.y();dynamicForce[2] = force.z();
00304 dynamicForce[3] = dynamicForce[4] = dynamicForce[5] = 0;
00305 }
00306
00308 void inherit(Contact *c);
00309
00311 double getConstraintError();
00312
00314 static const double THRESHOLD;
00315
00317 static const double INHERITANCE_THRESHOLD;
00318
00320 static const double INHERITANCE_ANGULAR_THRESHOLD;
00321
00323 virtual SoSeparator* getVisualIndicator(){return NULL;}
00324
00326 double getPrevCn(){return prevCn;}
00328 double getPrevLambda(){return prevLambda;}
00330 double *getPrevBetas(){return prevBetas;}
00332 void setLCPInfo(double cn, double l, double *betas);
00333
00335 bool isSlipping() const {return mSlip;}
00336
00338 bool inherits(){return inheritanceInfo;}
00339
00341 SoMaterial *coneMat;
00343 float coneR, coneG, coneB;
00344 };
00345
00347
00352 class PointContact : public Contact
00353 {
00354 public:
00356 PointContact(Body *b1, Body *b2, position pos, vec3 norm);
00358 ~PointContact();
00360 int setUpFrictionEdges(bool dynamicsOn = false);
00362 SoSeparator* getVisualIndicator();
00363 };
00364
00366
00380 class SoftContact : public Contact
00381 {
00382 protected:
00384 vec3 *bodyNghbd;
00385
00387 int numPts;
00388
00390 double r1, r2;
00392 double a, b, c;
00393
00395 double relPhi;
00396
00398 mat3 fitRot;
00399
00401 double fitRotAngle;
00402
00404 double majorAxis;
00406 double minorAxis;
00407
00409 double r1prime;
00411 double r2prime;
00412
00413
00414
00415 int CalcRelPhi();
00416
00418 int CalcRprimes();
00419
00421 void FitPoints( );
00422
00424 double CalcContact_Mattress( double nForce );
00425
00426 public:
00428 SoftContact( Body *b1, Body *b2, position pos, vec3 norm, Neighborhood *bn );
00429
00431 ~SoftContact( );
00432
00434 int setUpFrictionEdges(bool dynamicsOn = false );
00435
00437 SoSeparator* getVisualIndicator();
00438
00440 virtual void computeWrenches();
00441 };
00442
00444
00473 class VirtualContact : public Contact
00474 {
00475 private:
00477 position mCenter;
00479 float mMaxRadius;
00480
00482 SoSeparator *mWorldInd;
00484 SoMaterial *mZaxisMat;
00485
00487 int mFingerNum;
00489 int mLinkNum;
00490
00492 void init();
00493 public:
00494
00496 VirtualContact();
00498 VirtualContact(int f, int l, Contact *original);
00500 VirtualContact(const VirtualContact *original);
00502 ~VirtualContact();
00503
00505 void setBody(Body *b){body1 = b;}
00507 void setObject(Body *b){body2 = b;}
00508
00510 void writeToFile(FILE *fp);
00512 void readFromFile(FILE *fp);
00513
00515 void computeWrenches(bool useObjectData = false, bool simply = false);
00516
00518 void scaleWrenches(double factor);
00519
00521 int setUpFrictionEdges(bool dynamicsOn = false);
00522
00524 void updateContact(Body* object);
00525
00527 void setRadius(float r){mMaxRadius = r;}
00529 void setCenter(position c){mCenter = c;}
00531 double getMaxRadius(){return mMaxRadius;}
00533 position getCenter(){return mCenter;}
00534
00536 SoSeparator* getVisualIndicator();
00538 void getWorldIndicator(bool useObjectData = false);
00539
00541 position getWorldLocation();
00543 vec3 getWorldNormal();
00545 void getObjectDistanceAndNormal(Body *body, vec3 *objDistance, vec3 *objNormal);
00546
00548 void mark(bool m);
00549
00551 int getFingerNum(){return mFingerNum;}
00553 int getLinkNum(){return mLinkNum;}
00554 };
00555
00556
00557
00558
00559 class VirtualContactOnObject : public VirtualContact
00560 {
00561 public:
00562 VirtualContactOnObject ();
00563 ~VirtualContactOnObject ();
00564 void readFromFile(FILE * fp);
00565 #ifdef ARIZONA_PROJECT_ENABLED
00566 void readFromRawData(ArizonaRawExp* are, QString file, int index, bool flipNormal = false);
00567 #endif
00568 void writeToFile(FILE * fp);
00569 };
00570 #define CONTACT_HXX
00571 #endif