00001 /* Copyright (c) 2005 Arachi, Inc. and Stanford University. 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining 00004 * a copy of this software and associated documentation files (the 00005 * "Software"), to deal in the Software without restriction, including 00006 * without limitation the rights to use, copy, modify, merge, publish, 00007 * distribute, sublicense, and/or sell copies of the Software, and to 00008 * permit persons to whom the Software is furnished to do so, subject 00009 * to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 00018 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 00019 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 00020 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00021 */ 00022 00023 #ifndef _taoJoint_h 00024 #define _taoJoint_h 00025 00026 #include "taoDJoint.h" 00027 #include "taoVar.h" 00028 #include "taoTypes.h" 00029 #include "deMath.h" 00030 00031 class taoABJoint; 00032 class taoJCParam; 00033 00041 class taoJoint : public taoDJoint 00042 { 00043 public: 00044 taoJoint() : _type(TAO_JOINT_USER), _abJoint(NULL), _jcp(NULL), _clamp_dQ(0), _max_dQ(5), _damping(0), _inertia(0), _var(NULL), _next(NULL) {} 00045 virtual ~taoJoint(); 00046 00047 virtual deInt getDOF() = 0; 00048 virtual void reset() = 0; 00049 00050 virtual void setDVar(taoDVar* var) { _var = var; } 00051 virtual taoDVar* getDVar() { return _var; } 00052 00053 void setType(taoJointType t) { _type = t; } 00054 taoJointType getType() { return _type; } 00055 00056 void setABJoint(taoABJoint* joint) { _abJoint = joint; } 00057 taoABJoint* getABJoint() { return _abJoint; } 00058 00059 void setJCParam(taoJCParam* jcp) { _jcp = jcp; } 00060 taoJCParam* getJCParam() { return _jcp; } 00061 00062 void setDQclamp(deInt b) { _clamp_dQ = b; } 00063 deInt getDQclamp() { return _clamp_dQ; } 00064 00065 void setNext(taoJoint* joint) { _next = joint; } 00066 taoJoint* getNext() { return _next; } 00067 00068 virtual void setDQmax(deFloat dq) { _max_dQ = dq; } 00069 virtual deFloat getDQmax() { return _max_dQ; } 00070 00071 virtual void setDamping(deFloat d) { _damping = d; } 00072 virtual deFloat getDamping() { return _damping; } 00073 00074 virtual void setInertia(deFloat i) { _inertia = i; } 00075 virtual deFloat getInertia() { return _inertia; } 00076 00077 virtual void clampDQ() = 0; 00078 virtual void integrate(const deFloat dt) = 0; 00079 virtual void updateFrameLocal(deFrame* local) = 0; 00080 00081 virtual void setTau(const deFloat* v) = 0; 00082 virtual void setDDQ(const deFloat* v) = 0; 00083 virtual void setDQ(const deFloat* v) = 0; 00084 virtual void setQ(const deFloat* v) = 0; 00085 virtual void getTau(deFloat* v) = 0; 00086 virtual void getDDQ(deFloat* v) = 0; 00087 virtual void getDQ(deFloat* v) = 0; 00088 virtual void getQ(deFloat* v) = 0; 00089 00090 private: 00091 taoJointType _type; 00092 taoABJoint* _abJoint; 00093 taoJCParam* _jcp; 00094 00095 deInt _clamp_dQ; 00096 deFloat _max_dQ; 00097 00098 deFloat _damping; 00099 deFloat _inertia; 00100 00101 taoDVar* _var; 00102 taoJoint* _next; 00103 }; 00104 00112 class taoJointSpherical : public taoJoint 00113 { 00114 public: 00115 taoJointSpherical(); 00116 00117 virtual deInt getDOF() { return 3; } 00118 virtual void reset(); 00119 00120 virtual taoVarSpherical* getVarSpherical() { return (taoVarSpherical*)getDVar(); } 00121 00122 virtual void addQdelta(); 00123 virtual void addDQdelta(); 00124 virtual void zeroTau() { getVarSpherical()->_Tau.zero(); } 00125 virtual void setTau(const deFloat* v) { getVarSpherical()->_Tau.set(v); } 00126 virtual void setDDQ(const deFloat* v) { getVarSpherical()->_ddQ.set(v); } 00127 virtual void setDQ(const deFloat* v) { getVarSpherical()->_dQ.set(v); } 00128 virtual void setQ(const deFloat* v) { getVarSpherical()->_Q.set(v); } 00129 virtual void getTau(deFloat* v) { getVarSpherical()->_Tau.get(v); } 00130 virtual void getDDQ(deFloat* v) { getVarSpherical()->_ddQ.get(v); } 00131 virtual void getDQ(deFloat* v) { getVarSpherical()->_dQ.get(v); } 00132 virtual void getQ(deFloat* v) { deQuaternion& q = getVarSpherical()->_Q; v[0] = q[0]; v[1] = q[1]; v[2] = q[2]; v[3] = q[3]; } 00133 00134 virtual void clampDQ(); 00135 virtual void integrate(const deFloat dt); 00136 virtual void updateFrameLocal(deFrame* local) { local->rotation() = getVarSpherical()->_Q; } 00137 00138 virtual deMatrix3* getJg(); 00139 }; 00140 00148 class taoJointDOF1 : public taoJoint 00149 { 00150 public: 00151 taoJointDOF1(taoAxis axis) : _axis(axis) {} 00152 00153 taoAxis getAxis() const { return _axis; } 00154 virtual deInt getDOF() { return 1; } 00155 00156 virtual deVector6& getS(); 00157 00158 virtual void reset() 00159 { 00160 getVarDOF1()->_Q = 0; 00161 getVarDOF1()->_dQ = 0; 00162 getVarDOF1()->_ddQ = 0; 00163 getVarDOF1()->_Tau = 0; 00164 } 00165 00166 virtual taoVarDOF1* getVarDOF1() { return (taoVarDOF1*)getDVar(); } 00167 00168 virtual void addQdelta() { getVarDOF1()->_Q += getVarDOF1()->_ddQ; } 00169 virtual void addDQdelta() { getVarDOF1()->_dQ += getVarDOF1()->_ddQ; if (getDQclamp()) clampDQ(); } 00170 virtual void zeroTau() { getVarDOF1()->_Tau = 0; } 00171 virtual void setTau(const deFloat* v) { getVarDOF1()->_Tau = *v; } 00172 virtual void setDDQ(const deFloat* v) { getVarDOF1()->_ddQ = *v; } 00173 virtual void setDQ(const deFloat* v) { getVarDOF1()->_dQ = *v; } 00174 virtual void setQ(const deFloat* v) { getVarDOF1()->_Q = *v; } 00175 virtual void getTau(deFloat* v) { *v = getVarDOF1()->_Tau; } 00176 virtual void getDDQ(deFloat* v) { *v = getVarDOF1()->_ddQ; } 00177 virtual void getDQ(deFloat* v) { *v = getVarDOF1()->_dQ; } 00178 virtual void getQ(deFloat* v) { *v = getVarDOF1()->_Q; } 00179 00180 virtual void clampDQ(); 00181 virtual void integrate(const deFloat dt); 00182 00183 virtual deVector6& getJg(); 00184 00185 private: 00186 taoAxis _axis; 00187 }; 00188 00196 class taoJointPrismatic : public taoJointDOF1 00197 { 00198 public: 00199 taoJointPrismatic(taoAxis axis); 00200 virtual void updateFrameLocal(deFrame* local) 00201 { local->translation()[getAxis()] = getVarDOF1()->_Q; } 00202 }; 00203 00211 class taoJointRevolute : public taoJointDOF1 00212 { 00213 public: 00214 taoJointRevolute(taoAxis axis); 00215 virtual void updateFrameLocal(deFrame* local) 00216 { 00217 local->rotation().set(getAxis(), getVarDOF1()->_Q); 00218 } 00219 }; 00220 00228 class taoJointUser : public taoJointDOF1 00229 { 00230 public: 00231 taoJointUser(); 00232 //virtual void updateFrameLocal(deFrame* local) = 0; 00233 }; 00234 00235 #endif // _taoJoint_h