Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpStatisticalTestSigma.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 
39 #include <visp3/core/vpStatisticalTestSigma.h>
40 
41 BEGIN_VISP_NAMESPACE
43 {
44  float delta = m_h * m_stdev;
45  m_limitDown = m_mean - delta;
46  m_limitUp = m_mean + delta;
47 }
48 
50 {
51  if (m_s <= m_limitDown) {
53  }
54  else {
56  }
57 }
58 
60 {
61  if (m_s >= m_limitUp) {
63  }
64  else {
66  }
67 }
68 
70 {
71  bool areStatsAvailable = vpStatisticalTestAbstract::updateStatistics(signal);
72  if (areStatsAvailable) {
73  computeLimits();
74  }
75  return areStatsAvailable;
76 }
77 
79 {
80  m_s = signal;
81 }
82 
83 vpStatisticalTestSigma::vpStatisticalTestSigma(const float &h, const unsigned int &nbSamplesForStats)
85  , m_h(h)
86 {
87  init(h, nbSamplesForStats);
88 }
89 
90 vpStatisticalTestSigma::vpStatisticalTestSigma(const float &h, const float &mean, const float &stdev)
92  , m_h(h)
93 {
94  init(h, mean, stdev);
95 }
96 
97 void vpStatisticalTestSigma::init(const float &h, const unsigned int &nbSamplesForStats)
98 {
100  m_h = h;
101  setNbSamplesForStat(nbSamplesForStats);
102  m_s = 0;
103 }
104 
105 void vpStatisticalTestSigma::init(const float &h, const float &mean, const float &stdev)
106 {
108  m_h = h;
109  m_mean = mean;
110  m_s = 0;
111  m_stdev = stdev;
112  computeLimits();
114 }
115 END_VISP_NAMESPACE
Base class for methods detecting the drift of the mean of a process.
vpMeanDriftType
Enum that indicates if a drift of the mean occurred.
void init()
(Re)Initialize the algorithm.
virtual bool updateStatistics(const float &signal)
Update m_s and if enough values are available, compute the mean, the standard deviation and the limit...
void setNbSamplesForStat(const unsigned int &nbSamples)
Set the number of samples required to compute the mean and standard deviation of the signal and alloc...
vpStatisticalTestSigma(const float &h=3.f, const unsigned int &nbSamplesForStats=30)
Construct a new vpStatisticalTestSigma object.
virtual vpMeanDriftType detectUpwardMeanDrift() override
Detects if an upward mean drift occurred on the mean.
virtual vpMeanDriftType detectDownwardMeanDrift() override
Detects if a downward mean drift occurred.
virtual bool updateStatistics(const float &signal) override
Update m_s and if enough values are available, compute the mean, the standard deviation and the limit...
virtual void computeLimits()
Compute the upper and lower limits of the test signal.
virtual void updateTestSignals(const float &signal) override
Update the test signals.