Visual Servoing Platform  version 3.6.1 under development (2024-12-04)
exponentialMap.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Test some vpColVector functionalities.
33  *
34 *****************************************************************************/
35 
42 #include <visp3/core/vpColVector.h>
43 #include <visp3/core/vpConfig.h>
44 #include <visp3/core/vpExponentialMap.h>
45 #include <visp3/core/vpHomogeneousMatrix.h>
46 #include <visp3/core/vpRotationVector.h>
47 #include <visp3/core/vpRxyzVector.h>
48 #include <visp3/core/vpThetaUVector.h>
49 #include <visp3/core/vpTranslationVector.h>
50 
51 int main()
52 {
53 #ifdef ENABLE_VISP_NAMESPACE
54  using namespace VISP_NAMESPACE_NAME;
55 #endif
56  try {
58  t[0] = 0.1; // t_x in m/s
59  t[1] = 0.2f; // t_y in m/s
60  t[2] = 0.f; // t_z in m/s
61 
62  vpRxyzVector rxyz;
63  rxyz[0] = vpMath::rad(0.f); // r_x in rad/s
64  rxyz[1] = vpMath::rad(0.f); // r_y in rad/s
65  rxyz[2] = vpMath::rad(90.f); // r_z in rad/s
66 
67  // Build a ThetaU rotation vector from a Rxyz vector
68  vpThetaUVector tu;
69  tu.buildFrom(rxyz);
70 
71  vpColVector v(6); // Velocity vector [t, thetaU]^t
72 
73  v[0] = t[0]; // t_x
74  v[1] = t[1]; // t_y
75  v[2] = t[2]; // t_z
76  v[3] = tu[0]; // ThetaU_x
77  v[4] = tu[1]; // ThetaU_y
78  v[5] = tu[2]; // ThetaU_z
79 
80  std::cout << "Considered velocity : \n" << v << std::endl;
81 
83 
84  // Compute the displacement from the velocity applied during 1 second
86 
87  {
88  // Extract translation from homogenous matrix
89  vpTranslationVector dt; // translation displacement
90  M.extract(dt);
91 
92  // Extract rotation from homogenous matrix
94  M.extract(R);
95  vpRxyzVector drxyz(R); // rotational displacement
96 
97  std::cout << "Displacement if velocity is applied during 1 s : \n" << dt << " " << drxyz << std::endl;
98  }
99 
100  // Compute the displacement from the velocity applied during 2 seconds
101  M = vpExponentialMap::direct(v, 2.f);
102 
103  {
104  // Extract translation from homogenous matrix
105  vpTranslationVector dt; // translation displacement
106  M.extract(dt);
107 
108  // Extract rotation from homogenous matrix
110  M.extract(R);
111  vpRxyzVector drxyz(R); // rotational displacement
112 
113  std::cout << "Displacement if velocity is applied during 2 s : \n" << dt << " " << drxyz << std::endl;
114  }
115 
116  // Compute the velocity from the displacement observed during 2 seconds
117  v = vpExponentialMap::inverse(M, 2.f);
118 
119  std::cout << "Velocity from displacement observed during 2 s: \n" << v << std::endl;
120  return EXIT_SUCCESS;
121  }
122  catch (const vpException &e) {
123  std::cout << "Catch an exception: " << e << std::endl;
124  return EXIT_FAILURE;
125  }
126 }
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
error that can be emitted by ViSP classes.
Definition: vpException.h:60
static vpHomogeneousMatrix direct(const vpColVector &v)
static vpColVector inverse(const vpHomogeneousMatrix &M)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void extract(vpRotationMatrix &R) const
static double rad(double deg)
Definition: vpMath.h:129
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:183
Implementation of a rotation vector as axis-angle minimal representation.
vpThetaUVector & buildFrom(const vpHomogeneousMatrix &M)
Class that consider the case of a translation vector.