sot-talos-balance  1.5.0
dummy-dcm-estimator.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 <sot/core/debug.hh>
20 #include <dynamic-graph/factory.h>
21 #include <dynamic-graph/command-bind.h>
22 
23 #include <dynamic-graph/all-commands.h>
24 #include <sot/core/stop-watch.hh>
25 
26 namespace dynamicgraph
27 {
28  namespace sot
29  {
30  namespace talos_balance
31  {
32  namespace dg = ::dynamicgraph;
33  using namespace dg;
34  using namespace dg::command;
35 
36 //Size to be aligned "-------------------------------------------------------"
37 #define PROFILE_DUMMYDCMESTIMATOR_DCM_COMPUTATION "DummyDcmEstimator: dcm computation "
38 
39 #define INPUT_SIGNALS m_omegaSIN << m_massSIN << m_comSIN << m_momentaSIN
40 
41 #define OUTPUT_SIGNALS m_dcmSOUT
42 
45  typedef DummyDcmEstimator EntityClassName;
46 
47  /* --- DG FACTORY ---------------------------------------------------- */
48  DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(DummyDcmEstimator,
49  "DummyDcmEstimator");
50 
51  /* ------------------------------------------------------------------- */
52  /* --- CONSTRUCTION -------------------------------------------------- */
53  /* ------------------------------------------------------------------- */
54  DummyDcmEstimator::DummyDcmEstimator(const std::string& name)
55  : Entity(name)
56  , CONSTRUCT_SIGNAL_IN(omega, double)
57  , CONSTRUCT_SIGNAL_IN(mass, double)
58  , CONSTRUCT_SIGNAL_IN(com, dynamicgraph::Vector)
59  , CONSTRUCT_SIGNAL_IN(momenta, dynamicgraph::Vector)
60  , CONSTRUCT_SIGNAL_OUT(dcm, dynamicgraph::Vector, INPUT_SIGNALS)
61  , m_initSucceeded(false)
62  {
63  Entity::signalRegistration( INPUT_SIGNALS << OUTPUT_SIGNALS );
64 
65  /* Commands. */
66  addCommand("init", makeCommandVoid0(*this, &DummyDcmEstimator::init, docCommandVoid0("Initialize the entity.")));
67  }
68 
70  {
71  if(!m_omegaSIN.isPlugged())
72  return SEND_MSG("Init failed: signal omega is not plugged", MSG_TYPE_ERROR);
73  if(!m_massSIN.isPlugged())
74  return SEND_MSG("Init failed: signal mass is not plugged", MSG_TYPE_ERROR);
75  if(!m_comSIN.isPlugged())
76  return SEND_MSG("Init failed: signal com is not plugged", MSG_TYPE_ERROR);
77  if(!m_momentaSIN.isPlugged())
78  return SEND_MSG("Init failed: signal momenta is not plugged", MSG_TYPE_ERROR);
79 
80  m_initSucceeded = true;
81  }
82 
83  /* ------------------------------------------------------------------- */
84  /* --- SIGNALS ------------------------------------------------------- */
85  /* ------------------------------------------------------------------- */
86 
88  {
89  if(!m_initSucceeded)
90  {
91  SEND_WARNING_STREAM_MSG("Cannot compute signal com_dcom before initialization!");
92  return s;
93  }
94 
95  getProfiler().start(PROFILE_DUMMYDCMESTIMATOR_DCM_COMPUTATION);
96 
97  const double & omega = m_omegaSIN(iter);
98  const double & mass = m_massSIN(iter);
99  const Vector & com = m_comSIN(iter);
100  const Vector & momenta = m_momentaSIN(iter);
101 
102  assert( com.size()==3 && "Unexpected size of signal com" );
103  assert( (momenta.size()==3 || momenta.size()==6) && "Unexpected size of signal momenta" );
104 
105  const Vector dcom = momenta.head<3>()/mass;
106 
107  const Vector dcm = com + dcom/omega;
108 
109  s = dcm;
110 
111  getProfiler().stop(PROFILE_DUMMYDCMESTIMATOR_DCM_COMPUTATION);
112 
113  return s;
114  }
115 
116  /* --- COMMANDS ---------------------------------------------------------- */
117 
118  /* ------------------------------------------------------------------- */
119  /* --- ENTITY -------------------------------------------------------- */
120  /* ------------------------------------------------------------------- */
121 
122  void DummyDcmEstimator::display(std::ostream& os) const
123  {
124  os << "DummyDcmEstimator " << getName();
125  try
126  {
127  getProfiler().report_all(3, os);
128  }
129  catch (ExceptionSignal e) {}
130  }
131  } // namespace talos_balance
132  } // namespace sot
133 } // namespace dynamicgraph
134 
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: math/fwd.hh:40
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
#define PROFILE_DUMMYDCMESTIMATOR_DCM_COMPUTATION
#define INPUT_SIGNALS
EIGEN_MAKE_ALIGNED_OPERATOR_NEW DummyDcmEstimator(const std::string &name)
#define OUTPUT_SIGNALS