GCC Code Coverage Report


Directory: ./
File: src/task/gain-hyperbolic.cpp
Date: 2024-08-13 12:13:25
Exec Total Coverage
Lines: 0 34 0.0%
Branches: 0 82 0.0%

Line Branch Exec Source
1 /*
2 * Copyright 2010,
3 * François Bleibel,
4 * Olivier Stasse,
5 *
6 * CNRS/AIST
7 *
8 */
9
10 /* SOT */
11 #include <sot/core/gain-hyperbolic.hh>
12
13 /* --------------------------------------------------------------------- */
14 /* --------------------------------------------------------------------- */
15 /* --------------------------------------------------------------------- */
16
17 #include <sot/core/debug.hh>
18 #include <sot/core/exception-signal.hh>
19 #include <sot/core/factory.hh>
20
21 using namespace dynamicgraph::sot;
22 using namespace dynamicgraph;
23
24 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(GainHyperbolic, "GainHyperbolic");
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
41 GainHyperbolic::GainHyperbolic(const std::string &name)
42 : __SOT_GAIN_HYPERBOLIC_INIT {
43 sotDEBUG(15) << "New gain <" << name << ">" << std::endl;
44 init();
45 Entity::signalRegistration(gainSOUT << errorSIN);
46 }
47
48 GainHyperbolic::GainHyperbolic(const std::string &name, const double &lambda)
49 : __SOT_GAIN_HYPERBOLIC_INIT {
50 init(lambda);
51 Entity::signalRegistration(gainSOUT);
52 }
53
54 GainHyperbolic::GainHyperbolic(const std::string &name, const double &valueAt0,
55 const double &valueAtInfty, const double &tanAt0,
56 const double &decal0)
57 : __SOT_GAIN_HYPERBOLIC_INIT {
58 init(valueAt0, valueAtInfty, tanAt0, decal0);
59 Entity::signalRegistration(gainSOUT);
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
76 void GainHyperbolic::forceConstant(void) { coeff_a = 0; }
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 }
105