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 (const 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, sigtime_t 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 }
exception-signal.hh
factory.hh
dynamicgraph::sot::GainHyperbolic::errorSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > errorSIN
Definition: gain-hyperbolic.hh:94
dynamicgraph
dynamicgraph::sot::GainHyperbolic::init
void init(void)
Definition: gain-hyperbolic.hh:81
dynamicgraph::Entity::name
std::string name
dynamicgraph::sot::GainHyperbolic::coeff_d
double coeff_d
Definition: gain-hyperbolic.hh:71
gain-hyperbolic.hh
dynamicgraph::sot::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeaturePosture, "FeaturePosture")
dynamicgraph::Entity::getName
const std::string & getName() const
dynamicgraph::sot::GainHyperbolic::ZERO_DEFAULT
static const double ZERO_DEFAULT
Definition: gain-hyperbolic.hh:56
debug.hh
dynamicgraph::sot::GainHyperbolic::TAN_DEFAULT
static const double TAN_DEFAULT
Definition: gain-hyperbolic.hh:58
res
res
sotDEBUGOUT
#define sotDEBUGOUT(level)
Definition: debug.hh:215
dynamicgraph::sigtime_t
int64_t sigtime_t
sotDEBUGIN
#define sotDEBUGIN(level)
Definition: debug.hh:214
dynamicgraph::sot::GainHyperbolic::coeff_a
double coeff_a
Definition: gain-hyperbolic.hh:68
dynamicgraph::sot::GainHyperbolic::display
virtual void display(std::ostream &os) const
Definition: gain-hyperbolic.cpp:82
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::GainHyperbolic::forceConstant
void forceConstant(void)
Definition: gain-hyperbolic.cpp:76
dynamicgraph::ExceptionSignal
dynamicgraph::sot::double
double
Definition: fir-filter.cpp:49
dynamicgraph::sot::GainHyperbolic::coeff_c
double coeff_c
Definition: gain-hyperbolic.hh:70
dynamicgraph::sot::GainHyperbolic::coeff_b
double coeff_b
Definition: gain-hyperbolic.hh:69
dynamicgraph::sot
dynamicgraph::sot::GainHyperbolic::computeGain
double & computeGain(double &res, sigtime_t t)
Definition: gain-hyperbolic.cpp:96
t
Transform3f t
dynamicgraph::sot::GainHyperbolic::gainSOUT
dynamicgraph::SignalTimeDependent< double, sigtime_t > gainSOUT
Definition: gain-hyperbolic.hh:95
__SOT_GAIN_HYPERBOLIC_INIT
#define __SOT_GAIN_HYPERBOLIC_INIT
Definition: gain-hyperbolic.cpp:34
dynamicgraph::sot::GainHyperbolic
Hyperbolic gain. It follows the law.
Definition: gain-hyperbolic.hh:53
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
dynamicgraph::sot::GainHyperbolic::GainHyperbolic
GainHyperbolic(const std::string &name)
Definition: gain-hyperbolic.cpp:41
compile.name
name
Definition: compile.py:23
dynamicgraph::sot::GainHyperbolic::INFTY_DEFAULT
static const double INFTY_DEFAULT
Definition: gain-hyperbolic.hh:57
sotDEBUG
#define sotDEBUG(level)
Definition: debug.hh:168


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31