ViSP  2.10.0
vpAdaptiveGain.cpp
1 /****************************************************************************
2  *
3  * $Id: vpAdaptiveGain.cpp 5126 2015-01-05 22:07:11Z 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  * Adaptive gain.
36  *
37  * Authors:
38  * Nicolas Mansard
39  *
40  *****************************************************************************/
45 /* --- VISP --- */
46 #include <visp/vpColVector.h>
47 #include <visp/vpDebug.h>
48 #include <visp/vpAdaptiveGain.h>
49 
50 #include <iostream>
51 #include <cmath> // std::fabs
52 #include <limits> // numeric_limits
53 
54 const double vpAdaptiveGain::DEFAULT_LAMBDA_ZERO = 1.666;
55 const double vpAdaptiveGain::DEFAULT_LAMBDA_INFINITY = 0.1666;
56 const double vpAdaptiveGain::DEFAULT_LAMBDA_SLOPE = 1.666;
57 
58 /* -------------------------------------------------------------------------- */
59 /* --- CONSTRUCTION --------------------------------------------------------- */
60 /* -------------------------------------------------------------------------- */
61 
70  :
71  coeff_a (),
72  coeff_b (),
73  coeff_c (),
74  lambda(1.)
75 {
76  vpDEBUG_TRACE (10, "# Entree constructeur par default.");
77  this ->initFromVoid ();
78 
79  vpDEBUG_TRACE (10, "# Sortie constructeur par default.");
80  return;
81 }
82 
89  :
90  coeff_a (),
91  coeff_b (),
92  coeff_c (),
93  lambda(1.)
94 {
96 }
97 
106 vpAdaptiveGain::vpAdaptiveGain (double gain_at_zero, double gain_at_infinity, double slope_at_zero)
107  :
108  coeff_a (),
109  coeff_b (),
110  coeff_c (),
111  lambda(1.)
112 {
113  initStandard(gain_at_zero, gain_at_infinity, slope_at_zero);
114 }
115 
116 /* -------------------------------------------------------------------------- */
117 /* --- INIT ----------------------------------------------------------------- */
118 /* -------------------------------------------------------------------------- */
119 
125 void vpAdaptiveGain::initFromConstant (const double c)
126 {
127  vpDEBUG_TRACE (10, "# Entree.");
128 
129  this ->coeff_a = 0;
130  this ->coeff_b = 1;
131  this ->coeff_c = c;
132 
133  vpDEBUG_TRACE (10, "# Sortie.");
134  return;
135 }
136 
137 
145 {
146  vpDEBUG_TRACE (10, "# Entree.");
147 
148  this ->initStandard (vpAdaptiveGain::DEFAULT_LAMBDA_ZERO,
151 
152  vpDEBUG_TRACE (10, "# Sortie.");
153  return;
154 }
155 
156 
164 void vpAdaptiveGain::initStandard (const double gain_at_zero,
165  const double gain_at_infinity,
166  const double slope_at_zero)
167 {
168  vpDEBUG_TRACE (10, "# Entree.");
169 
170  this ->coeff_a = gain_at_zero - gain_at_infinity;
171  //if (0 == this ->coeff_a)
172  if (std::fabs(this ->coeff_a) <= std::numeric_limits<double>::epsilon())
173  {
174  this ->coeff_b = 0;
175  }
176  else
177  {
178  this ->coeff_b = slope_at_zero / ( this ->coeff_a);
179  }
180  this ->coeff_c = gain_at_infinity;
181 
182  vpDEBUG_TRACE (10, "# Sortie :a,b,c= %.3f,%.3f,%.3f.",
183  this ->coeff_a, this ->coeff_b, this ->coeff_c);
184  return;
185 }
186 
187 
188 
189 /* -------------------------------------------------------------------------- */
190 /* --- MODIFICATOR ---------------------------------------------------------- */
191 /* -------------------------------------------------------------------------- */
192 
200 {
201  vpDEBUG_TRACE (10, "# Entree.");
202 
203  double res = this ->coeff_a + this ->coeff_c;
204 
205  this ->coeff_a = 0;
206  this ->coeff_b = 1;
207  this ->coeff_c = res;
208 
209  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
210  return res;
211 }
212 
213 /* -------------------------------------------------------------------------- */
214 /* --- VALEUR --------------------------------------------------------------- */
215 /* -------------------------------------------------------------------------- */
216 
227 double vpAdaptiveGain::value_const (const double x) const
228 {
229  vpDEBUG_TRACE (10, "# Entree.");
230 
231  double res = this ->coeff_a * exp (- this ->coeff_b * x) + this ->coeff_c;
232 
233  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
234  return res;
235 }
236 
244 {
245  vpDEBUG_TRACE (10, "# Entree.");
246 
247  double res = this ->coeff_c;
248 
249  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
250  return res;
251 }
252 
265 double vpAdaptiveGain::value (const double x) const
266 {
267  vpDEBUG_TRACE (10, "# Entree.");
268 
269  this ->lambda = this ->value_const (x);
270 
271  vpDEBUG_TRACE (10, "# Sortie: %.3f.", this ->lambda);
272  return lambda;
273 }
274 
275 
282 double vpAdaptiveGain:: limitValue (void) const
283 {
284  vpDEBUG_TRACE (10, "# Entree.");
285 
286  this ->lambda = this ->limitValue_const ();
287 
288  vpDEBUG_TRACE (10, "# Sortie: %.3f.", this ->lambda);
289  return lambda;
290 }
291 
292 /* -------------------------------------------------------------------------- */
293 /* --- ACCESSORS ------------------------------------------------------------ */
294 /* -------------------------------------------------------------------------- */
295 
296 
297 
298 // double vpAdaptiveGain::
299 // getLastValue (void) const
300 // {
301 // return this ->lambda;
302 // }
303 
314 double vpAdaptiveGain::operator() (const double x) const
315 {
316  return this ->value (x);
317 }
318 
326 double vpAdaptiveGain::operator() (void) const
327 {
328  return this ->limitValue ();
329 }
330 
339 {
340  return this ->value (x .infinityNorm());
341 }
342 
343 
344 // double operator() (double val_e) const;
345 // double operator() (const CColVector & e) const;
346 
347 /* -------------------------------------------------------------------------- */
348 /* --- OUTPUT --------------------------------------------------------------- */
349 /* -------------------------------------------------------------------------- */
350 
351 
352 
359 VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpAdaptiveGain& lambda)
360 {
361  os << "Zero= " << lambda .coeff_a + lambda .coeff_c
362  << "\tInf= " << lambda .coeff_c
363  << "\tDeriv= " << lambda .coeff_a * lambda .coeff_b;
364 
365  return os;
366 }
#define vpDEBUG_TRACE
Definition: vpDebug.h:482
Adaptive gain computation.
static const double DEFAULT_LAMBDA_ZERO
static const double DEFAULT_LAMBDA_INFINITY
static const double DEFAULT_LAMBDA_SLOPE
void initFromVoid(void)
double value(double x) const
void initStandard(double gain_at_zero, double gain_at_infinity, double slope_at_zero)
double limitValue_const(void) const
double operator()(void) const
double setConstant(void)
double value_const(double x) const
void initFromConstant(double c)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
double limitValue(void) const