Main MRPT website > C++ reference for MRPT 1.9.9
jacobians.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef mrpt_math_jacobians_H
10 #define mrpt_math_jacobians_H
11 
12 #include <mrpt/math/num_jacobian.h>
13 #include <mrpt/math/CQuaternion.h>
14 #include <mrpt/poses/CPose3D.h>
15 #include <mrpt/poses/CPosePDF.h>
17 #include <mrpt/poses/CPose3DPDF.h>
18 #include <functional>
19 
20 namespace mrpt
21 {
22 namespace math
23 {
24 /** A collection of functions to compute jacobians of diverse transformations,
25  * etc (some functions are redirections to existing methods elsewhere, so this
26  * namespace is actually used with grouping purposes).
27  * Since most functions in this namespace are inline, their use implies no
28  * execution time overload and the code may be more clear to read, so it's
29  * recommended to use them where needed.
30  * \ingroup mrpt_base_grp
31  */
32 namespace jacobians
33 {
34 /** Computes the 4x3 Jacobian of the transformation from a 3D pose angles (yaw
35  * pitch roll) into a Quaternion, that is, the Jacobian of:
36  * \f[ \mathbf{q} = \left( \begin{array}{c} \cos (\phi /2) \cos (\theta /2)
37  * \cos (\psi /2) + \sin (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \sin
38  * (\phi /2) \cos (\theta /2) \cos (\psi /2) - \cos (\phi /2) \sin (\theta /2)
39  * \sin (\psi /2) \\ \cos (\phi /2) \sin (\theta /2) \cos (\psi /2) + \sin
40  * (\phi /2) \cos (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \cos (\theta /2)
41  * \sin (\psi /2) - \sin (\phi /2) \sin (\theta /2) \cos (\psi /2) \\
42  * \end{array}\right) \f]
43  * With : \f$ \phi = roll \f$, \f$ \theta = pitch \f$ and \f$ \psi = yaw \f$.
44  * \sa jacob_yawpitchroll_from_quat, mrpt::poses::CPose3D::getAsQuaternion
45  */
47  mrpt::math::CMatrixFixedNumeric<double, 4, 3>& out_dq_dr, const double yaw,
48  const double pitch, const double roll)
49 {
51  mrpt::poses::CPose3D p(0, 0, 0, yaw, pitch, roll);
52  p.getAsQuaternion(q, &out_dq_dr);
53 }
54 
55 /** Computes the 4x3 Jacobian of the transformation from a 3D pose angles (yaw
56  * pitch roll) into a Quaternion, that is, the Jacobian of:
57  * \f[ \mathbf{q} = \left( \begin{array}{c} \cos (\phi /2) \cos (\theta /2)
58  * \cos (\psi /2) + \sin (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \sin
59  * (\phi /2) \cos (\theta /2) \cos (\psi /2) - \cos (\phi /2) \sin (\theta /2)
60  * \sin (\psi /2) \\ \cos (\phi /2) \sin (\theta /2) \cos (\psi /2) + \sin
61  * (\phi /2) \cos (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \cos (\theta /2)
62  * \sin (\psi /2) - \sin (\phi /2) \sin (\theta /2) \cos (\psi /2) \\
63  * \end{array}\right) \f]
64  * With : \f$ \phi = roll \f$, \f$ \theta = pitch \f$ and \f$ \psi = yaw \f$.
65  * \sa jacob_yawpitchroll_from_quat, mrpt::poses::CPose3D::getAsQuaternion
66  */
69  const mrpt::poses::CPose3D& in_pose)
70 {
72  in_pose.getAsQuaternion(q, &out_dq_dr);
73 }
74 
75 /** Computes the 3x4 Jacobian of the transformation from a quaternion (qr qx qy
76  * qz) to 3D pose angles (yaw pitch roll).
77  * \sa jacob_quat_from_yawpitchroll
78  */
81 {
82  MRPT_UNUSED_PARAM(out_dr_dq);
83  THROW_EXCEPTION("TO DO")
84 }
85 
86 /** Compute the Jacobian of the rotation composition operation \f$ p = f(\cdot)
87  * = q_{this} \times r \f$, that is the 4x4 matrix \f$ \frac{\partial
88  * f}{\partial q_{this} } \f$.
89  * The output matrix can be a dynamic or fixed size (4x4) matrix. The input
90  * quaternion can be mrpt::math::CQuaternionFloat or
91  * mrpt::math::CQuaternionDouble.
92  */
93 template <class QUATERNION, class MATRIXLIKE>
94 inline void jacob_quat_rotation(
95  const QUATERNION& quaternion, MATRIXLIKE& out_mat4x4)
96 {
97  quaternion.rotationJacobian(out_mat4x4);
98 }
99 
100 /** Given the 3D(6D) pose composition \f$ f(x,u) = x \oplus u \f$, compute the
101  * two 6x6 Jacobians \f$ \frac{\partial f}{\partial x} \f$ and \f$
102  * \frac{\partial f}{\partial u} \f$.
103  * For the equations, see CPose3DPDF::jacobiansPoseComposition
104  */
107  CMatrixDouble66& out_df_dx, CMatrixDouble66& out_df_du)
108 {
110  x, u, out_df_dx, out_df_du);
111 }
112 
113 /** Given the 3D(6D) pose composition \f$ f(x,u) = x \oplus u \f$, compute the
114  * two 6x6 Jacobians \f$ \frac{\partial f}{\partial x} \f$ and \f$
115  * \frac{\partial f}{\partial u} \f$.
116  * For the equations, see CPose3DQuatPDF::jacobiansPoseComposition
117  */
120  CMatrixDouble77& out_df_dx, CMatrixDouble77& out_df_du)
121 {
123  x, u, out_df_dx, out_df_du);
124 }
125 
126 /** Given the 2D pose composition \f$ f(x,u) = x \oplus u \f$, compute the two
127  * 3x3 Jacobians \f$ \frac{\partial f}{\partial x} \f$ and \f$ \frac{\partial
128  * f}{\partial u} \f$.
129  * For the equations, see CPosePDF::jacobiansPoseComposition
130  */
133  const mrpt::poses::CPosePDFGaussian& u, CMatrixDouble33& out_df_dx,
134  CMatrixDouble33& out_df_du)
135 {
136  mrpt::poses::CPosePDF::jacobiansPoseComposition(x, u, out_df_dx, out_df_du);
137 }
138 
139 /** Numerical estimation of the Jacobian of a user-supplied function - this
140  * template redirects to mrpt::math::estimateJacobian, see that function for
141  * documentation. */
142 template <class VECTORLIKE, class VECTORLIKE2, class VECTORLIKE3,
143  class MATRIXLIKE, class USERPARAM>
145  const VECTORLIKE& x,
146  std::function<
147  void(const VECTORLIKE& x, const USERPARAM& y, VECTORLIKE3& out)>
148  functor,
149  const VECTORLIKE2& increments, const USERPARAM& userParam,
150  MATRIXLIKE& out_Jacobian)
151 {
153  x, functor, increments, userParam, out_Jacobian);
154 }
155 
156 } // End of jacobians namespace
157 } // End of MATH namespace
158 } // End of namespace
159 #endif
static void jacobiansPoseComposition(const CPose3D &x, const CPose3D &u, mrpt::math::CMatrixDouble66 &df_dx, mrpt::math::CMatrixDouble66 &df_du)
This static method computes the pose composition Jacobians.
Definition: CPose3DPDF.cpp:141
#define THROW_EXCEPTION(msg)
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:3721
void getAsQuaternion(mrpt::math::CQuaternionDouble &q, mrpt::math::CMatrixFixedNumeric< double, 4, 3 > *out_dq_dr=nullptr) const
Returns the quaternion associated to the rotation of this object (NOTE: XYZ translation is ignored) ...
Definition: CPose3D.cpp:584
void jacob_numeric_estimate(const VECTORLIKE &x, std::function< void(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out)> functor, const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Numerical estimation of the Jacobian of a user-supplied function - this template redirects to mrpt::m...
Definition: jacobians.h:144
void estimateJacobian(const VECTORLIKE &x, const std::function< void(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out)> &functor, const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Estimate the Jacobian of a multi-dimensional function around a point "x", using finite differences of...
Definition: num_jacobian.h:31
A numeric matrix of compile-time fixed size.
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
void jacob_quat_from_yawpitchroll(mrpt::math::CMatrixFixedNumeric< double, 4, 3 > &out_dq_dr, const double yaw, const double pitch, const double roll)
Computes the 4x3 Jacobian of the transformation from a 3D pose angles (yaw pitch roll) into a Quatern...
Definition: jacobians.h:46
void jacobs_6D_pose_comp(const mrpt::poses::CPose3D &x, const mrpt::poses::CPose3D &u, CMatrixDouble66 &out_df_dx, CMatrixDouble66 &out_df_du)
Given the 3D(6D) pose composition , compute the two 6x6 Jacobians and .
Definition: jacobians.h:105
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
Definition: CPose3DQuat.h:48
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
static void jacobiansPoseComposition(const CPose2D &x, const CPose2D &u, mrpt::math::CMatrixDouble33 &df_dx, mrpt::math::CMatrixDouble33 &df_du, const bool compute_df_dx=true, const bool compute_df_du=true)
This static method computes the pose composition Jacobians, with these formulas:
Definition: CPosePDF.cpp:32
void jacob_quat_rotation(const QUATERNION &quaternion, MATRIXLIKE &out_mat4x4)
Compute the Jacobian of the rotation composition operation , that is the 4x4 matrix ...
Definition: jacobians.h:94
GLenum GLint GLint y
Definition: glext.h:3538
void jacob_yawpitchroll_from_quat(mrpt::math::CMatrixFixedNumeric< double, 3, 4 > &out_dr_dq)
Computes the 3x4 Jacobian of the transformation from a quaternion (qr qx qy qz) to 3D pose angles (ya...
Definition: jacobians.h:79
GLenum GLint x
Definition: glext.h:3538
A quaternion, which can represent a 3D rotation as pair , with a real part "r" and a 3D vector ...
Definition: CQuaternion.h:46
static void jacobiansPoseComposition(const CPose3DQuat &x, const CPose3DQuat &u, mrpt::math::CMatrixDouble77 &df_dx, mrpt::math::CMatrixDouble77 &df_du, CPose3DQuat *out_x_oplus_u=nullptr)
This static method computes the two Jacobians of a pose composition operation $f(x,u)= x u$.
void jacobs_2D_pose_comp(const mrpt::poses::CPosePDFGaussian &x, const mrpt::poses::CPosePDFGaussian &u, CMatrixDouble33 &out_df_dx, CMatrixDouble33 &out_df_du)
Given the 2D pose composition , compute the two 3x3 Jacobians and .
Definition: jacobians.h:131
GLfloat GLfloat p
Definition: glext.h:6305



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019