gain-hyperbolic.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 /* SOT */
12 
13 /* --------------------------------------------------------------------- */
14 /* --------------------------------------------------------------------- */
15 /* --------------------------------------------------------------------- */
16 
17 #include <sot/core/debug.hh>
19 #include <sot/core/factory.hh>
20 
21 using namespace dynamicgraph::sot;
22 using namespace dynamicgraph;
23 
25 
26 const double GainHyperbolic::ZERO_DEFAULT = .1;
27 const double GainHyperbolic::INFTY_DEFAULT = .1;
28 const double GainHyperbolic::TAN_DEFAULT = 1;
29 
30 /* --------------------------------------------------------------------- */
31 /* --------------------------------------------------------------------- */
32 /* --------------------------------------------------------------------- */
33 
34 #define __SOT_GAIN_HYPERBOLIC_INIT \
35  Entity(name), coeff_a(0), coeff_b(0), coeff_c(0), coeff_d(0), \
36  errorSIN(NULL, "sotGainHyperbolic(" + name + ")::input(vector)::error"), \
37  gainSOUT(boost::bind(&GainHyperbolic::computeGain, this, _1, _2), \
38  errorSIN, \
39  "sotGainHyperbolic(" + name + ")::output(double)::gain")
40 
43  sotDEBUG(15) << "New gain <" << name << ">" << std::endl;
44  init();
46 }
47 
48 GainHyperbolic::GainHyperbolic(const std::string &name, const double &lambda)
50  init(lambda);
52 }
53 
54 GainHyperbolic::GainHyperbolic(const std::string &name, const double &valueAt0,
55  const double &valueAtInfty, const double &tanAt0,
56  const double &decal0)
58  init(valueAt0, valueAtInfty, tanAt0, decal0);
60 }
61 
62 void GainHyperbolic::init(const double &valueAt0, const double &valueAtInfty,
63  const double &tanAt0, const double &decal0) {
64  coeff_a = valueAt0 - valueAtInfty;
65  if (0 == coeff_a) {
66  coeff_b = 0;
67  } else {
68  coeff_b = tanAt0 / coeff_a / 2;
69  }
70  coeff_c = valueAtInfty;
71  coeff_d = decal0;
72 
73  return;
74 }
75 
77 
78 /* --------------------------------------------------------------------- */
79 /* --------------------------------------------------------------------- */
80 /* --------------------------------------------------------------------- */
81 
82 void GainHyperbolic::display(std::ostream &os) const {
83  os << "Gain Hyperbolic " << getName();
84  try {
85  os << " = " << double(gainSOUT.accessCopy());
86  } catch (ExceptionSignal e) {
87  }
88  // os <<" ("<<coeff_a<<";"<<coeff_b<<";"<<coeff_c<<coeff_d<<") ";
89  os << " (" << coeff_a << ".exp(-" << coeff_b << "(x-" << coeff_d << "))+"
90  << coeff_c;
91 }
92 
93 /* --------------------------------------------------------------------- */
94 /* --------------------------------------------------------------------- */
95 /* --------------------------------------------------------------------- */
96 double &GainHyperbolic::computeGain(double &res, int t) {
97  sotDEBUGIN(15);
98  const dynamicgraph::Vector &error = errorSIN(t);
99  const double norm = error.norm();
100  res = coeff_a * .5 * (tanh(-coeff_b * (norm - coeff_d)) + 1) + coeff_c;
101 
102  sotDEBUGOUT(15);
103  return res;
104 }
virtual void display(std::ostream &os) const
Eigen::VectorXd Vector
void signalRegistration(const SignalArray< int > &signals)
#define sotDEBUGOUT(level)
Definition: debug.hh:212
GainHyperbolic(const std::string &name)
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeaturePosture, "FeaturePosture")
#define sotDEBUGIN(level)
Definition: debug.hh:211
dynamicgraph::SignalTimeDependent< double, int > gainSOUT
Hyperbolic gain. It follows the law The default coefficients are:
#define __SOT_GAIN_HYPERBOLIC_INIT
#define sotDEBUG(level)
Definition: debug.hh:165
const std::string & getName() const
double & computeGain(double &res, int t)
Transform3f t
virtual const T & accessCopy() const
dynamicgraph::SignalPtr< dynamicgraph::Vector, int > errorSIN


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26