sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
saturation.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018, Gepetto team, LAAS-CNRS
3  *
4  * This file is part of sot-talos-balance.
5  * sot-talos-balance is free software: you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation, either version 3 of
8  * the License, or (at your option) any later version.
9  * sot-talos-balance is distributed in the hope that it will be
10  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details. You should
13  * have received a copy of the GNU Lesser General Public License along
14  * with sot-talos-balance. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
18 
19 #include <dynamic-graph/all-commands.h>
20 #include <dynamic-graph/command-bind.h>
21 #include <dynamic-graph/factory.h>
22 
23 #include <sot/core/debug.hh>
24 #include <sot/core/stop-watch.hh>
25 
26 namespace dynamicgraph {
27 namespace sot {
28 namespace talos_balance {
29 namespace dg = ::dynamicgraph;
30 using namespace dg;
31 using namespace dg::command;
32 
33 //Size to be aligned\
34 "-------------------------------------------------------"
35 
36 #define PROFILE_SATURATION_SOUT_COMPUTATION "Saturation: sOut computation"
37 
38 #define INPUT_SIGNALS m_xSIN << m_ySIN << m_kSIN << m_xLimSIN << m_yLimSIN
39 
40 #define OUTPUT_SIGNALS m_yOutSOUT
41 
44 typedef Saturation EntityClassName;
45 
46 /* --- DG FACTORY ---------------------------------------------------- */
47 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(Saturation, "Saturation");
48 
49 /* ------------------------------------------------------------------- */
50 /* --- CONSTRUCTION -------------------------------------------------- */
51 /* ------------------------------------------------------------------- */
52 Saturation::Saturation(const std::string &name)
53  : Entity(name),
54  CONSTRUCT_SIGNAL_IN(x, dynamicgraph::Vector),
55  CONSTRUCT_SIGNAL_IN(y, dynamicgraph::Vector),
56  CONSTRUCT_SIGNAL_IN(k, double),
57  CONSTRUCT_SIGNAL_IN(xLim, dynamicgraph::Vector),
58  CONSTRUCT_SIGNAL_IN(yLim, dynamicgraph::Vector),
59  CONSTRUCT_SIGNAL_OUT(yOut, dynamicgraph::Vector, INPUT_SIGNALS) {
60  Entity::signalRegistration(INPUT_SIGNALS << OUTPUT_SIGNALS);
61 }
62 
63 /* ------------------------------------------------------------------- */
64 /* --- SIGNALS ------------------------------------------------------- */
65 /* ------------------------------------------------------------------- */
66 
68  getProfiler().start(PROFILE_SATURATION_SOUT_COMPUTATION);
69 
70  const double &x = m_xSIN(iter)[0];
71  s = m_ySIN(iter);
72  const double &y = s[0];
73  const double &k = m_kSIN(iter);
74  const double &xLim = m_xLimSIN(iter)[0];
75  const double &yLim = m_yLimSIN(iter)[0];
76 
77  double r = y;
78 
79  assert(k > 0 && "k must be strictly positive");
80  assert(xLim > 0 && "xLim must be strictly positive");
81  assert(yLim > 0 && "yLim must be strictly positive");
82 
83  if ((x <= -xLim) or (x > xLim)) {
84  r = 0.0;
85  } else if (-xLim + yLim / k < x and x <= xLim - yLim / k) {
86  r = std::min(std::max(y, -yLim), yLim);
87  } else if (-xLim < x and x <= -xLim + yLim / k) {
88  r = std::min(std::max(y, -k * (x + xLim)), k * (x + xLim));
89  } else if (xLim - yLim / k < x and x <= xLim) {
90  r = std::min(std::max(y, -yLim + k * (x - xLim + yLim / k)),
91  yLim - k * (x - xLim + yLim / k));
92  }
93 
94  s[0] = r;
95 
96  getProfiler().stop(PROFILE_SATURATION_SOUT_COMPUTATION);
97 
98  return s;
99 }
100 
101 /* --- COMMANDS ---------------------------------------------------------- */
102 
103 /* ------------------------------------------------------------------- */
104 /* --- ENTITY -------------------------------------------------------- */
105 /* ------------------------------------------------------------------- */
106 
107 void Saturation::display(std::ostream &os) const {
108  os << "Saturation " << getName();
109  try {
110  getProfiler().report_all(3, os);
111  } catch (ExceptionSignal e) {
112  }
113 }
114 } // namespace talos_balance
115 } // namespace sot
116 } // namespace dynamicgraph
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: saturation.cpp:38
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
saturation.hh
dynamicgraph
Definition: treeview.dox:24
PROFILE_SATURATION_SOUT_COMPUTATION
#define PROFILE_SATURATION_SOUT_COMPUTATION
Definition: saturation.cpp:36
sot_talos_balance.test.script_test_end_effector.y
y
Definition: script_test_end_effector.py:11
dynamicgraph::sot::talos_balance::DEFINE_SIGNAL_OUT_FUNCTION
DEFINE_SIGNAL_OUT_FUNCTION(dq, dynamicgraph::Vector)
Definition: admittance-controller-end-effector.cpp:210
dynamicgraph::sot::talos_balance::Saturation::Saturation
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Saturation(const std::string &name)
Definition: saturation.cpp:52
sot_talos_balance.test.script_test_end_effector.x
x
Definition: script_test_end_effector.py:10
dynamicgraph::sot::talos_balance::math::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: fwd.hh:36
dynamicgraph::sot::talos_balance::Saturation::display
virtual void display(std::ostream &os) const
Definition: saturation.cpp:107
dynamicgraph::sot::talos_balance::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
dynamicgraph::sot::talos_balance::EntityClassName
AdmittanceControllerEndEffector EntityClassName
Definition: admittance-controller-end-effector.cpp:46
sot_talos_balance.test.appli_dcm_zmp_control.name
name
Definition: appli_dcm_zmp_control.py:298
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: saturation.cpp:40