Blender V2.61 - r43446

jacobian.cpp

Go to the documentation of this file.
00001 
00004 // Copyright  (C)  2007  Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00005 
00006 // Version: 1.0
00007 // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00008 // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00009 // URL: http://www.orocos.org/kdl
00010 
00011 // This library is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU Lesser General Public
00013 // License as published by the Free Software Foundation; either
00014 // version 2.1 of the License, or (at your option) any later version.
00015 
00016 // This library is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00024 
00025 #include "jacobian.hpp"
00026 
00027 namespace KDL
00028 {
00029     Jacobian::Jacobian(unsigned int _size,unsigned int _nr_blocks):
00030         size(_size),nr_blocks(_nr_blocks)
00031     {
00032         twists = new Twist[size*nr_blocks];
00033     }
00034 
00035     Jacobian::Jacobian(const Jacobian& arg):
00036                        size(arg.columns()),
00037                        nr_blocks(arg.nr_blocks)
00038     {
00039         twists = new Twist[size*nr_blocks];
00040         for(unsigned int i=0;i<size*nr_blocks;i++)
00041             twists[i] = arg.twists[i];
00042     }
00043 
00044     Jacobian& Jacobian::operator = (const Jacobian& arg)
00045     {
00046         assert(size==arg.size);
00047         assert(nr_blocks==arg.nr_blocks);
00048         for(unsigned int i=0;i<size;i++)
00049             twists[i]=arg.twists[i];
00050         return *this;
00051     }
00052 
00053 
00054     Jacobian::~Jacobian()
00055     {
00056         delete [] twists;
00057     }
00058 
00059     double Jacobian::operator()(int i,int j)const
00060     {
00061         assert(i<6*(int)nr_blocks&&j<(int)size);
00062         return twists[j+6*(int)(floor((double)i/6))](i%6);
00063     }
00064 
00065     double& Jacobian::operator()(int i,int j)
00066     {
00067         assert(i<6*(int)nr_blocks&&j<(int)size);
00068         return twists[j+6*(int)(floor((double)i/6))](i%6);
00069     }
00070 
00071     unsigned int Jacobian::rows()const
00072     {
00073         return 6*nr_blocks;
00074     }
00075 
00076     unsigned int Jacobian::columns()const
00077     {
00078         return size;
00079     }
00080 
00081     void SetToZero(Jacobian& jac)
00082     {
00083         for(unsigned int i=0;i<jac.size*jac.nr_blocks;i++)
00084             SetToZero(jac.twists[i]);
00085     }
00086 
00087     void changeRefPoint(const Jacobian& src1, const Vector& base_AB, Jacobian& dest)
00088     {
00089         assert(src1.size==dest.size);
00090         assert(src1.nr_blocks==dest.nr_blocks);
00091         for(unsigned int i=0;i<src1.size*src1.nr_blocks;i++)
00092             dest.twists[i]=src1.twists[i].RefPoint(base_AB);
00093     }
00094 
00095     void changeBase(const Jacobian& src1, const Rotation& rot, Jacobian& dest)
00096     {
00097         assert(src1.size==dest.size);
00098         assert(src1.nr_blocks==dest.nr_blocks);
00099         for(unsigned int i=0;i<src1.size*src1.nr_blocks;i++)
00100             dest.twists[i]=rot*src1.twists[i];
00101     }
00102 
00103     void changeRefFrame(const Jacobian& src1,const Frame& frame, Jacobian& dest)
00104     {
00105         assert(src1.size==dest.size);
00106         assert(src1.nr_blocks==dest.nr_blocks);
00107         for(unsigned int i=0;i<src1.size*src1.nr_blocks;i++)
00108             dest.twists[i]=frame*src1.twists[i];
00109     }
00110 
00111     bool Jacobian::operator ==(const Jacobian& arg)
00112     {
00113         return Equal((*this),arg);
00114     }
00115     
00116     bool Jacobian::operator!=(const Jacobian& arg)
00117     {
00118         return !Equal((*this),arg);
00119     }
00120     
00121     bool Equal(const Jacobian& a,const Jacobian& b,double eps)
00122     {
00123         if(a.rows()==b.rows()&&a.columns()==b.columns()){
00124             bool rc=true;
00125             for(unsigned int i=0;i<a.columns();i++)
00126                 rc&=Equal(a.twists[i],b.twists[i],eps);
00127             return rc;
00128         }else
00129             return false;
00130     }
00131     
00132 }