jntarrayacc.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /** \file itasc/kdl/jntarrayacc.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 "jntarrayacc.hpp"
  21. namespace KDL
  22. {
  23. JntArrayAcc::JntArrayAcc(unsigned int size):
  24. q(size),qdot(size),qdotdot(size)
  25. {
  26. }
  27. JntArrayAcc::JntArrayAcc(const JntArray& qin, const JntArray& qdotin,const JntArray& qdotdotin):
  28. q(qin),qdot(qdotin),qdotdot(qdotdotin)
  29. {
  30. assert(q.rows()==qdot.rows()&&qdot.rows()==qdotdot.rows());
  31. }
  32. JntArrayAcc::JntArrayAcc(const JntArray& qin, const JntArray& qdotin):
  33. q(qin),qdot(qdotin),qdotdot(q.rows())
  34. {
  35. assert(q.rows()==qdot.rows());
  36. }
  37. JntArrayAcc::JntArrayAcc(const JntArray& qin):
  38. q(qin),qdot(q.rows()),qdotdot(q.rows())
  39. {
  40. }
  41. JntArray JntArrayAcc::value()const
  42. {
  43. return q;
  44. }
  45. JntArray JntArrayAcc::deriv()const
  46. {
  47. return qdot;
  48. }
  49. JntArray JntArrayAcc::dderiv()const
  50. {
  51. return qdotdot;
  52. }
  53. void Add(const JntArrayAcc& src1,const JntArrayAcc& src2,JntArrayAcc& dest)
  54. {
  55. Add(src1.q,src2.q,dest.q);
  56. Add(src1.qdot,src2.qdot,dest.qdot);
  57. Add(src1.qdotdot,src2.qdotdot,dest.qdotdot);
  58. }
  59. void Add(const JntArrayAcc& src1,const JntArrayVel& src2,JntArrayAcc& dest)
  60. {
  61. Add(src1.q,src2.q,dest.q);
  62. Add(src1.qdot,src2.qdot,dest.qdot);
  63. dest.qdotdot=src1.qdotdot;
  64. }
  65. void Add(const JntArrayAcc& src1,const JntArray& src2,JntArrayAcc& dest)
  66. {
  67. Add(src1.q,src2,dest.q);
  68. dest.qdot=src1.qdot;
  69. dest.qdotdot=src1.qdotdot;
  70. }
  71. void Subtract(const JntArrayAcc& src1,const JntArrayAcc& src2,JntArrayAcc& dest)
  72. {
  73. Subtract(src1.q,src2.q,dest.q);
  74. Subtract(src1.qdot,src2.qdot,dest.qdot);
  75. Subtract(src1.qdotdot,src2.qdotdot,dest.qdotdot);
  76. }
  77. void Subtract(const JntArrayAcc& src1,const JntArrayVel& src2,JntArrayAcc& dest)
  78. {
  79. Subtract(src1.q,src2.q,dest.q);
  80. Subtract(src1.qdot,src2.qdot,dest.qdot);
  81. dest.qdotdot=src1.qdotdot;
  82. }
  83. void Subtract(const JntArrayAcc& src1,const JntArray& src2,JntArrayAcc& dest)
  84. {
  85. Subtract(src1.q,src2,dest.q);
  86. dest.qdot=src1.qdot;
  87. dest.qdotdot=src1.qdotdot;
  88. }
  89. void Multiply(const JntArrayAcc& src,const double& factor,JntArrayAcc& dest)
  90. {
  91. Multiply(src.q,factor,dest.q);
  92. Multiply(src.qdot,factor,dest.qdot);
  93. Multiply(src.qdotdot,factor,dest.qdotdot);
  94. }
  95. void Multiply(const JntArrayAcc& src,const doubleVel& factor,JntArrayAcc& dest)
  96. {
  97. Multiply(src.qdot,factor.grad*2,dest.qdot);
  98. Multiply(src.qdotdot,factor.t,dest.qdotdot);
  99. Add(dest.qdot,dest.qdotdot,dest.qdotdot);
  100. Multiply(src.q,factor.grad,dest.q);
  101. Multiply(src.qdot,factor.t,dest.qdot);
  102. Add(dest.qdot,dest.q,dest.qdot);
  103. Multiply(src.q,factor.t,dest.q);
  104. }
  105. void Multiply(const JntArrayAcc& src,const doubleAcc& factor,JntArrayAcc& dest)
  106. {
  107. Multiply(src.q,factor.dd,dest.q);
  108. Multiply(src.qdot,factor.d*2,dest.qdot);
  109. Multiply(src.qdotdot,factor.t,dest.qdotdot);
  110. Add(dest.qdotdot,dest.qdot,dest.qdotdot);
  111. Add(dest.qdotdot,dest.q,dest.qdotdot);
  112. Multiply(src.q,factor.d,dest.q);
  113. Multiply(src.qdot,factor.t,dest.qdot);
  114. Add(dest.qdot,dest.q,dest.qdot);
  115. Multiply(src.q,factor.t,dest.q);
  116. }
  117. void Divide(const JntArrayAcc& src,const double& factor,JntArrayAcc& dest)
  118. {
  119. Divide(src.q,factor,dest.q);
  120. Divide(src.qdot,factor,dest.qdot);
  121. Divide(src.qdotdot,factor,dest.qdotdot);
  122. }
  123. void Divide(const JntArrayAcc& src,const doubleVel& factor,JntArrayAcc& dest)
  124. {
  125. Multiply(src.q,(2*factor.grad*factor.grad)/(factor.t*factor.t*factor.t),dest.q);
  126. Multiply(src.qdot,(2*factor.grad)/(factor.t*factor.t),dest.qdot);
  127. Divide(src.qdotdot,factor.t,dest.qdotdot);
  128. Subtract(dest.qdotdot,dest.qdot,dest.qdotdot);
  129. Add(dest.qdotdot,dest.q,dest.qdotdot);
  130. Multiply(src.q,factor.grad/(factor.t*factor.t),dest.q);
  131. Divide(src.qdot,factor.t,dest.qdot);
  132. Subtract(dest.qdot,dest.q,dest.qdot);
  133. Divide(src.q,factor.t,dest.q);
  134. }
  135. void Divide(const JntArrayAcc& src,const doubleAcc& factor,JntArrayAcc& dest)
  136. {
  137. Multiply(src.q,(2*factor.d*factor.d)/(factor.t*factor.t*factor.t)-factor.dd/(factor.t*factor.t),dest.q);
  138. Multiply(src.qdot,(2*factor.d)/(factor.t*factor.t),dest.qdot);
  139. Divide(src.qdotdot,factor.t,dest.qdotdot);
  140. Subtract(dest.qdotdot,dest.qdot,dest.qdotdot);
  141. Add(dest.qdotdot,dest.q,dest.qdotdot);
  142. Multiply(src.q,factor.d/(factor.t*factor.t),dest.q);
  143. Divide(src.qdot,factor.t,dest.qdot);
  144. Subtract(dest.qdot,dest.q,dest.qdot);
  145. Divide(src.q,factor.t,dest.q);
  146. }
  147. void SetToZero(JntArrayAcc& array)
  148. {
  149. SetToZero(array.q);
  150. SetToZero(array.qdot);
  151. SetToZero(array.qdotdot);
  152. }
  153. bool Equal(const JntArrayAcc& src1,const JntArrayAcc& src2,double eps)
  154. {
  155. return (Equal(src1.q,src2.q,eps)&&Equal(src1.qdot,src2.qdot,eps)&&Equal(src1.qdotdot,src2.qdotdot,eps));
  156. }
  157. }