ViSP  2.9.0
vpAdaptiveGain.cpp
1 /****************************************************************************
2  *
3  * $Id: vpAdaptiveGain.cpp 4641 2014-02-05 12:42:03Z 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 {
91 }
92 
101 vpAdaptiveGain::vpAdaptiveGain (double gain_at_zero, double gain_at_infinity, double slope_at_zero)
102 {
103  initStandard(gain_at_zero, gain_at_infinity, slope_at_zero);
104 }
105 
106 /* -------------------------------------------------------------------------- */
107 /* --- INIT ----------------------------------------------------------------- */
108 /* -------------------------------------------------------------------------- */
109 
115 void vpAdaptiveGain::initFromConstant (const double c)
116 {
117  vpDEBUG_TRACE (10, "# Entree.");
118 
119  this ->coeff_a = 0;
120  this ->coeff_b = 1;
121  this ->coeff_c = c;
122 
123  vpDEBUG_TRACE (10, "# Sortie.");
124  return;
125 }
126 
127 
135 {
136  vpDEBUG_TRACE (10, "# Entree.");
137 
138  this ->initStandard (vpAdaptiveGain::DEFAULT_LAMBDA_ZERO,
141 
142  vpDEBUG_TRACE (10, "# Sortie.");
143  return;
144 }
145 
146 
154 void vpAdaptiveGain::initStandard (const double gain_at_zero,
155  const double gain_at_infinity,
156  const double slope_at_zero)
157 {
158  vpDEBUG_TRACE (10, "# Entree.");
159 
160  this ->coeff_a = gain_at_zero - gain_at_infinity;
161  //if (0 == this ->coeff_a)
162  if (std::fabs(this ->coeff_a) <= std::numeric_limits<double>::epsilon())
163  {
164  this ->coeff_b = 0;
165  }
166  else
167  {
168  this ->coeff_b = slope_at_zero / ( this ->coeff_a);
169  }
170  this ->coeff_c = gain_at_infinity;
171 
172  vpDEBUG_TRACE (10, "# Sortie :a,b,c= %.3f,%.3f,%.3f.",
173  this ->coeff_a, this ->coeff_b, this ->coeff_c);
174  return;
175 }
176 
177 
178 
179 /* -------------------------------------------------------------------------- */
180 /* --- MODIFICATOR ---------------------------------------------------------- */
181 /* -------------------------------------------------------------------------- */
182 
190 {
191  vpDEBUG_TRACE (10, "# Entree.");
192 
193  double res = this ->coeff_a + this ->coeff_c;
194 
195  this ->coeff_a = 0;
196  this ->coeff_b = 1;
197  this ->coeff_c = res;
198 
199  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
200  return res;
201 }
202 
203 /* -------------------------------------------------------------------------- */
204 /* --- VALEUR --------------------------------------------------------------- */
205 /* -------------------------------------------------------------------------- */
206 
217 double vpAdaptiveGain::value_const (const double x) const
218 {
219  vpDEBUG_TRACE (10, "# Entree.");
220 
221  double res = this ->coeff_a * exp (- this ->coeff_b * x) + this ->coeff_c;
222 
223  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
224  return res;
225 }
226 
234 {
235  vpDEBUG_TRACE (10, "# Entree.");
236 
237  double res = this ->coeff_c;
238 
239  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
240  return res;
241 }
242 
255 double vpAdaptiveGain::value (const double x) const
256 {
257  vpDEBUG_TRACE (10, "# Entree.");
258 
259  this ->lambda = this ->value_const (x);
260 
261  vpDEBUG_TRACE (10, "# Sortie: %.3f.", this ->lambda);
262  return lambda;
263 }
264 
265 
272 double vpAdaptiveGain:: limitValue (void) const
273 {
274  vpDEBUG_TRACE (10, "# Entree.");
275 
276  this ->lambda = this ->limitValue_const ();
277 
278  vpDEBUG_TRACE (10, "# Sortie: %.3f.", this ->lambda);
279  return lambda;
280 }
281 
282 /* -------------------------------------------------------------------------- */
283 /* --- ACCESSORS ------------------------------------------------------------ */
284 /* -------------------------------------------------------------------------- */
285 
286 
287 
288 // double vpAdaptiveGain::
289 // getLastValue (void) const
290 // {
291 // return this ->lambda;
292 // }
293 
304 double vpAdaptiveGain::operator() (const double x) const
305 {
306  return this ->value (x);
307 }
308 
316 double vpAdaptiveGain::operator() (void) const
317 {
318  return this ->limitValue ();
319 }
320 
329 {
330  return this ->value (x .infinityNorm());
331 }
332 
333 
334 // double operator() (double val_e) const;
335 // double operator() (const CColVector & e) const;
336 
337 /* -------------------------------------------------------------------------- */
338 /* --- OUTPUT --------------------------------------------------------------- */
339 /* -------------------------------------------------------------------------- */
340 
341 
342 
349 VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpAdaptiveGain& lambda)
350 {
351  os << "Zero= " << lambda .coeff_a + lambda .coeff_c
352  << "\tInf= " << lambda .coeff_c
353  << "\tDeriv= " << lambda .coeff_a * lambda .coeff_b;
354 
355  return os;
356 }
#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