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 JOINT_H
00030
00031 #include <list>
00032 #include <vector>
00033
00034 #include "mytools.h"
00035 #include "matvec3D.h"
00036
00037 class KinematicChain;
00038 class DynJoint;
00039 class Robot;
00040 class Matrix;
00041
00042 class SoTransform;
00043 class TiXmlElement;
00044
00045 enum JointT {REVOLUTE,PRISMATIC};
00046
00048
00058 class DHTransform {
00059
00061 vec3 dtrans;
00062
00064 vec3 atrans;
00065
00067 transf tr4TimesTr3;
00068
00070 transf tr2;
00071
00073 transf tr1;
00074
00076 transf tran;
00077
00079 double theta;
00080
00082 double d;
00083
00085 double a;
00086
00088 double alpha;
00089
00090 public:
00091 DHTransform(double thval=0.0,double dval=0.0,double aval=0.0,
00092 double alval=0.0);
00093 DHTransform( const DHTransform *d ){
00094 memcpy( this, d, sizeof(DHTransform));
00095 }
00096
00098 double getD() const {return d;}
00099
00101 double getTheta() const {return theta;}
00102
00104 const transf& getTran() const {return tran;}
00105
00111 transf getTran(double thetaVal,double dVal) const
00112 {
00113 return tr4TimesTr3 * translate_transf(vec3(0,0,dVal)) *
00114 rotate_transf(thetaVal,vec3(0,0,1));
00115 }
00116
00117 void setD(double q);
00118 void setTheta(double q);
00119 };
00120
00122
00132 class Joint {
00133 protected:
00135 int DOFnum;
00136
00138 KinematicChain *owner;
00139
00141 int jointNum;
00142
00144 bool draggerAttached;
00145
00147 double dynamicsVal;
00148
00150 double velocity;
00151
00153 double minVal,maxVal;
00154
00156 double mCouplingRatio;
00157
00159 double c;
00160
00162 double f1;
00163
00165 double f0;
00166
00169 double mK;
00170
00172 double mRestVal;
00173
00175 vec3 worldAxis;
00176
00178 DHTransform *DH;
00179
00181 SoTransform *IVTran;
00182
00183 public:
00185 DynJoint *dynJoint;
00186
00189 Joint(KinematicChain *k) : DOFnum(0), owner(k), jointNum(-1), draggerAttached(false), dynamicsVal(0.0),
00190 velocity(0.0),minVal(0.0),maxVal(0.0),mCouplingRatio(1.0),c(0.0),f1(0.0),f0(0.0),mK(0.0),
00191 mRestVal(0.0), DH(NULL),
00192 IVTran(NULL), dynJoint(NULL) {IVTran = new SoTransform(); IVTran->ref();}
00193
00194 virtual ~Joint();
00195
00199 virtual int initJointFromXml(const TiXmlElement* root, int jnum) =0;
00200
00202 void cloneFrom(const Joint *original);
00203
00205 virtual int setVal(double q)=0;
00206
00208 void setMin(double min) {minVal = min;}
00209
00211 void setMax(double max) {maxVal = max;}
00212
00214 virtual void applyInternalWrench(double magnitude)=0;
00215
00217 virtual void applyPassiveInternalWrenches();
00218
00220 void setVelocity(double v) {velocity = v;}
00221
00223 void setDynamicsVal(double v) {dynamicsVal = v;}
00224
00227 void setWorldAxis(const vec3 &wa) {worldAxis = normalise(wa);}
00228
00230 void setDraggerAttached(bool b) {draggerAttached = b;}
00231
00233 void setSpringStiffness(double k) {mK = k;}
00234
00236 void setRestValue(double r){mRestVal = r;}
00237
00238
00239
00241 int getNum() const {return jointNum;}
00242
00244 int getChainNum() const;
00245
00247 virtual double getVal() const =0;
00248
00250 double getDisplacement() const {return getVal() - mRestVal;}
00251
00253 virtual JointT getType() const =0;
00254
00257 virtual transf getTran(double jointVal) const =0;
00258
00261 virtual transf getDynamicsTran() const =0;
00262
00264 int getDOFNum() const {return DOFnum;}
00265
00267 double getCouplingRatio() const {return mCouplingRatio;}
00268
00270 double getSpringStiffness() {return mK;}
00271
00273 double getOffset() const {return c;}
00274
00276 double getMin() const {return minVal;}
00277
00279 double getMax() const {return maxVal;}
00280
00282 double getVelocity() const {return velocity;}
00283
00287 double getFriction() const {
00288 return -f1 * velocity + (velocity<0 ? f0 : (velocity>0 ? -f0 : 0.0));
00289 }
00290
00294 double getSpringForce() const;
00295
00298 double getDynamicsVal() const {return dynamicsVal;}
00299
00301 transf const& getTran() const {return DH->getTran();}
00302
00304 vec3 const& getWorldAxis() const {return worldAxis;}
00305
00307 DHTransform *getDH() const {return DH;}
00308
00311 SoTransform *getIVTran() const {return IVTran;}
00312
00314 static Matrix jacobian(const Joint *joint, const transf &jointTran,
00315 const transf &toTarget, bool worldCoords);
00316 };
00317
00318
00320
00323 class PrismaticJoint : public Joint {
00324
00325 public:
00326
00328 PrismaticJoint(KinematicChain *k) : Joint(k) {}
00329
00330 virtual int initJointFromXml(const TiXmlElement* root, int jnum);
00331
00332 virtual void applyInternalWrench(double magnitude);
00333
00334 virtual int setVal(double q);
00335
00337 virtual double getVal() const {return DH->getD() - c;}
00338
00340 virtual JointT getType() const {return PRISMATIC;}
00341
00342 transf getTran(double jointVal) const {
00343 return DH->getTran(DH->getTheta(),jointVal + c);
00344 }
00345
00346 transf getDynamicsTran() const {
00347 return DH->getTran(DH->getTheta(),dynamicsVal);
00348 }
00349
00350 };
00351
00353
00356 class RevoluteJoint : public Joint {
00357
00358 public:
00359
00361 RevoluteJoint(KinematicChain *k) : Joint(k) {}
00362
00363 virtual int initJointFromXml(const TiXmlElement* root, int jnum);
00364
00366 virtual double getVal() const {return DH->getTheta() - c;}
00367
00368 virtual void applyInternalWrench(double magnitude);
00369
00370 virtual int setVal(double q);
00371
00373 virtual JointT getType() const {return REVOLUTE;}
00374
00375
00376 transf getTran(double jointVal) const {
00377 return DH->getTran(jointVal + c,DH->getD());
00378 }
00379 transf getDynamicsTran() const {
00380 return DH->getTran(dynamicsVal,DH->getD());
00381 }
00382
00383 };
00384
00385 #define JOINT_H
00386 #endif