Visual Servoing Platform  version 3.4.1 under development (2021-10-17)
testKalmanAcceleration.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  * Tests some vpLinearKalmanFilterInstantiation functionalities.
33  *
34  * Authors:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
46 #include <fstream>
47 #include <iostream>
48 #include <visp3/core/vpLinearKalmanFilterInstantiation.h>
49 
50 int main()
51 {
52  try {
53  unsigned int nsignal = 1; // Number of signal to filter
54  unsigned int niter = 100;
55 
56  std::string filename = "/tmp/log.dat";
57  std::ofstream flog(filename.c_str());
58 
60 
63  kalman.setStateModel(model);
64 
65  unsigned int size_state_vector = kalman.getStateSize() * nsignal;
66  unsigned int size_measure_vector = kalman.getMeasureSize() * nsignal;
67 
68  vpColVector sigma_measure(size_measure_vector);
69  for (unsigned int signal = 0; signal < nsignal; signal++)
70  sigma_measure = 0.0001;
71  vpColVector sigma_state(size_state_vector);
72  for (unsigned int signal = 0; signal < nsignal; signal++) {
73  sigma_state[3 * signal] = 0.; // not used
74  sigma_state[3 * signal + 1] = 0.000001;
75  sigma_state[3 * signal + 2] = 0.000001;
76  }
77 
78  vpColVector velocity_measure(size_measure_vector);
79 
80  double rho = 0.9; // correlation
81  double dt = 0.2; // sampling period
82 
83  for (unsigned int signal = 0; signal < nsignal; signal++)
84  velocity_measure[signal] = 3 + 2 * signal;
85 
86  kalman.verbose(false);
87  kalman.initFilter(nsignal, sigma_state, sigma_measure, rho, dt);
88 
89  for (unsigned int iter = 0; iter <= niter; iter++) {
90  std::cout << "-------- iter " << iter << " ------------" << std::endl;
91  for (unsigned int signal = 0; signal < nsignal; signal++) {
92  velocity_measure[signal] = 3 + 2 * signal + 0.3 * sin(vpMath::rad(360. / niter * iter));
93  }
94  std::cout << "measure : " << velocity_measure.t() << std::endl;
95 
96  flog << velocity_measure.t();
97 
98  // kalman.prediction();
99  kalman.filter(velocity_measure);
100  flog << kalman.Xest.t();
101  flog << kalman.Xpre.t();
102 
103  std::cout << "Xest: " << kalman.Xest.t() << std::endl;
104  std::cout << "Xpre: " << kalman.Xpre.t() << std::endl;
105 
106  flog << std::endl;
107  }
108 
109  flog.close();
110  return 0;
111  } catch (const vpException &e) {
112  std::cout << "Catch an exception: " << e << std::endl;
113  return 0;
114  }
115 }
error that can be emited by ViSP classes.
Definition: vpException.h:71
static double rad(double deg)
Definition: vpMath.h:110
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
This class provides an implementation of some specific linear Kalman filters.