jntarrayvel.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /** \file itasc/kdl/jntarrayvel.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. JntArrayVel::JntArrayVel(unsigned int size):
  24. q(size),qdot(size)
  25. {
  26. }
  27. JntArrayVel::JntArrayVel(const JntArray& qin, const JntArray& qdotin):
  28. q(qin),qdot(qdotin)
  29. {
  30. assert(q.rows()==qdot.rows());
  31. }
  32. JntArrayVel::JntArrayVel(const JntArray& qin):
  33. q(qin),qdot(q.rows())
  34. {
  35. }
  36. JntArray JntArrayVel::value()const
  37. {
  38. return q;
  39. }
  40. JntArray JntArrayVel::deriv()const
  41. {
  42. return qdot;
  43. }
  44. void Add(const JntArrayVel& src1,const JntArrayVel& src2,JntArrayVel& dest)
  45. {
  46. Add(src1.q,src2.q,dest.q);
  47. Add(src1.qdot,src2.qdot,dest.qdot);
  48. }
  49. void Add(const JntArrayVel& src1,const JntArray& src2,JntArrayVel& dest)
  50. {
  51. Add(src1.q,src2,dest.q);
  52. dest.qdot=src1.qdot;
  53. }
  54. void Subtract(const JntArrayVel& src1,const JntArrayVel& src2,JntArrayVel& dest)
  55. {
  56. Subtract(src1.q,src2.q,dest.q);
  57. Subtract(src1.qdot,src2.qdot,dest.qdot);
  58. }
  59. void Subtract(const JntArrayVel& src1,const JntArray& src2,JntArrayVel& dest)
  60. {
  61. Subtract(src1.q,src2,dest.q);
  62. dest.qdot=src1.qdot;
  63. }
  64. void Multiply(const JntArrayVel& src,const double& factor,JntArrayVel& dest)
  65. {
  66. Multiply(src.q,factor,dest.q);
  67. Multiply(src.qdot,factor,dest.qdot);
  68. }
  69. void Multiply(const JntArrayVel& src,const doubleVel& factor,JntArrayVel& dest)
  70. {
  71. Multiply(src.q,factor.grad,dest.q);
  72. Multiply(src.qdot,factor.t,dest.qdot);
  73. Add(dest.qdot,dest.q,dest.qdot);
  74. Multiply(src.q,factor.t,dest.q);
  75. }
  76. void Divide(const JntArrayVel& src,const double& factor,JntArrayVel& dest)
  77. {
  78. Divide(src.q,factor,dest.q);
  79. Divide(src.qdot,factor,dest.qdot);
  80. }
  81. void Divide(const JntArrayVel& src,const doubleVel& factor,JntArrayVel& dest)
  82. {
  83. Multiply(src.q,(factor.grad/factor.t/factor.t),dest.q);
  84. Divide(src.qdot,factor.t,dest.qdot);
  85. Subtract(dest.qdot,dest.q,dest.qdot);
  86. Divide(src.q,factor.t,dest.q);
  87. }
  88. void SetToZero(JntArrayVel& array)
  89. {
  90. SetToZero(array.q);
  91. SetToZero(array.qdot);
  92. }
  93. bool Equal(const JntArrayVel& src1,const JntArrayVel& src2,double eps)
  94. {
  95. return Equal(src1.q,src2.q,eps)&&Equal(src1.qdot,src2.qdot,eps);
  96. }
  97. }