Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testKalmanAcceleration.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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  * Tests some vpLinearKalmanFilterInstantiation functionalities.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
45 #include <visp3/core/vpLinearKalmanFilterInstantiation.h>
46 #include <iostream>
47 #include <fstream>
48 
49 int
50 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 
90  for (unsigned int iter=0; iter <= niter; iter++) {
91  std::cout << "-------- iter " << iter << " ------------" << std::endl;
92  for (unsigned int signal=0; signal < nsignal; signal ++) {
93  velocity_measure[signal] = 3+2*signal
94  + 0.3*sin(vpMath::rad(360./niter*iter));
95  }
96  std::cout << "measure : " << velocity_measure.t() << std::endl;
97 
98  flog << velocity_measure.t();
99 
100  // kalman.prediction();
101  kalman.filter(velocity_measure);
102  flog << kalman.Xest.t();
103  flog << kalman.Xpre.t();
104 
105  std::cout << "Xest: " << kalman.Xest.t() << std::endl;
106  std::cout << "Xpre: " << kalman.Xpre.t() << std::endl;
107 
108  flog << std::endl;
109  }
110 
111  flog.close();
112  return 0;
113  }
114  catch(vpException &e) {
115  std::cout << "Catch an exception: " << e << std::endl;
116  return 0;
117  }
118 }
error that can be emited by ViSP classes.
Definition: vpException.h:73
static double rad(double deg)
Definition: vpMath.h:104
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
This class provides an implementation of some specific linear Kalman filters.