ViSP  2.9.0
testKalmanAcceleration.cpp
1 /****************************************************************************
2  *
3  * $Id: testKalmanAcceleration.cpp 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Tests some vpLinearKalmanFilterInstantiation functionalities.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
49 #include <visp/vpLinearKalmanFilterInstantiation.h>
50 #include <iostream>
51 #include <fstream>
52 
53 int
54 main()
55 {
56  try {
57  unsigned int nsignal = 1; // Number of signal to filter
58  unsigned int niter = 100;
59 
60  std::string filename = "/tmp/log.dat";
61  std::ofstream flog(filename.c_str());
62 
64 
67  kalman.setStateModel(model);
68 
69  unsigned int size_state_vector = kalman.getStateSize()*nsignal;
70  unsigned int size_measure_vector = kalman.getMeasureSize()*nsignal;
71 
72  vpColVector sigma_measure(size_measure_vector);
73  for (unsigned int signal=0; signal < nsignal; signal ++)
74  sigma_measure = 0.0001;
75  vpColVector sigma_state(size_state_vector);
76  for (unsigned int signal=0; signal < nsignal; signal ++) {
77  sigma_state[3*signal] = 0.; // not used
78  sigma_state[3*signal+1] = 0.000001;
79  sigma_state[3*signal+2] = 0.000001;
80  }
81 
82  vpColVector velocity_measure(size_measure_vector);
83 
84  double rho = 0.9; // correlation
85  double dt = 0.2; // sampling period
86 
87  for (unsigned int signal=0; signal < nsignal; signal ++)
88  velocity_measure[signal] = 3+2*signal;
89 
90  kalman.verbose(false);
91  kalman.initFilter(nsignal, sigma_state, sigma_measure, rho, dt);
92 
93 
94  for (unsigned int iter=0; iter <= niter; iter++) {
95  std::cout << "-------- iter " << iter << " ------------" << std::endl;
96  for (unsigned int signal=0; signal < nsignal; signal ++) {
97  velocity_measure[signal] = 3+2*signal
98  + 0.3*sin(vpMath::rad(360./niter*iter));
99  }
100  std::cout << "measure : " << velocity_measure.t() << std::endl;
101 
102  flog << velocity_measure.t();
103 
104  // kalman.prediction();
105  kalman.filter(velocity_measure);
106  flog << kalman.Xest.t();
107  flog << kalman.Xpre.t();
108 
109  std::cout << "Xest: " << kalman.Xest.t() << std::endl;
110  std::cout << "Xpre: " << kalman.Xpre.t() << std::endl;
111 
112  flog << std::endl;
113  }
114 
115  flog.close();
116  return 0;
117  }
118  catch(vpException e) {
119  std::cout << "Catch an exception: " << e << std::endl;
120  return 0;
121  }
122 }
error that can be emited by ViSP classes.
Definition: vpException.h:76
static double rad(double deg)
Definition: vpMath.h:100
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
This class provides an implementation of some specific linear Kalman filters.