sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
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 <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 #define PROFILE_DUMMYDCMESTIMATOR_DCM_COMPUTATION \
35  "DummyDcmEstimator: dcm computation "
36 
37 #define INPUT_SIGNALS m_omegaSIN << m_massSIN << m_comSIN << m_momentaSIN
38 
39 #define OUTPUT_SIGNALS m_dcmSOUT
40 
43 typedef DummyDcmEstimator EntityClassName;
44 
45 /* --- DG FACTORY ---------------------------------------------------- */
46 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(DummyDcmEstimator, "DummyDcmEstimator");
47 
48 /* ------------------------------------------------------------------- */
49 /* --- CONSTRUCTION -------------------------------------------------- */
50 /* ------------------------------------------------------------------- */
52  : Entity(name),
53  CONSTRUCT_SIGNAL_IN(omega, double),
54  CONSTRUCT_SIGNAL_IN(mass, double),
55  CONSTRUCT_SIGNAL_IN(com, dynamicgraph::Vector),
56  CONSTRUCT_SIGNAL_IN(momenta, dynamicgraph::Vector),
57  CONSTRUCT_SIGNAL_OUT(dcm, dynamicgraph::Vector, INPUT_SIGNALS),
58  m_initSucceeded(false) {
59  Entity::signalRegistration(INPUT_SIGNALS << OUTPUT_SIGNALS);
60 
61  /* Commands. */
62  addCommand("init",
63  makeCommandVoid0(*this, &DummyDcmEstimator::init,
64  docCommandVoid0("Initialize the entity.")));
65 }
66 
68  if (!m_omegaSIN.isPlugged())
69  return SEND_MSG("Init failed: signal omega is not plugged", MSG_TYPE_ERROR);
70  if (!m_massSIN.isPlugged())
71  return SEND_MSG("Init failed: signal mass is not plugged", MSG_TYPE_ERROR);
72  if (!m_comSIN.isPlugged())
73  return SEND_MSG("Init failed: signal com is not plugged", MSG_TYPE_ERROR);
74  if (!m_momentaSIN.isPlugged())
75  return SEND_MSG("Init failed: signal momenta is not plugged",
76  MSG_TYPE_ERROR);
77 
78  m_initSucceeded = true;
79 }
80 
81 /* ------------------------------------------------------------------- */
82 /* --- SIGNALS ------------------------------------------------------- */
83 /* ------------------------------------------------------------------- */
84 
86  if (!m_initSucceeded) {
87  SEND_WARNING_STREAM_MSG(
88  "Cannot compute signal com_dcom before initialization!");
89  return s;
90  }
91  if (s.size() != 3) s.resize(3);
92 
93  getProfiler().start(PROFILE_DUMMYDCMESTIMATOR_DCM_COMPUTATION);
94 
95  const double& omega = m_omegaSIN(iter);
96  const double& mass = m_massSIN(iter);
97  const Vector& com = m_comSIN(iter);
98  const Vector& momenta = m_momentaSIN(iter);
99 
100  assert(com.size() == 3 && "Unexpected size of signal com");
101  assert((momenta.size() == 3 || momenta.size() == 6) &&
102  "Unexpected size of signal momenta");
103 
104  const Eigen::Vector3d dcom = momenta.head<3>() / mass;
105 
106  const Eigen::Vector3d dcm = com + dcom / omega;
107 
108  s = dcm;
109 
110  getProfiler().stop(PROFILE_DUMMYDCMESTIMATOR_DCM_COMPUTATION);
111 
112  return s;
113 }
114 
115 /* --- COMMANDS ---------------------------------------------------------- */
116 
117 /* ------------------------------------------------------------------- */
118 /* --- ENTITY -------------------------------------------------------- */
119 /* ------------------------------------------------------------------- */
120 
121 void DummyDcmEstimator::display(std::ostream& os) const {
122  os << "DummyDcmEstimator " << getName();
123  try {
124  getProfiler().report_all(3, os);
125  } catch (ExceptionSignal e) {
126  }
127 }
128 } // namespace talos_balance
129 } // namespace sot
130 } // namespace dynamicgraph
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: dummy-dcm-estimator.cpp:37
dynamicgraph::sot::talos_balance::DummyDcmEstimator::DummyDcmEstimator
EIGEN_MAKE_ALIGNED_OPERATOR_NEW DummyDcmEstimator(const std::string &name)
Definition: dummy-dcm-estimator.cpp:51
dynamicgraph
Definition: treeview.dox:24
dynamicgraph::sot::talos_balance::DummyDcmEstimator::display
virtual void display(std::ostream &os) const
Definition: dummy-dcm-estimator.cpp:121
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: dummy-dcm-estimator.cpp:39
sot_talos_balance.test.appli_ankle_admittance.mass
mass
Definition: appli_ankle_admittance.py:36
dynamicgraph::sot::talos_balance::DummyDcmEstimator::m_initSucceeded
bool m_initSucceeded
Definition: dummy-dcm-estimator.hh:78
dynamicgraph::sot::talos_balance::DEFINE_SIGNAL_OUT_FUNCTION
DEFINE_SIGNAL_OUT_FUNCTION(dq, dynamicgraph::Vector)
Definition: admittance-controller-end-effector.cpp:210
dummy-dcm-estimator.hh
dynamicgraph::sot::talos_balance::math::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: fwd.hh:36
PROFILE_DUMMYDCMESTIMATOR_DCM_COMPUTATION
#define PROFILE_DUMMYDCMESTIMATOR_DCM_COMPUTATION
Definition: dummy-dcm-estimator.cpp:34
dynamicgraph::sot::talos_balance::DummyDcmEstimator::init
void init()
Definition: dummy-dcm-estimator.cpp:67
dynamicgraph::sot::talos_balance::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
sot_talos_balance.test.appli_ankle_admittance.omega
omega
Definition: appli_ankle_admittance.py:39
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