jacobianframe.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                         jacobianframe.cpp -  description
00003                        -------------------------
00004     begin                : June 2006
00005     copyright            : (C) 2006 Erwin Aertbelien
00006     email                : firstname.lastname@mech.kuleuven.ac.be
00007 
00008  History (only major changes)( AUTHOR-Description ) :
00009  
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., 59 Temple Place,                                    *
00024  *   Suite 330, Boston, MA  02111-1307  USA                                *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 #include <kdl/jacobianframe.hpp>
00029 
00030 namespace KDL {
00039  int GetEulerZYX(const Jacobian<Rotation>& JR, 
00040                                   Jacobian<double>& gamma, 
00041                                   Jacobian<double>& beta, 
00042                                   Jacobian<double>& alpha,
00043                                   double eps) {
00044         // position-domain :
00045         JR.value().GetEulerZYX(alpha.value(),beta.value(),gamma.value());
00046         double ca = ::cos(alpha.value()); 
00047         double sa = ::sin(alpha.value()); 
00048         double cb = ::cos(beta.value()); 
00049         double sb = ::sin(beta.value()); 
00050         // velocity-domain :
00051         assert(gamma.nrOfDeriv()==JR.nrOfDeriv());
00052         assert(beta.nrOfDeriv()==JR.nrOfDeriv());
00053         assert(alpha.nrOfDeriv()==JR.nrOfDeriv());
00054     for (int i=0;i<JR.nrOfDeriv();++i) {
00055                 if (JR.hasDeriv(i) ) {
00056                         Vector w = JR.deriv(i);                 
00057                         double dgamma = (ca*w[0]+sa*w[1]);
00058                         if (fabs(cb) < eps) { 
00059                                 if (fabs(dgamma)< eps) {
00060                                         dgamma = 0.0;  // arbitrary choice
00061                                 } else {
00062                                         return 1;
00063                                 }
00064                         } else {
00065                                 dgamma /= cb;
00066                         }
00067                         double dalpha = w[2] + sb*dgamma;
00068                         double dbeta  = -sa*w[0]+ca*w[1];
00069                         gamma.deriv(i)=dgamma;
00070                         alpha.deriv(i)=dalpha;
00071                         beta.deriv(i) =dbeta;
00072                 } else {
00073                         gamma.setDeriv(i,false);
00074                         beta.setDeriv(i,false);
00075                         alpha.setDeriv(i,false);
00076                 }
00077         }
00078         return 0;
00079  }
00087  void SetEulerZYX(const Jacobian<double>& gamma, 
00088                                   const Jacobian<double>& beta, 
00089                                   const Jacobian<double>& alpha,
00090                                   Jacobian<Rotation>& JR) {
00091         // position-domain :
00092         JR.value() = Rotation::EulerZYX(alpha.value(),beta.value(),gamma.value());
00093         double ca = ::cos(alpha.value()); 
00094         double sa = ::sin(alpha.value()); 
00095         double cb = ::cos(beta.value()); 
00096         double sb = ::sin(beta.value()); 
00097         // velocity-domain :
00098         assert(gamma.nrOfDeriv()==JR.nrOfDeriv());
00099         assert(beta.nrOfDeriv()==JR.nrOfDeriv());
00100         assert(alpha.nrOfDeriv()==JR.nrOfDeriv());
00101     for (int i=0;i<gamma.nrOfDeriv();++i) {
00102                 if (gamma.hasDeriv(i) || beta.hasDeriv(i) || alpha.hasDeriv(i) ) {
00103                         Vector w;
00104                         double dalpha  = alpha.deriv(i);
00105                         double dbeta   = beta.deriv(i);
00106                         double dgamma  = gamma.deriv(i);
00107                         w[0] = -sa*dbeta + ca*cb*dgamma;
00108                         w[1] =  ca*dbeta + sa*cb*dgamma;
00109                         w[2] =  dalpha - sb*dgamma; 
00110                         JR.deriv(i) = w;
00111                 } else {
00112                         JR.setDeriv(i,false);
00113                 }
00114         }
00115 }
00116 
00117 
00118 } // end of namespace


orocos_kdl
Author(s): Ruben Smits, Erwin Aertbelien, Orocos Developers
autogenerated on Sat Dec 28 2013 17:17:25