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