Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
testKalmanAcceleration.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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*****************************************************************************/
35
43#include <fstream>
44#include <iostream>
45#include <visp3/core/vpLinearKalmanFilterInstantiation.h>
46
47int main()
48{
49 try {
50 unsigned int nsignal = 1; // Number of signal to filter
51 unsigned int niter = 100;
52
53 std::string filename = "/tmp/log.dat";
54 std::ofstream flog(filename.c_str());
55
57
60 kalman.setStateModel(model);
61
62 unsigned int size_state_vector = kalman.getStateSize() * nsignal;
63 unsigned int size_measure_vector = kalman.getMeasureSize() * nsignal;
64
65 vpColVector sigma_measure(size_measure_vector);
66 for (unsigned int signal = 0; signal < nsignal; signal++)
67 sigma_measure = 0.0001;
68 vpColVector sigma_state(size_state_vector);
69 for (unsigned int signal = 0; signal < nsignal; signal++) {
70 sigma_state[3 * signal] = 0.; // not used
71 sigma_state[3 * signal + 1] = 0.000001;
72 sigma_state[3 * signal + 2] = 0.000001;
73 }
74
75 vpColVector velocity_measure(size_measure_vector);
76
77 double rho = 0.9; // correlation
78 double dt = 0.2; // sampling period
79
80 for (unsigned int signal = 0; signal < nsignal; signal++)
81 velocity_measure[signal] = 3 + 2 * signal;
82
83 kalman.verbose(false);
84 kalman.initFilter(nsignal, sigma_state, sigma_measure, rho, dt);
85
86 for (unsigned int iter = 0; iter <= niter; iter++) {
87 std::cout << "-------- iter " << iter << " ------------" << std::endl;
88 for (unsigned int signal = 0; signal < nsignal; signal++) {
89 velocity_measure[signal] = 3 + 2 * signal + 0.3 * sin(vpMath::rad(360. / niter * iter));
90 }
91 std::cout << "measure : " << velocity_measure.t() << std::endl;
92
93 flog << velocity_measure.t();
94
95 // kalman.prediction();
96 kalman.filter(velocity_measure);
97 flog << kalman.Xest.t();
98 flog << kalman.Xpre.t();
99
100 std::cout << "Xest: " << kalman.Xest.t() << std::endl;
101 std::cout << "Xpre: " << kalman.Xpre.t() << std::endl;
102
103 flog << std::endl;
104 }
105
106 flog.close();
107 return EXIT_SUCCESS;
108 } catch (const vpException &e) {
109 std::cout << "Catch an exception: " << e << std::endl;
110 return EXIT_FAILURE;
111 }
112}
Implementation of column vector and the associated operations.
vpRowVector t() const
error that can be emitted by ViSP classes.
Definition vpException.h:59
vpColVector Xpre
unsigned int getMeasureSize()
void verbose(bool on)
vpColVector Xest
unsigned int getStateSize()
This class provides an implementation of some specific linear Kalman filters.
void initFilter(unsigned int nsignal, vpColVector &sigma_state, vpColVector &sigma_measure, double rho, double dt)
static double rad(double deg)
Definition vpMath.h:116