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     void ChainIkSolverVel_pinv_givens::updateInternalDataStructures() {
00050         nj = chain.getNrOfJoints();
00051         jnt2jac.updateInternalDataStructures();
00052         jac.resize(nj);
00053         transpose = (nj > 6);
00054         m = max(6,nj);
00055         n = min(6,nj);
00056         jac_eigen.conservativeResize(m,n);
00057         U.conservativeResizeLike(MatrixXd::Identity(m,m));
00058         V.conservativeResizeLike(MatrixXd::Identity(n,n));
00059         B.conservativeResize(m,n);
00060         S.conservativeResize(n);
00061         tempi.conservativeResize(m);
00062         tempj.conservativeResize(n);
00063         SUY.conservativeResizeLike(VectorXd::Zero(nj));
00064         qdot_eigen.conservativeResize(nj);
00065     }
00066 
00067     ChainIkSolverVel_pinv_givens::~ChainIkSolverVel_pinv_givens()
00068     {
00069     }
00070 
00071 
00072     int ChainIkSolverVel_pinv_givens::CartToJnt(const JntArray& q_in, const Twist& v_in, JntArray& qdot_out)
00073     {
00074         if (nj != chain.getNrOfJoints())
00075             return (error = E_NOT_UP_TO_DATE);
00076 
00077         if (nj != q_in.rows() || nj != qdot_out.rows())
00078             return (error = E_SIZE_MISMATCH);
00079 
00080         toggle=!toggle;
00081 
00082         error = jnt2jac.JntToJac(q_in,jac);
00083         if (E_NOERROR > error )
00084             return error;
00085 
00086         for(unsigned int i=0;i<6;i++)
00087             v_in_eigen(i)=v_in(i);
00088 
00089         for(unsigned int i=0;i<m;i++){
00090             for(unsigned int j=0;j<n;j++)
00091                 if(transpose)
00092                     jac_eigen(i,j)=jac(j,i);
00093                 else
00094                     jac_eigen(i,j)=jac(i,j);
00095         }
00096         svd_eigen_Macie(jac_eigen,U,S,V,B,tempi,1e-15,toggle);
00097 
00098         if(transpose)
00099             UY.noalias() = V.transpose() * v_in_eigen;
00100         else
00101             UY.noalias() = U.transpose() * v_in_eigen;
00102 
00103         for (unsigned int i = 0; i < n; i++){
00104             double wi = UY(i);
00105             double alpha = S(i);
00106             
00107             if (alpha != 0)
00108                 alpha = 1.0 / alpha;
00109             else
00110                 alpha = 0.0;
00111             SUY(i)= alpha * wi;
00112         }
00113         if(transpose)
00114             qdot_eigen.noalias() = U * SUY;
00115         else
00116             qdot_eigen.noalias() = V * SUY;
00117 
00118         for (unsigned int j=0;j<chain.getNrOfJoints();j++)
00119             qdot_out(j)=qdot_eigen(j);
00120 
00121         return (error = E_NOERROR);
00122 
00123     }
00124 }


orocos_kdl
Author(s):
autogenerated on Fri Jun 14 2019 19:33:22