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