SCL  1.0
Standard Control Library : Control, dynamics, physics, and simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
taoJoint.h
1 /* Copyright (c) 2005 Arachi, Inc. and Stanford University. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject
9  * to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
26 #ifndef _taoJoint_h
27 #define _taoJoint_h
28 
29 #include "taoDJoint.h"
30 #include "taoABJoint.h"
31 #include "taoVar.h"
32 #include "taoTypes.h"
33 #include <tao/matrix/TaoDeMath.h>
34 
35 #include <cassert>
36 #include <iostream>
37 
45 class taoJoint : public taoDJoint
46 {
47 public:
48  taoJoint() : _type(scl::JOINT_TYPE_NOTASSIGNED), _clamp_dQ(0), _max_dQ(5), _damping(0), _inertia(0), _var(NULL), _next(NULL) {}
49  virtual ~taoJoint();
50 
51  virtual deInt getDOF() = 0;
52  virtual void reset() = 0;
53 
54  virtual void setDVar(taoDVar* var) { _var = var; }
55  virtual taoDVar* getDVar() { return _var; }
56  virtual taoDVar const * getDVar() const { return _var; }
57 
58  void setType(scl::EJointType t) { _type = t; }
59  scl::EJointType getType() const { return _type; }
60 
61  virtual void setABJoint(taoABJoint* joint) = 0;
62  virtual taoABJoint* getABJoint() = 0;
63  virtual taoABJoint const * getABJoint() const = 0;
64 
65  void setDQclamp(deInt b) { _clamp_dQ = b; }
66  deInt getDQclamp() { return _clamp_dQ; }
67 
68  void setNext(taoJoint* joint) { _next = joint; }
69  taoJoint* getNext() { return _next; }
70 
71  virtual void setDQmax(deFloat dq) { _max_dQ = dq; }
72  virtual deFloat getDQmax() { return _max_dQ; }
73 
74  virtual void setDamping(deFloat d) { _damping = d; }
75  virtual deFloat getDamping() { return _damping; }
76 
77  virtual void setInertia(deFloat i) { _inertia = i; }
78  virtual deFloat getInertia() { return _inertia; }
79 
80  virtual void clampDQ() = 0;
81  virtual void integrate(const deFloat dt) = 0;
82  virtual void updateFrameLocal(deFrame* local) = 0;
83 
85  virtual void setTau(const deFloat* v) = 0;
86  virtual void zeroTau() = 0;
87 
89  virtual void setDDQ(const deFloat* v) = 0;
90  virtual void zeroDDQ() = 0;
91 
93  virtual void setDQ(const deFloat* v) = 0;
94  virtual void zeroDQ() = 0;
95 
97  virtual void setQ(const deFloat* v) = 0;
98  virtual void zeroQ() = 0;
99 
101  virtual void getTau(deFloat* v) const = 0;
102 
104  virtual void getDDQ(deFloat* v) const = 0;
105 
107  virtual void getDQ(deFloat* v) const = 0;
108 
110  virtual void getQ(deFloat* v) const = 0;
111 
123  virtual void getJgColumns(deVector6 * Jg_columns) const = 0;
124 
125 private:
126  scl::EJointType _type;
127 
128  deInt _clamp_dQ;
129  deFloat _max_dQ;
130 
131  deFloat _damping;
132  deFloat _inertia;
133 
134  taoDVar* _var;
143 };
144 
153 {
154 public:
156 
157  virtual deInt getDOF() { return 3; }
158  virtual void reset();
159 
160  virtual taoVarSpherical* getVarSpherical() { return (taoVarSpherical*)getDVar(); }
161  virtual taoVarSpherical const * getVarSpherical() const { return (taoVarSpherical*)getDVar(); }
162 
163  virtual void setABJoint(taoABJoint* joint)
164  {
165  taoABJointSpherical * tmp = dynamic_cast<taoABJointSpherical *>(joint);
166  if(NULL == tmp)
167  {
168  std::cout <<"\ntaoJointPrismatic::setABJoint(): Incorrect joint type passed. Can't set ABJoint";
169  assert(false);
170  }
171  if(NULL== _abJoint) { delete _abJoint; }
172  _abJoint = tmp;
173  }
174 
175  virtual taoABJoint* getABJoint(){ return _abJoint; }
176  virtual taoABJoint const * getABJoint() const { return _abJoint; }
177 
178  virtual void addQdelta();
179  virtual void addDQdelta();
180  virtual void zeroTau() { getVarSpherical()->force_gc_.zero(); }
181  virtual void zeroDDQ() { getVarSpherical()->ddq_.zero(); }
182  virtual void zeroDQ() { getVarSpherical()->dq_.zero(); getVarSpherical()->dq_rotated_.zero(); }
183  virtual void zeroQ() { getVarSpherical()->q_quat_.identity(); }
184  virtual void setTau(const deFloat* v) { getVarSpherical()->force_gc_.set(v); }
185  virtual void setDDQ(const deFloat* v) { getVarSpherical()->ddq_.set(v); }
186  virtual void setDQ(const deFloat* v) { getVarSpherical()->dq_.set(v); }
187  virtual void setQ(const deFloat* v) { getVarSpherical()->q_quat_.set(v); }
188  virtual void getTau(deFloat* v) const { getVarSpherical()->force_gc_.get(v); }
189  virtual void getDDQ(deFloat* v) const { getVarSpherical()->ddq_.get(v); }
190  virtual void getDQ(deFloat* v) const { getVarSpherical()->dq_.get(v); }
191  virtual void getQ(deFloat* v) const { deQuaternion const & q = getVarSpherical()->q_quat_; v[0] = q[0]; v[1] = q[1]; v[2] = q[2]; v[3] = q[3]; }
192 
193  virtual void clampDQ();
194  virtual void integrate(const deFloat dt);
195  virtual void updateFrameLocal(deFrame* local) { local->rotation() = getVarSpherical()->q_quat_; }
196 
235  virtual deMatrix3* getJg();
236 
241  virtual void getJgColumns(deVector6 * Jg_columns) const;
242 
243 protected:
244  taoABJointSpherical * _abJoint;
245 
246 };
247 
255 class taoJointDOF1 : public taoJoint
256 {
257 public:
258  taoJointDOF1(taoJointType axis) : _axis(axis) {}
259 
260  taoJointType getJointType() const { return _axis; }
261  virtual deInt getDOF() { return 1; }
262 
263  virtual deVector6& getS();
264 
265  virtual void reset()
266  {
267  getVarDOF1()->q_ = 0;
268  getVarDOF1()->dq_ = 0;
269  getVarDOF1()->ddq_ = 0;
270  getVarDOF1()->tau_ = 0;
271  }
272 
273  virtual taoVarDOF1* getVarDOF1() { return (taoVarDOF1*)getDVar(); }
274  virtual taoVarDOF1 const * getVarDOF1() const { return (taoVarDOF1*)getDVar(); }
275 
276  virtual void addQdelta() { getVarDOF1()->q_ += getVarDOF1()->ddq_; }
277  virtual void addDQdelta() { getVarDOF1()->dq_ += getVarDOF1()->ddq_; if (getDQclamp()) clampDQ(); }
278  virtual void zeroTau() { getVarDOF1()->tau_ = 0; }
279  virtual void zeroDDQ() { getVarDOF1()->ddq_ = 0; }
280  virtual void zeroDQ() { getVarDOF1()->dq_ = 0; }
281  virtual void zeroQ() { getVarDOF1()->q_ = 0; }
282 
283  virtual void setTau(const deFloat* v) { getVarDOF1()->tau_ = *v; }
284  virtual void setDDQ(const deFloat* v) { getVarDOF1()->ddq_ = *v; }
285  virtual void setDQ(const deFloat* v) { getVarDOF1()->dq_ = *v; }
286  virtual void setQ(const deFloat* v) { getVarDOF1()->q_ = *v; }
287  virtual void getTau(deFloat* v) const { *v = getVarDOF1()->tau_; }
288  virtual void getDDQ(deFloat* v) const { *v = getVarDOF1()->ddq_; }
289  virtual void getDQ(deFloat* v) const { *v = getVarDOF1()->dq_; }
290  virtual void getQ(deFloat* v) const { *v = getVarDOF1()->q_; }
291 
292  virtual void clampDQ();
293  virtual void integrate(const deFloat dt);
294 
305  virtual deVector6& getJg() const;
306 
310  virtual void getJgColumns(deVector6 * Jg_columns) const;
311 
312 private:
313  taoJointType _axis;
314 };
315 
324 {
325 public:
326  taoJointPrismatic(taoJointType axis);
327  virtual void updateFrameLocal(deFrame* local)
328  { local->translation()[getJointType()] = getVarDOF1()->q_; }
329 
330  virtual void setABJoint(taoABJoint* joint)
331  {
332  taoABJointPrismatic * tmp = dynamic_cast<taoABJointPrismatic *>(joint);
333  if(NULL == tmp)
334  {
335  std::cout <<"\ntaoJointPrismatic::setABJoint(): Incorrect joint type passed. Can't set ABJoint";
336  assert(false);
337  }
338  if(NULL== _abJoint) { delete _abJoint; }
339  _abJoint = tmp;
340  }
341 
342  virtual taoABJoint* getABJoint(){ return _abJoint; }
343  virtual taoABJoint const * getABJoint() const { return _abJoint; }
344 
345 protected:
346  taoABJointPrismatic *_abJoint;
347 };
348 
357 {
358 public:
359  taoJointRevolute(taoJointType axis);
360  virtual void updateFrameLocal(deFrame* local)
361  {
362  local->rotation().set(getJointType(), getVarDOF1()->q_);
363  }
364 
365  virtual void setABJoint(taoABJoint* joint)
366  {
367  taoABJointRevolute * tmp = dynamic_cast<taoABJointRevolute *>(joint);
368  if(NULL == tmp)
369  {
370  std::cout <<"\ntaoJointPrismatic::setABJoint(): Incorrect joint type passed. Can't set ABJoint";
371  assert(false);
372  }
373  if(NULL== _abJoint) { delete _abJoint; }
374  _abJoint = tmp;
375  }
376 
377  virtual taoABJoint* getABJoint(){ return _abJoint; }
378  virtual taoABJoint const * getABJoint() const { return _abJoint; }
379 
380 protected:
381  taoABJointRevolute *_abJoint;
382 };
383 
392 {
393 public:
394  taoJointUser();
395  //virtual void updateFrameLocal(deFrame* local) = 0;
396 
397 
398  virtual void setABJoint(taoABJoint* joint)
399  {
400  if(NULL== _abJoint) { delete _abJoint; }
401  _abJoint = joint;
402  }
403 
404  virtual taoABJoint* getABJoint(){ return _abJoint; }
405  virtual taoABJoint const * getABJoint() const { return _abJoint; }
406 
407 protected:
408  taoABJoint* _abJoint;
409 };
410 
411 #endif // _taoJoint_h
virtual void getQ(deFloat *v) const
Definition: taoJoint.h:191
deQuaternion q_quat_
joint position
Definition: taoVar.h:71
1-DOF joint variable class for articulated bodyThis provides joint variables necessary for articulate...
Definition: taoVar.h:53
abstract joint class for articulated bodyThis class should be used as a base class and implemented ac...
Definition: taoDJoint.h:43
Definition: taoABJoint.h:285
virtual void getJgColumns(deVector6 *Jg_columns) const =0
virtual void setTau(const deFloat *v)
Definition: taoJoint.h:283
virtual void getDQ(deFloat *v) const
Definition: taoJoint.h:289
virtual void setTau(const deFloat *v)=0
deFloat dq_
joint velocity
Definition: taoVar.h:57
virtual void setDDQ(const deFloat *v)
Definition: taoJoint.h:185
deQuaternion & rotation()
Definition: TaoDeFrame.h:49
deVector3 dq_rotated_
joint velocity in reference (parent) frame
Definition: taoVar.h:75
User defined joint class for articulated bodyThis provides a user defined joint for articulated body ...
Definition: taoJoint.h:391
virtual void getDDQ(deFloat *v) const =0
virtual void setDQ(const deFloat *v)
Definition: taoJoint.h:186
virtual void setTau(const deFloat *v)
Definition: taoJoint.h:184
Articulated body joint classThis class provides joint for articulated body.
Definition: taoABJoint.h:45
deFloat q_
joint position
Definition: taoVar.h:56
deFloat ddq_
joint acceleration
Definition: taoVar.h:58
virtual void getTau(deFloat *v) const
Definition: taoJoint.h:287
6x1 vector classThis class consists of two 3x1 vectors.
Definition: TaoDeVector6.h:33
spherical joint variable class for articulated bodyThis provides joint variables necessary for articu...
Definition: taoVar.h:68
virtual ~taoJoint()
Definition: taoJoint.cpp:29
deVector3 ddq_
joint acceleration
Definition: taoVar.h:73
virtual void setDQ(const deFloat *v)=0
1 DOF joint class for articulated bodyThis provides a 1-DOF joint for articulated body dynamics ...
Definition: taoJoint.h:255
deFloat tau_
joint force (torque)
Definition: taoVar.h:59
DE_MATH_API void get(deFloat *v) const
[x y z] = this
Definition: TaoDeVector3Inl.h:42
virtual void setDQ(const deFloat *v)
Definition: taoJoint.h:285
virtual void getTau(deFloat *v) const
Definition: taoJoint.h:188
virtual void getJgColumns(deVector6 *Jg_columns) const
Definition: taoJoint.cpp:146
Quaternion classThis is a C++ wrapper class of deQuaternionf.
Definition: TaoDeQuaternion.h:35
virtual void setQ(const deFloat *v)
Definition: taoJoint.h:286
DE_MATH_API void set(const deFloat x, const deFloat y, const deFloat z)
this = (x, y, z)
Definition: TaoDeVector3Inl.h:40
virtual void getJgColumns(deVector6 *Jg_columns) const
Definition: taoJoint.cpp:127
Transformation class using quaternionThis class consists of a quaternion for rotation and a vector fo...
Definition: TaoDeFrame.h:36
virtual void setQ(const deFloat *v)=0
abstract joint variable class for articulated bodyThis class should be used as a base class and imple...
Definition: taoVar.h:42
virtual deMatrix3 * getJg()
Definition: taoJoint.cpp:122
Prismatic joint class for articulated bodyThis provides a prismatic joint for articulated body dynami...
Definition: taoJoint.h:323
deVector3 & translation()
Definition: TaoDeFrame.h:53
Revolute joint class for articulated bodyThis provides a revolute joint for articulated body dynamics...
Definition: taoJoint.h:356
virtual void getQ(deFloat *v) const =0
deVector3 force_gc_
joint force (torque)
Definition: taoVar.h:74
Base joint class for articulated bodyThis provides a joint for articulated body dynamics.
Definition: taoJoint.h:45
virtual void setQ(const deFloat *v)
Definition: taoJoint.h:187
virtual void getDQ(deFloat *v) const
Definition: taoJoint.h:190
DE_MATH_API void identity()
this = (0, 0, 0, 1)
Definition: TaoDeQuaternionInl.h:33
virtual void getDQ(deFloat *v) const =0
Spherical joint class for articulated bodyThis provides a spherical joint for articulated body dynami...
Definition: taoJoint.h:152
virtual void setDDQ(const deFloat *v)
Definition: taoJoint.h:284
virtual void getDDQ(deFloat *v) const
Definition: taoJoint.h:288
3x3 matrix classThis is a C++ wrapper class of deMatrix3f.
Definition: TaoDeMatrix3.h:33
virtual void addQdelta()
Definition: taoJoint.cpp:50
virtual void getDDQ(deFloat *v) const
Definition: taoJoint.h:189
EJointType
Definition: DataTypes.hpp:110
Definition: taoABJoint.h:171
virtual deVector6 & getJg() const
Definition: taoJoint.cpp:141
deVector3 dq_
joint velocity in local frame
Definition: taoVar.h:72
virtual void getTau(deFloat *v) const =0
virtual void setDDQ(const deFloat *v)=0
virtual void getQ(deFloat *v) const
Definition: taoJoint.h:290
taoJoint * _next
Definition: taoJoint.h:142
DE_MATH_API void zero()
this = 0
Definition: TaoDeVector3Inl.h:38
DE_MATH_API void set(const deMatrix3 &m)
this = m
Definition: TaoDeQuaternionInl.h:37
Definition: taoABJoint.h:264