jacobian.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /** \file itasc/kdl/jacobian.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 "jacobian.hpp"
  21. namespace KDL
  22. {
  23. Jacobian::Jacobian(unsigned int _size,unsigned int _nr_blocks):
  24. size(_size),nr_blocks(_nr_blocks)
  25. {
  26. twists = new Twist[size*nr_blocks];
  27. }
  28. Jacobian::Jacobian(const Jacobian& arg):
  29. size(arg.columns()),
  30. nr_blocks(arg.nr_blocks)
  31. {
  32. twists = new Twist[size*nr_blocks];
  33. for(unsigned int i=0;i<size*nr_blocks;i++)
  34. twists[i] = arg.twists[i];
  35. }
  36. Jacobian& Jacobian::operator = (const Jacobian& arg)
  37. {
  38. assert(size==arg.size);
  39. assert(nr_blocks==arg.nr_blocks);
  40. for(unsigned int i=0;i<size;i++)
  41. twists[i]=arg.twists[i];
  42. return *this;
  43. }
  44. Jacobian::~Jacobian()
  45. {
  46. delete [] twists;
  47. }
  48. double Jacobian::operator()(int i,int j)const
  49. {
  50. assert(i<6*(int)nr_blocks&&j<(int)size);
  51. return twists[j+6*(int)(floor((double)i/6))](i%6);
  52. }
  53. double& Jacobian::operator()(int i,int j)
  54. {
  55. assert(i<6*(int)nr_blocks&&j<(int)size);
  56. return twists[j+6*(int)(floor((double)i/6))](i%6);
  57. }
  58. unsigned int Jacobian::rows()const
  59. {
  60. return 6*nr_blocks;
  61. }
  62. unsigned int Jacobian::columns()const
  63. {
  64. return size;
  65. }
  66. void SetToZero(Jacobian& jac)
  67. {
  68. for(unsigned int i=0;i<jac.size*jac.nr_blocks;i++)
  69. SetToZero(jac.twists[i]);
  70. }
  71. void changeRefPoint(const Jacobian& src1, const Vector& base_AB, Jacobian& dest)
  72. {
  73. assert(src1.size==dest.size);
  74. assert(src1.nr_blocks==dest.nr_blocks);
  75. for(unsigned int i=0;i<src1.size*src1.nr_blocks;i++)
  76. dest.twists[i]=src1.twists[i].RefPoint(base_AB);
  77. }
  78. void changeBase(const Jacobian& src1, const Rotation& rot, Jacobian& dest)
  79. {
  80. assert(src1.size==dest.size);
  81. assert(src1.nr_blocks==dest.nr_blocks);
  82. for(unsigned int i=0;i<src1.size*src1.nr_blocks;i++)
  83. dest.twists[i]=rot*src1.twists[i];
  84. }
  85. void changeRefFrame(const Jacobian& src1,const Frame& frame, Jacobian& dest)
  86. {
  87. assert(src1.size==dest.size);
  88. assert(src1.nr_blocks==dest.nr_blocks);
  89. for(unsigned int i=0;i<src1.size*src1.nr_blocks;i++)
  90. dest.twists[i]=frame*src1.twists[i];
  91. }
  92. bool Jacobian::operator ==(const Jacobian& arg)
  93. {
  94. return Equal((*this),arg);
  95. }
  96. bool Jacobian::operator!=(const Jacobian& arg)
  97. {
  98. return !Equal((*this),arg);
  99. }
  100. bool Equal(const Jacobian& a,const Jacobian& b,double eps)
  101. {
  102. if(a.rows()==b.rows()&&a.columns()==b.columns()){
  103. bool rc=true;
  104. for(unsigned int i=0;i<a.columns();i++)
  105. rc&=Equal(a.twists[i],b.twists[i],eps);
  106. return rc;
  107. }else
  108. return false;
  109. }
  110. }