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 HUMAN_HAND_H
00027 #define HUMAN_HAND_H
00028
00046 #include <vector>
00047 #include <limits>
00048 #include <set>
00049
00050 #include <Inventor/SoType.h>
00051 #include "robot.h"
00052
00053 class SoSeparator;
00054 class SoSphere;
00055 class SoCylinder;
00056 class SoTransform;
00057 class SoDrawStyle;
00058 class Tendon;
00059
00068 class TendonInsertionPoint {
00069 private:
00071 vec3 mAttachPoint;
00072
00074
00076 bool mPermanent;
00077
00079
00080 int mAttachChainNr;
00082 int mAttachLinkNr;
00083
00084 SoSeparator *mIVInsertion;
00085 SoMaterial *mIVInsertionMaterial;
00086 SoTransform *mIVInsertionTran;
00087 SoSphere *mIVInsertionGeom;
00088
00089 SoSeparator *mIVConnector;
00090 SoMaterial *mIVConnectorMaterial;
00091 SoTransform *mIVConnectorTran;
00092 SoCylinder *mIVConnectorGeom;
00093
00094 Tendon* mOwner;
00095
00096 void createInsertionGeometry();
00097 void createConnectorGeometry();
00098 public:
00099
00101 vec3 mInsertionForce;
00102
00103 TendonInsertionPoint(Tendon* myOwner,int chain,int link,vec3 point,bool isPerm=true);
00104
00105 void removeAllGeometry();
00106
00107 Tendon* getTendon(){return mOwner;}
00108
00109 void setPermanent(bool p){mPermanent=p;}
00110
00111 bool isPermanent() const {return mPermanent;}
00112
00113 SbVec3f getWorldPosition();
00114
00115 vec3 getAttachPoint() const {return mAttachPoint;}
00116
00117 void setAttachPoint(vec3 attachPoint);
00118
00120
00121 Link* getAttachedLink();
00122
00123 SoSeparator* getIVInsertion(){return mIVInsertion;}
00124 SoSphere* getIVInsertionGeom(){return mIVInsertionGeom;}
00125 SoMaterial* getIVInsertionMaterial(){return mIVInsertionMaterial;}
00126
00127 SoSeparator* getIVConnector(){return mIVConnector;}
00128 SoMaterial* getIVConnectorMaterial(){return mIVConnectorMaterial;}
00129 SoTransform* getIVConnectorTran(){return mIVConnectorTran;}
00130 SoCylinder* getIVConnectorGeom(){return mIVConnectorGeom;}
00131
00132 static const double INSERTION_POINT_RADIUS;
00133 static const double CONNECTOR_RADIUS;
00134 };
00135
00140 class TendonWrapper{
00141 private:
00142 int attachLinkNr;
00143 int attachChainNr;
00144 Robot *owner;
00145
00146 SoSeparator *IVWrapper;
00147 SoMaterial *IVWrapperMaterial;
00148 SoTransform *IVWrapperTran;
00149 SoCylinder *IVWrapperGeom;
00150
00152 std::list<QString> mExemptList;
00153
00154 public:
00155 vec3 location, orientation;
00156 double radius;
00157
00158 TendonWrapper(Robot* myOwner);
00159 Link* getAttachedLink();
00160 Robot* getRobot(){return owner;}
00161
00162 void setLocation(vec3 loc);
00163 vec3 getLocation() const {return location;}
00164
00165 void setOrientation(vec3 orient);
00166 vec3 getOrientation() const {return orientation;}
00167
00168 void setRadius(double r);
00169 double getRadius() const {return radius;}
00170
00171 void createGeometry();
00172 void updateGeometry();
00173 SoSeparator* getIVRoot(){return IVWrapper;}
00174 int getChainNr(){return attachChainNr;}
00175 int getLinkNr(){return attachLinkNr;}
00176 bool loadFromXml(const TiXmlElement* root);
00178 bool isExempt(QString name);
00179 };
00180
00182 class Tendon{
00183 private:
00184 Robot* mOwner;
00185
00186 SoSeparator *mIVRoot;
00187
00189 SoDrawStyle* mIVVisibleToggle;
00190
00192 SoSeparator* mIVForceIndRoot;
00193
00195 SoDrawStyle* mIVForceIndToggle;
00196
00198 SoMaterial *mIVForceIndMaterial;
00199
00201 SoSeparator *mIVForceIndicators;
00202
00204 float mActiveForce;
00205
00207 float mPassiveForce;
00208
00210 bool mApplyPassiveForce;
00211
00213 double mK;
00214
00216
00217 std::list<TendonInsertionPoint *> mInsPointList;
00218
00219 QString mTendonName;
00220
00221 bool mVisible;
00222
00223 bool mForcesVisible;
00224
00225 bool mSelected;
00226
00228 float mCurrentLength;
00229
00231 float mRestLength;
00232
00235 float mPreTensionLength;
00236
00238 float mDefaultRestLength;
00239
00240 void updateForceIndicators();
00241
00242 public:
00243
00244 Tendon(Robot* myOwner);
00245
00246 Robot *getRobot(){return mOwner;}
00247
00248 SoSeparator* getIVRoot(){return mIVRoot;}
00249
00251 void addInsertionPoint(int chain,int link,vec3 point, bool isPerm);
00252
00254 std::list<TendonInsertionPoint*>::iterator
00255 insertInsertionPoint(std::list<TendonInsertionPoint*>::iterator itPos,
00256 int chain, int link, vec3 point, bool isPerm);
00257
00259 std::list<TendonInsertionPoint*>::iterator
00260 removeInsertionPoint(std::list<TendonInsertionPoint*>::iterator itPos);
00261
00263 void updateGeometry();
00264
00266 void updateInsertionForces();
00267
00269 void computeSimplePassiveForces();
00270
00272 void checkWrapperIntersections();
00273
00275 void removeWrapperIntersections();
00276
00278 int getNumInsPoints() const {return mInsPointList.size();}
00279
00281 int getNumPermInsPoints() const;
00282
00284 TendonInsertionPoint* getPermInsPoint(int n);
00285
00287 void removeTemporaryInsertionPoints();
00288
00290 double minInsPointDistance();
00291
00292 void select();
00293 void deselect();
00294 bool isSelected(){return mSelected;}
00295
00296 void setActiveForce(float f);
00297
00298 void setPassiveForce(float f);
00299
00300 float getActiveForce(){return mActiveForce;}
00301
00302 float getPassiveForce(){return mPassiveForce;}
00303
00304 float getTotalForce(){if (mApplyPassiveForce) return mActiveForce+mPassiveForce; else return mActiveForce;}
00305
00306 void setStiffness(double k){mK = k;}
00307
00308 double getStiffness() {return mK;}
00309
00310 float getDefaultRestLength(){return mDefaultRestLength;}
00311
00312 void setDefaultRestLength(double l){mDefaultRestLength = l;}
00313
00314 float getPreTensionLength(){return mPreTensionLength;}
00315
00316 void setPreTensionLength(double l){mPreTensionLength = l;}
00317
00318 void setName(QString name){mTendonName=name;}
00319
00320 QString getName(){return mTendonName;}
00321
00322 void setVisible(bool v);
00323
00324 bool isVisible(){return mVisible;}
00325
00326 void setForcesVisible(bool v);
00327
00328 bool forcesVisible() {return mForcesVisible;}
00329
00331
00332 void applyForces();
00333
00334 void setApplyPassiveForce(bool b){mApplyPassiveForce=b;}
00335
00336
00337 void setRestLength(double length);
00338
00340
00342 float getExcursion(){return mCurrentLength - mRestLength;}
00343
00345 float getCurrentLength(){return mCurrentLength;}
00346
00347 bool loadFromXml(const TiXmlElement *root);
00348
00349 transf getInsertionPointWorldTransform(std::list<TendonInsertionPoint*>::iterator insPt);
00350
00352
00355 void getInsertionPointTransforms(std::vector<transf> &insPointTrans);
00356
00358 void getInsertionPointForceMagnitudes(std::vector<double> &magnitudes);
00359
00361 void getInsertionPointLinkTransforms(std::list< std::pair<transf, Link*> > &insPointLinkTrans);
00362
00364 bool insPointInsideWrapper();
00365 };
00366
00368
00374 class HumanHand : public Hand {
00375 Q_OBJECT
00376 protected:
00377 std::vector<Tendon *> mTendonVec;
00378
00379 std::vector<TendonWrapper *> mTendonWrapperVec;
00380
00382 void applyTendonForces();
00383
00384 public:
00385 HumanHand(World*,const char*);
00386 virtual ~HumanHand() {}
00387
00388 virtual int loadFromXml(const TiXmlElement* root,QString rootPath);
00389
00390 void updateTendonGeometry();
00391
00392 int getNumTendons(){return mTendonVec.size();}
00393
00394 int getNumTendonWrappers(){return mTendonWrapperVec.size();}
00395
00396 Tendon* getTendon(int i){return mTendonVec[i];}
00397
00398 TendonWrapper* getTendonWrapper(int i){return mTendonWrapperVec[i];}
00399
00400 void selectTendon(int i){mTendonVec[i]->select();}
00401
00402 void deselectTendon(int i){mTendonVec[i]->deselect();}
00403
00405 virtual void DOFController(double timeStep);
00406
00408
00410 int tendonEquilibrium(const std::set<size_t> &activeTendons,
00411 const std::set<size_t> &passiveTendons,
00412 bool compute_tendon_forces,
00413 std::vector<double> &activeTendonForces,
00414 std::vector<double> &jointResiduals,
00415 double& unbalanced_magnitude,
00416 bool useJointSprings = true);
00417
00418 int contactEquilibrium(std::list<Contact*> contacts,
00419 const std::set<size_t> &activeTendons,
00420 std::vector<double> &activeTendonForces,
00421 double &unbalanced_magnitude);
00422
00423 int contactForcesFromTendonForces(std::list<Contact*> contacts,
00424 std::vector<double> &contactForces,
00425 const std::set<size_t> &activeTendons,
00426 const std::vector<double> &activeTendonForces);
00427
00430 int contactTorques(std::list<Contact*> contacts,
00431 std::vector<double> &jointTorques);
00432
00434 bool insPointInsideWrapper();
00435
00438 void setRestPosition()
00439 {
00440 for(size_t i=0; i<mTendonVec.size(); i++)
00441 {
00442 if (mTendonVec[i]->getDefaultRestLength() < 0.0)
00443 {
00444 if (mTendonVec[i]->getPreTensionLength() < 0.0)
00445 {
00446 mTendonVec[i]->setRestLength( mTendonVec[i]->getCurrentLength() );
00447 }
00448 else
00449 {
00450 mTendonVec[i]->setRestLength( mTendonVec[i]->getCurrentLength() -
00451 mTendonVec[i]->getPreTensionLength() );
00452 }
00453 }
00454 else
00455 {
00456 mTendonVec[i]->setRestLength( mTendonVec[i]->getDefaultRestLength() );
00457 }
00458 }
00459 }
00460
00462 void removeTemporaryInsertionPoints()
00463 {
00464 for(size_t i=0; i<mTendonVec.size(); i++)
00465 {
00466 mTendonVec[i]->removeTemporaryInsertionPoints();
00467 }
00468 }
00469
00472 double minInsPointDistance()
00473 {
00474 double minDist = std::numeric_limits<double>::max();
00475 for(size_t i=0; i<mTendonVec.size(); i++)
00476 {
00477 minDist = std::min(minDist, mTendonVec[i]->minInsPointDistance());
00478 }
00479 return minDist;
00480 }
00481
00482 };
00483
00484 #endif