Visual Servoing Platform  version 3.6.1 under development (2024-05-08)
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/vpExponentialMap.h>
44 #include <visp3/core/vpHomogeneousMatrix.h>
45 #include <visp3/core/vpRotationVector.h>
46 #include <visp3/core/vpRxyzVector.h>
47 #include <visp3/core/vpThetaUVector.h>
48 #include <visp3/core/vpTranslationVector.h>
49 
50 int main()
51 {
52  try {
54  t[0] = 0.1; // t_x in m/s
55  t[1] = 0.2f; // t_y in m/s
56  t[2] = 0.f; // t_z in m/s
57 
58  vpRxyzVector rxyz;
59  rxyz[0] = vpMath::rad(0.f); // r_x in rad/s
60  rxyz[1] = vpMath::rad(0.f); // r_y in rad/s
61  rxyz[2] = vpMath::rad(90.f); // r_z in rad/s
62 
63  // Build a ThetaU rotation vector from a Rxyz vector
64  vpThetaUVector tu;
65  tu.buildFrom(rxyz);
66 
67  vpColVector v(6); // Velocity vector [t, thetaU]^t
68 
69  v[0] = t[0]; // t_x
70  v[1] = t[1]; // t_y
71  v[2] = t[2]; // t_z
72  v[3] = tu[0]; // ThetaU_x
73  v[4] = tu[1]; // ThetaU_y
74  v[5] = tu[2]; // ThetaU_z
75 
76  std::cout << "Considered velocity : \n" << v << std::endl;
77 
79 
80  // Compute the displacement from the velocity applied during 1 second
82 
83  {
84  // Extract translation from homogenous matrix
85  vpTranslationVector dt; // translation displacement
86  M.extract(dt);
87 
88  // Extract rotation from homogenous matrix
90  M.extract(R);
91  vpRxyzVector drxyz(R); // rotational displacement
92 
93  std::cout << "Displacement if velocity is applied during 1 s : \n" << dt << " " << drxyz << std::endl;
94  }
95 
96  // Compute the displacement from the velocity applied during 2 seconds
97  M = vpExponentialMap::direct(v, 2.f);
98 
99  {
100  // Extract translation from homogenous matrix
101  vpTranslationVector dt; // translation displacement
102  M.extract(dt);
103 
104  // Extract rotation from homogenous matrix
106  M.extract(R);
107  vpRxyzVector drxyz(R); // rotational displacement
108 
109  std::cout << "Displacement if velocity is applied during 2 s : \n" << dt << " " << drxyz << std::endl;
110  }
111 
112  // Compute the velocity from the displacement observed during 2 seconds
113  v = vpExponentialMap::inverse(M, 2.f);
114 
115  std::cout << "Velocity from displacement observed during 2 s: \n" << v << std::endl;
116  return EXIT_SUCCESS;
117  }
118  catch (const vpException &e) {
119  std::cout << "Catch an exception: " << e << std::endl;
120  return EXIT_FAILURE;
121  }
122 }
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
error that can be emitted by ViSP classes.
Definition: vpException.h:59
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:127
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:176
Implementation of a rotation vector as axis-angle minimal representation.
vpThetaUVector buildFrom(const vpHomogeneousMatrix &M)
Class that consider the case of a translation vector.