Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright 2010, |
3 |
|
|
* François Bleibel, |
4 |
|
|
* Olivier Stasse, |
5 |
|
|
* |
6 |
|
|
* CNRS/AIST |
7 |
|
|
* |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#ifndef __SOT_GAIN_HYPERBOLIC_HH__ |
11 |
|
|
#define __SOT_GAIN_HYPERBOLIC_HH__ |
12 |
|
|
|
13 |
|
|
/* --------------------------------------------------------------------- */ |
14 |
|
|
/* --- INCLUDE --------------------------------------------------------- */ |
15 |
|
|
/* --------------------------------------------------------------------- */ |
16 |
|
|
|
17 |
|
|
/* Matrix */ |
18 |
|
|
#include <dynamic-graph/linear-algebra.h> |
19 |
|
|
|
20 |
|
|
/* SOT */ |
21 |
|
|
#include <dynamic-graph/all-signals.h> |
22 |
|
|
#include <dynamic-graph/entity.h> |
23 |
|
|
|
24 |
|
|
/* --------------------------------------------------------------------- */ |
25 |
|
|
/* --- API ------------------------------------------------------------- */ |
26 |
|
|
/* --------------------------------------------------------------------- */ |
27 |
|
|
|
28 |
|
|
#if defined(WIN32) |
29 |
|
|
#if defined(gain_hyperbolic_EXPORTS) |
30 |
|
|
#define SOTGAINHYPERBOLIC_EXPORT __declspec(dllexport) |
31 |
|
|
#else |
32 |
|
|
#define SOTGAINHYPERBOLIC_EXPORT __declspec(dllimport) |
33 |
|
|
#endif |
34 |
|
|
#else |
35 |
|
|
#define SOTGAINHYPERBOLIC_EXPORT |
36 |
|
|
#endif |
37 |
|
|
|
38 |
|
|
/* --------------------------------------------------------------------- */ |
39 |
|
|
/* --- CLASS ----------------------------------------------------------- */ |
40 |
|
|
/* --------------------------------------------------------------------- */ |
41 |
|
|
|
42 |
|
|
namespace dynamicgraph { |
43 |
|
|
namespace sot { |
44 |
|
|
|
45 |
|
|
/** \brief Hyperbolic gain. |
46 |
|
|
* It follows the law \f[ g(e) = a \frac{\tanh(-b(||e|| - d)) + 1}{2} + c \f] |
47 |
|
|
* The default coefficients are: |
48 |
|
|
* - \f$ a = 0 \f$, |
49 |
|
|
* - \f$ b = 0 \f$, |
50 |
|
|
* - \f$ c = 0.1 \f$, |
51 |
|
|
* - \f$ d = 0 \f$. |
52 |
|
|
*/ |
53 |
|
|
class SOTGAINHYPERBOLIC_EXPORT GainHyperbolic : public dynamicgraph::Entity { |
54 |
|
|
public: /* --- CONSTANTS --- */ |
55 |
|
|
/* Default values. */ |
56 |
|
|
static const double ZERO_DEFAULT; // = 0.1 |
57 |
|
|
static const double INFTY_DEFAULT; // = 0.1 |
58 |
|
|
static const double TAN_DEFAULT; // = 1. |
59 |
|
|
|
60 |
|
|
public: /* --- ENTITY INHERITANCE --- */ |
61 |
|
|
static const std::string CLASS_NAME; |
62 |
|
|
virtual void display(std::ostream &os) const; |
63 |
|
✗ |
virtual const std::string &getClassName(void) const { return CLASS_NAME; } |
64 |
|
|
|
65 |
|
|
protected: |
66 |
|
|
/* Parameters of the hyperbolic-gain function: |
67 |
|
|
* lambda (x) = a * exp (-b*x) + c. */ |
68 |
|
|
double coeff_a; |
69 |
|
|
double coeff_b; |
70 |
|
|
double coeff_c; |
71 |
|
|
double coeff_d; |
72 |
|
|
|
73 |
|
|
public: /* --- CONSTRUCTORS ---- */ |
74 |
|
|
GainHyperbolic(const std::string &name); |
75 |
|
|
GainHyperbolic(const std::string &name, const double &lambda); |
76 |
|
|
GainHyperbolic(const std::string &name, const double &valueAt0, |
77 |
|
|
const double &valueAtInfty, const double &tanAt0, |
78 |
|
|
const double &decal0); |
79 |
|
|
|
80 |
|
|
public: /* --- INIT --- */ |
81 |
|
✗ |
inline void init(void) { init(ZERO_DEFAULT, INFTY_DEFAULT, TAN_DEFAULT, 0); } |
82 |
|
✗ |
inline void init(const double &lambda) { init(lambda, lambda, 1., 0); } |
83 |
|
|
/** Set the coefficients. |
84 |
|
|
* - \f$ a = valueAt0 - valueAtInfty \f$, |
85 |
|
|
* - \f$ b = \frac{tanAt0}{2*a} \f$, or \f$ b = 0 \f$ if \f$ a == 0 \f$, |
86 |
|
|
* - \f$ c = valueAtInfty \f$, |
87 |
|
|
* - \f$ d = decal0 \f$. |
88 |
|
|
*/ |
89 |
|
|
void init(const double &valueAt0, const double &valueAtInfty, |
90 |
|
|
const double &tanAt0, const double &decal0); |
91 |
|
|
void forceConstant(void); |
92 |
|
|
|
93 |
|
|
public: /* --- SIGNALS --- */ |
94 |
|
|
dynamicgraph::SignalPtr<dynamicgraph::Vector, int> errorSIN; |
95 |
|
|
dynamicgraph::SignalTimeDependent<double, int> gainSOUT; |
96 |
|
|
|
97 |
|
|
protected: |
98 |
|
|
double &computeGain(double &res, int t); |
99 |
|
|
}; |
100 |
|
|
|
101 |
|
|
} /* namespace sot */ |
102 |
|
|
} /* namespace dynamicgraph */ |
103 |
|
|
|
104 |
|
|
#endif // #ifndef __SOT_GAIN_HYPERBOLIC_HH__ |
105 |
|
|
|