Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpAdaptiveGain.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Description:
31  * Adaptive gain.
32  *
33  * Authors:
34  * Nicolas Mansard
35  *
36  *****************************************************************************/
41 /* --- VISP --- */
42 #include <visp3/core/vpColVector.h>
43 #include <visp3/core/vpDebug.h>
44 #include <visp3/vs/vpAdaptiveGain.h>
45 
46 #include <iostream>
47 #include <cmath> // std::fabs
48 #include <limits> // numeric_limits
49 
50 const double vpAdaptiveGain::DEFAULT_LAMBDA_ZERO = 1.666;
51 const double vpAdaptiveGain::DEFAULT_LAMBDA_INFINITY = 0.1666;
52 const double vpAdaptiveGain::DEFAULT_LAMBDA_SLOPE = 1.666;
53 
54 /* -------------------------------------------------------------------------- */
55 /* --- CONSTRUCTION --------------------------------------------------------- */
56 /* -------------------------------------------------------------------------- */
57 
66  :
67  coeff_a (),
68  coeff_b (),
69  coeff_c (),
70  lambda(1.)
71 {
72  vpDEBUG_TRACE (10, "# Entree constructeur par default.");
73  this ->initFromVoid ();
74 
75  vpDEBUG_TRACE (10, "# Sortie constructeur par default.");
76  return;
77 }
78 
85  :
86  coeff_a (),
87  coeff_b (),
88  coeff_c (),
89  lambda(1.)
90 {
92 }
93 
102 vpAdaptiveGain::vpAdaptiveGain (double gain_at_zero, double gain_at_infinity, double slope_at_zero)
103  :
104  coeff_a (),
105  coeff_b (),
106  coeff_c (),
107  lambda(1.)
108 {
109  initStandard(gain_at_zero, gain_at_infinity, slope_at_zero);
110 }
111 
112 /* -------------------------------------------------------------------------- */
113 /* --- INIT ----------------------------------------------------------------- */
114 /* -------------------------------------------------------------------------- */
115 
121 void vpAdaptiveGain::initFromConstant (const double c)
122 {
123  vpDEBUG_TRACE (10, "# Entree.");
124 
125  this ->coeff_a = 0;
126  this ->coeff_b = 1;
127  this ->coeff_c = c;
128 
129  vpDEBUG_TRACE (10, "# Sortie.");
130  return;
131 }
132 
133 
141 {
142  vpDEBUG_TRACE (10, "# Entree.");
143 
144  this ->initStandard (vpAdaptiveGain::DEFAULT_LAMBDA_ZERO,
147 
148  vpDEBUG_TRACE (10, "# Sortie.");
149  return;
150 }
151 
152 
160 void vpAdaptiveGain::initStandard (const double gain_at_zero,
161  const double gain_at_infinity,
162  const double slope_at_zero)
163 {
164  vpDEBUG_TRACE (10, "# Entree.");
165 
166  this ->coeff_a = gain_at_zero - gain_at_infinity;
167  //if (0 == this ->coeff_a)
168  if (std::fabs(this ->coeff_a) <= std::numeric_limits<double>::epsilon())
169  {
170  this ->coeff_b = 0;
171  }
172  else
173  {
174  this ->coeff_b = slope_at_zero / ( this ->coeff_a);
175  }
176  this ->coeff_c = gain_at_infinity;
177 
178  vpDEBUG_TRACE (10, "# Sortie :a,b,c= %.3f,%.3f,%.3f.",
179  this ->coeff_a, this ->coeff_b, this ->coeff_c);
180  return;
181 }
182 
183 
184 
185 /* -------------------------------------------------------------------------- */
186 /* --- MODIFICATOR ---------------------------------------------------------- */
187 /* -------------------------------------------------------------------------- */
188 
196 {
197  vpDEBUG_TRACE (10, "# Entree.");
198 
199  double res = this ->coeff_a + this ->coeff_c;
200 
201  this ->coeff_a = 0;
202  this ->coeff_b = 1;
203  this ->coeff_c = res;
204 
205  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
206  return res;
207 }
208 
209 /* -------------------------------------------------------------------------- */
210 /* --- VALEUR --------------------------------------------------------------- */
211 /* -------------------------------------------------------------------------- */
212 
223 double vpAdaptiveGain::value_const (const double x) const
224 {
225  vpDEBUG_TRACE (10, "# Entree.");
226 
227  double res = this ->coeff_a * exp (- this ->coeff_b * x) + this ->coeff_c;
228 
229  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
230  return res;
231 }
232 
240 {
241  vpDEBUG_TRACE (10, "# Entree.");
242 
243  double res = this ->coeff_c;
244 
245  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
246  return res;
247 }
248 
261 double vpAdaptiveGain::value (const double x) const
262 {
263  vpDEBUG_TRACE (10, "# Entree.");
264 
265  this ->lambda = this ->value_const (x);
266 
267  vpDEBUG_TRACE (10, "# Sortie: %.3f.", this ->lambda);
268  return lambda;
269 }
270 
271 
278 double vpAdaptiveGain:: limitValue (void) const
279 {
280  vpDEBUG_TRACE (10, "# Entree.");
281 
282  this ->lambda = this ->limitValue_const ();
283 
284  vpDEBUG_TRACE (10, "# Sortie: %.3f.", this ->lambda);
285  return lambda;
286 }
287 
288 /* -------------------------------------------------------------------------- */
289 /* --- ACCESSORS ------------------------------------------------------------ */
290 /* -------------------------------------------------------------------------- */
291 
292 
293 
294 // double vpAdaptiveGain::
295 // getLastValue (void) const
296 // {
297 // return this ->lambda;
298 // }
299 
310 double vpAdaptiveGain::operator() (const double x) const
311 {
312  return this ->value (x);
313 }
314 
322 double vpAdaptiveGain::operator() (void) const
323 {
324  return this ->limitValue ();
325 }
326 
335 {
336  return this ->value (x .infinityNorm());
337 }
338 
339 
340 // double operator() (double val_e) const;
341 // double operator() (const CColVector & e) const;
342 
343 /* -------------------------------------------------------------------------- */
344 /* --- OUTPUT --------------------------------------------------------------- */
345 /* -------------------------------------------------------------------------- */
346 
347 
348 
355 VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpAdaptiveGain& lambda)
356 {
357  os << "Zero= " << lambda .coeff_a + lambda .coeff_c
358  << "\tInf= " << lambda .coeff_c
359  << "\tDeriv= " << lambda .coeff_a * lambda .coeff_b;
360 
361  return os;
362 }
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)
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
double limitValue(void) const
#define vpDEBUG_TRACE
Definition: vpDebug.h:478