joint.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /** \file itasc/kdl/joint.cpp
  2. * \ingroup itasc
  3. */
  4. // Copyright (C) 2007 Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
  5. // Version: 1.0
  6. // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
  7. // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
  8. // URL: http://www.orocos.org/kdl
  9. // This library is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU Lesser General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2.1 of the License, or (at your option) any later version.
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Lesser General Public License for more details.
  17. // You should have received a copy of the GNU Lesser General Public
  18. // License along with this library; if not, write to the Free Software
  19. // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. #include "joint.hpp"
  21. namespace KDL {
  22. Joint::Joint(const JointType& _type, const double& _scale, const double& _offset,
  23. const double& _inertia, const double& _damping, const double& _stiffness):
  24. type(_type),scale(_scale),offset(_offset),inertia(_inertia),damping(_damping),stiffness(_stiffness)
  25. {
  26. // for sphere and swing, offset is not used, assume no offset
  27. }
  28. Joint::Joint(const Joint& in):
  29. type(in.type),scale(in.scale),offset(in.offset),
  30. inertia(in.inertia),damping(in.damping),stiffness(in.stiffness)
  31. {
  32. }
  33. Joint& Joint::operator=(const Joint& in)
  34. {
  35. type=in.type;
  36. scale=in.scale;
  37. offset=in.offset;
  38. inertia=in.inertia;
  39. damping=in.damping;
  40. stiffness=in.stiffness;
  41. return *this;
  42. }
  43. Joint::~Joint()
  44. {
  45. }
  46. Frame Joint::pose(const double* q)const
  47. {
  48. switch(type){
  49. case RotX:
  50. assert(q);
  51. return Frame(Rotation::RotX(scale*q[0]+offset));
  52. break;
  53. case RotY:
  54. assert(q);
  55. return Frame(Rotation::RotY(scale*q[0]+offset));
  56. break;
  57. case RotZ:
  58. assert(q);
  59. return Frame(Rotation::RotZ(scale*q[0]+offset));
  60. break;
  61. case TransX:
  62. assert(q);
  63. return Frame(Vector(scale*q[0]+offset,0.0,0.0));
  64. break;
  65. case TransY:
  66. assert(q);
  67. return Frame(Vector(0.0,scale*q[0]+offset,0.0));
  68. break;
  69. case TransZ:
  70. assert(q);
  71. return Frame(Vector(0.0,0.0,scale*q[0]+offset));
  72. break;
  73. case Sphere:
  74. // the joint angles represent a rotation vector expressed in the base frame of the joint
  75. // (= the frame you get when there is no offset nor rotation)
  76. assert(q);
  77. return Frame(Rot(Vector(q[0], q[1], q[2])));
  78. break;
  79. case Swing:
  80. // the joint angles represent a 2D rotation vector in the XZ planee of the base frame of the joint
  81. // (= the frame you get when there is no offset nor rotation)
  82. assert(q);
  83. return Frame(Rot(Vector(q[0], 0.0, q[1])));
  84. break;
  85. default:
  86. return Frame::Identity();
  87. break;
  88. }
  89. }
  90. Twist Joint::twist(const double& qdot, int dof)const
  91. {
  92. switch(type){
  93. case RotX:
  94. return Twist(Vector(0.0,0.0,0.0),Vector(scale*qdot,0.0,0.0));
  95. break;
  96. case RotY:
  97. return Twist(Vector(0.0,0.0,0.0),Vector(0.0,scale*qdot,0.0));
  98. break;
  99. case RotZ:
  100. return Twist(Vector(0.0,0.0,0.0),Vector(0.0,0.0,scale*qdot));
  101. break;
  102. case TransX:
  103. return Twist(Vector(scale*qdot,0.0,0.0),Vector(0.0,0.0,0.0));
  104. break;
  105. case TransY:
  106. return Twist(Vector(0.0,scale*qdot,0.0),Vector(0.0,0.0,0.0));
  107. break;
  108. case TransZ:
  109. return Twist(Vector(0.0,0.0,scale*qdot),Vector(0.0,0.0,0.0));
  110. break;
  111. case Swing:
  112. switch (dof) {
  113. case 0:
  114. return Twist(Vector(0.0,0.0,0.0),Vector(scale*qdot,0.0,0.0));
  115. case 1:
  116. return Twist(Vector(0.0,0.0,0.0),Vector(0.0,0.0,scale*qdot));
  117. }
  118. return Twist::Zero();
  119. case Sphere:
  120. switch (dof) {
  121. case 0:
  122. return Twist(Vector(0.0,0.0,0.0),Vector(scale*qdot,0.0,0.0));
  123. case 1:
  124. return Twist(Vector(0.0,0.0,0.0),Vector(0.0,scale*qdot,0.0));
  125. case 2:
  126. return Twist(Vector(0.0,0.0,0.0),Vector(0.0,0.0,scale*qdot));
  127. }
  128. return Twist::Zero();
  129. default:
  130. return Twist::Zero();
  131. break;
  132. }
  133. }
  134. unsigned int Joint::getNDof() const
  135. {
  136. switch (type) {
  137. case Sphere:
  138. return 3;
  139. case Swing:
  140. return 2;
  141. case None:
  142. return 0;
  143. default:
  144. return 1;
  145. }
  146. }
  147. } // end of namespace KDL