chainiksolvervel_pinv_givens.cpp
Go to the documentation of this file.
00001 // Copyright  (C)  2007  Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00002 
00003 // Version: 1.0
00004 // Author: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00005 // Maintainer: Ruben Smits <ruben dot smits at mech dot kuleuven dot be>
00006 // URL: http://www.orocos.org/kdl
00007 
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Lesser General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2.1 of the License, or (at your option) any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Lesser General Public License for more details.
00017 
00018 // You should have received a copy of the GNU Lesser General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 
00022 #include "chainiksolvervel_pinv_givens.hpp"
00023 #include "utilities/svd_eigen_Macie.hpp"
00024 
00025 namespace KDL
00026 {
00027     ChainIkSolverVel_pinv_givens::ChainIkSolverVel_pinv_givens(const Chain& _chain):
00028         chain(_chain),
00029         nj(chain.getNrOfJoints()),
00030         jnt2jac(chain),
00031         jac(nj),
00032         transpose(nj>6),toggle(true),
00033         m(max(6,nj)),
00034         n(min(6,nj)),
00035         jac_eigen(m,n),
00036         U(MatrixXd::Identity(m,m)),
00037         V(MatrixXd::Identity(n,n)),
00038         B(m,n),
00039         S(n),
00040         tempi(m),
00041         tempj(m),
00042         UY(VectorXd::Zero(6)),
00043         SUY(VectorXd::Zero(nj)),
00044         qdot_eigen(nj),
00045         v_in_eigen(6)
00046     {
00047     }
00048 
00049     ChainIkSolverVel_pinv_givens::~ChainIkSolverVel_pinv_givens()
00050     {
00051     }
00052 
00053 
00054     int ChainIkSolverVel_pinv_givens::CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out)
00055     {
00056         if (nj != q_in.rows() || nj != qdot_out.rows())
00057             return (error = E_SIZE_MISMATCH);
00058 
00059         toggle=!toggle;
00060 
00061         error = jnt2jac.JntToJac(q_in,jac);
00062         if (E_NOERROR > error )
00063             return error;
00064 
00065         for(unsigned int i=0;i<6;i++)
00066             v_in_eigen(i)=v_in(i);
00067 
00068         for(unsigned int i=0;i<m;i++){
00069             for(unsigned int j=0;j<n;j++)
00070                 if(transpose)
00071                     jac_eigen(i,j)=jac(j,i);
00072                 else
00073                     jac_eigen(i,j)=jac(i,j);
00074         }
00075         int ret = svd_eigen_Macie(jac_eigen,U,S,V,B,tempi,1e-15,toggle);
00076         //std::cout<<"# sweeps: "<<ret<<std::endl;
00077 
00078         if(transpose)
00079             UY.noalias() = V.transpose() * v_in_eigen;
00080         else
00081             UY.noalias() = U.transpose() * v_in_eigen;
00082 
00083         for (unsigned int i = 0; i < n; i++){
00084             double wi = UY(i);
00085             double alpha = S(i);
00086             
00087             if (alpha != 0)
00088                 alpha = 1.0 / alpha;
00089             else
00090                 alpha = 0.0;
00091             SUY(i)= alpha * wi;
00092         }
00093         if(transpose)
00094             qdot_eigen.noalias() = U * SUY;
00095         else
00096             qdot_eigen.noalias() = V * SUY;
00097 
00098         for (unsigned int j=0;j<chain.getNrOfJoints();j++)
00099             qdot_out(j)=qdot_eigen(j);
00100 
00101         return (error = E_NOERROR);
00102 
00103     }
00104 }


orocos_kdl
Author(s):
autogenerated on Sat Oct 7 2017 03:04:28