Main MRPT website > C++ reference
MRPT logo
jacobians.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef  mrpt_math_jacobians_H
00029 #define  mrpt_math_jacobians_H
00030 
00031 #include <mrpt/math/CQuaternion.h>
00032 #include <mrpt/math/utils.h>
00033 #include <mrpt/poses/CPose3D.h>
00034 #include <mrpt/poses/CPose3DPDFGaussian.h>
00035 #include <mrpt/poses/CPosePDFGaussian.h>
00036 
00037 namespace mrpt
00038 {
00039         namespace math
00040         {
00041                 /** A collection of functions to compute jacobians of diverse transformations, etc (some functions are redirections to existing methods elsewhere, so this namespace is actually used with grouping purposes).
00042                   *  Since most functions in this namespace are inline, their use implies no execution time overload and the code may be more clear to read, so it's recommended to use them where needed.
00043                  * \ingroup mrpt_base_grp
00044                   */
00045                 namespace jacobians
00046                 {
00047                         using namespace mrpt::utils;
00048                         using namespace mrpt::poses;
00049                         using namespace mrpt::math;
00050 
00051                         /** Computes the 4x3 Jacobian of the transformation from a 3D pose angles (yaw pitch roll) into a Quaternion, that is, the Jacobian of:
00052                           * \f[ \mathbf{q} = \left( \begin{array}{c} \cos (\phi /2) \cos (\theta /2) \cos (\psi /2) +  \sin (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \sin (\phi /2) \cos (\theta /2) \cos (\psi /2) -  \cos (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \sin (\theta /2) \cos (\psi /2) +  \sin (\phi /2) \cos (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \cos (\theta /2) \sin (\psi /2) -  \sin (\phi /2) \sin (\theta /2) \cos (\psi /2) \\ \end{array}\right) \f]
00053                           * With : \f$ \phi = roll \f$,  \f$ \theta = pitch \f$ and \f$ \psi = yaw \f$.
00054                           * \sa jacob_yawpitchroll_from_quat, mrpt::poses::CPose3D::getAsQuaternion
00055                           */
00056                         inline void jacob_quat_from_yawpitchroll(
00057                                 CMatrixFixedNumeric<double,4,3>  &out_dq_dr,
00058                                 const double yaw,
00059                                 const double pitch,
00060                                 const double roll
00061                                 )
00062                         {
00063                                 CQuaternionDouble q(UNINITIALIZED_QUATERNION);
00064                                 CPose3D  p(0,0,0,yaw,pitch,roll);
00065                                 p.getAsQuaternion(q,&out_dq_dr);
00066                         }
00067 
00068                         /** Computes the 4x3 Jacobian of the transformation from a 3D pose angles (yaw pitch roll) into a Quaternion, that is, the Jacobian of:
00069                           * \f[ \mathbf{q} = \left( \begin{array}{c} \cos (\phi /2) \cos (\theta /2) \cos (\psi /2) +  \sin (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \sin (\phi /2) \cos (\theta /2) \cos (\psi /2) -  \cos (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \sin (\theta /2) \cos (\psi /2) +  \sin (\phi /2) \cos (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \cos (\theta /2) \sin (\psi /2) -  \sin (\phi /2) \sin (\theta /2) \cos (\psi /2) \\ \end{array}\right) \f]
00070                           * With : \f$ \phi = roll \f$,  \f$ \theta = pitch \f$ and \f$ \psi = yaw \f$.
00071                           * \sa jacob_yawpitchroll_from_quat, mrpt::poses::CPose3D::getAsQuaternion
00072                           */
00073                         inline void jacob_quat_from_yawpitchroll(
00074                                 CMatrixFixedNumeric<double,4,3> &out_dq_dr,
00075                                 const CPose3D  &in_pose
00076                                 )
00077                         {
00078                                 CQuaternionDouble q(UNINITIALIZED_QUATERNION);
00079                                 in_pose.getAsQuaternion(q,&out_dq_dr);
00080                         }
00081 
00082 
00083                         /** Computes the 3x4 Jacobian of the transformation from a quaternion (qr qx qy qz) to 3D pose angles (yaw pitch roll).
00084                           * \sa jacob_quat_from_yawpitchroll
00085                           */
00086                         inline void jacob_yawpitchroll_from_quat(
00087                                 CMatrixFixedNumeric<double,3,4>  &out_dr_dq
00088                                 )
00089                         {
00090                                 THROW_EXCEPTION("TO DO")
00091                         }
00092 
00093                         /** Compute the Jacobian of the rotation composition operation \f$ p = f(\cdot) = q_{this} \times r \f$, that is the 4x4 matrix \f$ \frac{\partial f}{\partial q_{this} }  \f$.
00094                           *  The output matrix can be a dynamic or fixed size (4x4) matrix. The input quaternion can be mrpt::math::CQuaternionFloat or mrpt::math::CQuaternionDouble.
00095                           */
00096                         template <class QUATERNION,class MATRIXLIKE>
00097                         inline void jacob_quat_rotation(const QUATERNION& quaternion, MATRIXLIKE &out_mat4x4)
00098                         {
00099                                 quaternion.rotationJacobian(out_mat4x4);
00100                         }
00101 
00102                         /** Given the 3D(6D) pose composition \f$ f(x,u) = x \oplus u \f$, compute the two 6x6 Jacobians \f$ \frac{\partial f}{\partial x} \f$ and \f$ \frac{\partial f}{\partial u} \f$.
00103                           * For the equations, see CPose3DPDFGaussian::jacobiansPoseComposition
00104                           */
00105                         inline void jacobs_6D_pose_comp(
00106                                 const CPose3D   &x,
00107                                 const CPose3D   &u,
00108                                 CMatrixDouble66         &out_df_dx,
00109                                 CMatrixDouble66         &out_df_du)
00110                         {
00111                                 CPose3DPDFGaussian::jacobiansPoseComposition(x,u,out_df_dx,out_df_du);
00112                         }
00113 
00114                         /** Given the 2D pose composition \f$ f(x,u) = x \oplus u \f$, compute the two 3x3 Jacobians \f$ \frac{\partial f}{\partial x} \f$ and \f$ \frac{\partial f}{\partial u} \f$.
00115                           * For the equations, see CPosePDFGaussian::jacobiansPoseComposition
00116                           */
00117                         inline void jacobs_2D_pose_comp(
00118                                 const CPosePDFGaussian &x,
00119                                 const CPosePDFGaussian &u,
00120                                 CMatrixDouble33                  &out_df_dx,
00121                                 CMatrixDouble33                  &out_df_du)
00122                         {
00123                                 CPosePDFGaussian::jacobiansPoseComposition(x,u,out_df_dx,out_df_du);
00124                         }
00125 
00126                         /** Numerical estimation of the Jacobian of a user-supplied function - this template redirects to mrpt::math::estimateJacobian, see that function for documentation. */
00127                         template <class VECTORLIKE,class VECTORLIKE2, class VECTORLIKE3, class MATRIXLIKE, class USERPARAM >
00128                         inline void jacob_numeric_estimate(
00129                                 const VECTORLIKE        &x,
00130                                 void                            (*functor) (const VECTORLIKE &x,const USERPARAM &y, VECTORLIKE3  &out),
00131                                 const VECTORLIKE2       &increments,
00132                                 const USERPARAM         &userParam,
00133                                 MATRIXLIKE                      &out_Jacobian )
00134                         {
00135                                 mrpt::math::estimateJacobian(x,functor,increments,userParam,out_Jacobian);
00136                         }
00137 
00138 
00139                 } // End of jacobians namespace
00140 
00141         } // End of MATH namespace
00142 
00143 } // End of namespace
00144 
00145 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011