Blender V2.61 - r43446

jntarrayacc.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 "jntarrayacc.hpp"
00026 
00027 namespace KDL
00028 {
00029     JntArrayAcc::JntArrayAcc(unsigned int size):
00030         q(size),qdot(size),qdotdot(size)
00031     {
00032     }
00033     JntArrayAcc::JntArrayAcc(const JntArray& qin, const JntArray& qdotin,const JntArray& qdotdotin):
00034         q(qin),qdot(qdotin),qdotdot(qdotdotin)
00035     {
00036         assert(q.rows()==qdot.rows()&&qdot.rows()==qdotdot.rows());
00037     }
00038     JntArrayAcc::JntArrayAcc(const JntArray& qin, const JntArray& qdotin):
00039         q(qin),qdot(qdotin),qdotdot(q.rows())
00040     {
00041         assert(q.rows()==qdot.rows());
00042     }
00043     JntArrayAcc::JntArrayAcc(const JntArray& qin):
00044         q(qin),qdot(q.rows()),qdotdot(q.rows())
00045     {
00046     }
00047 
00048     JntArray JntArrayAcc::value()const
00049     {
00050         return q;
00051     }
00052 
00053     JntArray JntArrayAcc::deriv()const
00054     {
00055         return qdot;
00056     }
00057     JntArray JntArrayAcc::dderiv()const
00058     {
00059         return qdotdot;
00060     }
00061 
00062     void Add(const JntArrayAcc& src1,const JntArrayAcc& src2,JntArrayAcc& dest)
00063     {
00064         Add(src1.q,src2.q,dest.q);
00065         Add(src1.qdot,src2.qdot,dest.qdot);
00066         Add(src1.qdotdot,src2.qdotdot,dest.qdotdot);
00067     }
00068     void Add(const JntArrayAcc& src1,const JntArrayVel& src2,JntArrayAcc& dest)
00069     {
00070         Add(src1.q,src2.q,dest.q);
00071         Add(src1.qdot,src2.qdot,dest.qdot);
00072         dest.qdotdot=src1.qdotdot;
00073     }
00074     void Add(const JntArrayAcc& src1,const JntArray& src2,JntArrayAcc& dest)
00075     {
00076         Add(src1.q,src2,dest.q);
00077         dest.qdot=src1.qdot;
00078         dest.qdotdot=src1.qdotdot;
00079     }
00080 
00081     void Subtract(const JntArrayAcc& src1,const JntArrayAcc& src2,JntArrayAcc& dest)
00082     {
00083         Subtract(src1.q,src2.q,dest.q);
00084         Subtract(src1.qdot,src2.qdot,dest.qdot);
00085         Subtract(src1.qdotdot,src2.qdotdot,dest.qdotdot);
00086     }
00087     void Subtract(const JntArrayAcc& src1,const JntArrayVel& src2,JntArrayAcc& dest)
00088     {
00089         Subtract(src1.q,src2.q,dest.q);
00090         Subtract(src1.qdot,src2.qdot,dest.qdot);
00091         dest.qdotdot=src1.qdotdot;
00092     }
00093     void Subtract(const JntArrayAcc& src1,const JntArray& src2,JntArrayAcc& dest)
00094     {
00095         Subtract(src1.q,src2,dest.q);
00096         dest.qdot=src1.qdot;
00097         dest.qdotdot=src1.qdotdot;
00098     }
00099 
00100     void Multiply(const JntArrayAcc& src,const double& factor,JntArrayAcc& dest)
00101     {
00102         Multiply(src.q,factor,dest.q);
00103         Multiply(src.qdot,factor,dest.qdot);
00104         Multiply(src.qdotdot,factor,dest.qdotdot);
00105     }
00106     void Multiply(const JntArrayAcc& src,const doubleVel& factor,JntArrayAcc& dest)
00107     {
00108         Multiply(src.qdot,factor.grad*2,dest.qdot);
00109         Multiply(src.qdotdot,factor.t,dest.qdotdot);
00110         Add(dest.qdot,dest.qdotdot,dest.qdotdot);
00111         Multiply(src.q,factor.grad,dest.q);
00112         Multiply(src.qdot,factor.t,dest.qdot);
00113         Add(dest.qdot,dest.q,dest.qdot);
00114         Multiply(src.q,factor.t,dest.q);
00115     }
00116     void Multiply(const JntArrayAcc& src,const doubleAcc& factor,JntArrayAcc& dest)
00117     {
00118         Multiply(src.q,factor.dd,dest.q);
00119         Multiply(src.qdot,factor.d*2,dest.qdot);
00120         Multiply(src.qdotdot,factor.t,dest.qdotdot);
00121         Add(dest.qdotdot,dest.qdot,dest.qdotdot);
00122         Add(dest.qdotdot,dest.q,dest.qdotdot);
00123         Multiply(src.q,factor.d,dest.q);
00124         Multiply(src.qdot,factor.t,dest.qdot);
00125         Add(dest.qdot,dest.q,dest.qdot);
00126         Multiply(src.q,factor.t,dest.q);
00127     }
00128 
00129     void Divide(const JntArrayAcc& src,const double& factor,JntArrayAcc& dest)
00130     {
00131         Divide(src.q,factor,dest.q);
00132         Divide(src.qdot,factor,dest.qdot);
00133         Divide(src.qdotdot,factor,dest.qdotdot);
00134     }
00135     void Divide(const JntArrayAcc& src,const doubleVel& factor,JntArrayAcc& dest)
00136     {
00137         Multiply(src.q,(2*factor.grad*factor.grad)/(factor.t*factor.t*factor.t),dest.q);
00138         Multiply(src.qdot,(2*factor.grad)/(factor.t*factor.t),dest.qdot);
00139         Divide(src.qdotdot,factor.t,dest.qdotdot);
00140         Subtract(dest.qdotdot,dest.qdot,dest.qdotdot);
00141         Add(dest.qdotdot,dest.q,dest.qdotdot);
00142         Multiply(src.q,factor.grad/(factor.t*factor.t),dest.q);
00143         Divide(src.qdot,factor.t,dest.qdot);
00144         Subtract(dest.qdot,dest.q,dest.qdot);
00145         Divide(src.q,factor.t,dest.q);
00146     }
00147     void Divide(const JntArrayAcc& src,const doubleAcc& factor,JntArrayAcc& dest)
00148     {
00149         Multiply(src.q,(2*factor.d*factor.d)/(factor.t*factor.t*factor.t)-factor.dd/(factor.t*factor.t),dest.q);
00150         Multiply(src.qdot,(2*factor.d)/(factor.t*factor.t),dest.qdot);
00151         Divide(src.qdotdot,factor.t,dest.qdotdot);
00152         Subtract(dest.qdotdot,dest.qdot,dest.qdotdot);
00153         Add(dest.qdotdot,dest.q,dest.qdotdot);
00154         Multiply(src.q,factor.d/(factor.t*factor.t),dest.q);
00155         Divide(src.qdot,factor.t,dest.qdot);
00156         Subtract(dest.qdot,dest.q,dest.qdot);
00157         Divide(src.q,factor.t,dest.q);
00158     }
00159 
00160     void SetToZero(JntArrayAcc& array)
00161     {
00162         SetToZero(array.q);
00163         SetToZero(array.qdot);
00164         SetToZero(array.qdotdot);
00165     }
00166 
00167     bool Equal(const JntArrayAcc& src1,const JntArrayAcc& src2,double eps)
00168     {
00169         return (Equal(src1.q,src2.q,eps)&&Equal(src1.qdot,src2.qdot,eps)&&Equal(src1.qdotdot,src2.qdotdot,eps));
00170     }
00171 }
00172 
00173