sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
example.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/factory.h>
21 
22 #include <sot/core/debug.hh>
23 #include <sot/core/stop-watch.hh>
24 
25 namespace dynamicgraph {
26 namespace sot {
27 namespace talos_balance {
28 namespace dg = ::dynamicgraph;
29 using namespace dg;
30 using namespace dg::command;
31 
32 // Size to be aligned "-------------------------------------------------------"
33 #define PROFILE_EXAMPLE_SUM_COMPUTATION \
34  "Example: sum computation "
35 #define PROFILE_EXAMPLE_NBJOINTS_COMPUTATION \
36  "Example: nbJoints extraction "
37 
38 #define INPUT_SIGNALS m_firstAddendSIN << m_secondAddendSIN
39 
40 #define OUTPUT_SIGNALS m_sumSOUT << m_nbJointsSOUT
41 
44 typedef Example EntityClassName;
45 
46 /* --- DG FACTORY ---------------------------------------------------- */
47 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(Example, "Example");
48 
49 /* ------------------------------------------------------------------- */
50 /* --- CONSTRUCTION -------------------------------------------------- */
51 /* ------------------------------------------------------------------- */
52 Example::Example(const std::string& name)
53  : Entity(name),
54  CONSTRUCT_SIGNAL_IN(firstAddend, double),
55  CONSTRUCT_SIGNAL_IN(secondAddend, double),
56  CONSTRUCT_SIGNAL_OUT(sum, double, INPUT_SIGNALS),
57  CONSTRUCT_SIGNAL_OUT(nbJoints, int, INPUT_SIGNALS),
58  m_initSucceeded(false) {
59  Entity::signalRegistration(INPUT_SIGNALS << OUTPUT_SIGNALS);
60 
61  /* Commands. */
62  addCommand("init", makeCommandVoid1(*this, &Example::init,
63  docCommandVoid1("Initialize the entity.",
64  "Robot name")));
65 }
66 
67 void Example::init(const std::string& robotName) {
68  if (!m_firstAddendSIN.isPlugged())
69  return SEND_MSG("Init failed: signal firstAddend is not plugged",
70  MSG_TYPE_ERROR);
71  if (!m_secondAddendSIN.isPlugged())
72  return SEND_MSG("Init failed: signal secondAddend is not plugged",
73  MSG_TYPE_ERROR);
74 
75  /*std::string & robotName_nonconst = const_cast<std::string &>(robotName);*/
76  std::string robotName_nonconst(robotName);
77 
78  if (!isNameInRobotUtil(robotName_nonconst)) {
79  SEND_MSG("You should have a robotUtil pointer initialized before",
80  MSG_TYPE_ERROR);
81  } else {
82  m_robot_util = getRobotUtil(robotName_nonconst);
83  std::cerr << "m_robot_util:" << m_robot_util << std::endl;
84  }
85  for (unsigned int i = 0; i < 4; i++) {
86  std::cout << "Verbosity Level :" << i << std::endl;
87  Example::setLoggerVerbosityLevel((dynamicgraph::LoggerVerbosity)i);
88  Example::sendMsg("TEST MSG ERROR", dynamicgraph::MSG_TYPE_ERROR);
89  Example::sendMsg("TEST MSG DEBUG", dynamicgraph::MSG_TYPE_DEBUG);
90  Example::sendMsg("TEST MSG INFO", dynamicgraph::MSG_TYPE_INFO);
91  Example::sendMsg("TEST MSG WARNING", dynamicgraph::MSG_TYPE_WARNING);
92  }
93  m_initSucceeded = true;
94 }
95 
96 /* ------------------------------------------------------------------- */
97 /* --- SIGNALS ------------------------------------------------------- */
98 /* ------------------------------------------------------------------- */
99 
101  if (!m_initSucceeded) {
102  SEND_WARNING_STREAM_MSG("Cannot compute signal sum before initialization!");
103  return s;
104  }
105 
106  getProfiler().start(PROFILE_EXAMPLE_SUM_COMPUTATION);
107 
108  double firstAddend = m_firstAddendSIN(iter);
109  double secondAddend = m_secondAddendSIN(iter);
110 
111  s = firstAddend + secondAddend;
112 
113  getProfiler().stop(PROFILE_EXAMPLE_SUM_COMPUTATION);
114 
115  return s;
116 }
117 
119  if (!m_initSucceeded) {
120  SEND_WARNING_STREAM_MSG(
121  "Cannot compute signal nbJoints before initialization!");
122  return s;
123  }
124  (void)iter;
125 
126  getProfiler().start(PROFILE_EXAMPLE_NBJOINTS_COMPUTATION);
127 
128  s = int(m_robot_util->m_nbJoints);
129 
130  getProfiler().stop(PROFILE_EXAMPLE_NBJOINTS_COMPUTATION);
131 
132  return s;
133 }
134 
135 /* --- COMMANDS ---------------------------------------------------------- */
136 
137 /* ------------------------------------------------------------------- */
138 /* --- ENTITY -------------------------------------------------------- */
139 /* ------------------------------------------------------------------- */
140 
141 void Example::display(std::ostream& os) const {
142  os << "Example " << getName();
143  try {
144  getProfiler().report_all(3, os);
145  } catch (ExceptionSignal e) {
146  }
147 }
148 
149 } // namespace talos_balance
150 } // namespace sot
151 } // namespace dynamicgraph
dynamicgraph::sot::talos_balance::Example::init
void init(const std::string &robotName)
Definition: example.cpp:67
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
sot_talos_balance.test.appli_ankle_admittance.robotName
string robotName
Definition: appli_ankle_admittance.py:33
dynamicgraph::sot::talos_balance::Example::display
virtual void display(std::ostream &os) const
Definition: example.cpp:141
example.hh
dynamicgraph
Definition: treeview.dox:24
PROFILE_EXAMPLE_SUM_COMPUTATION
#define PROFILE_EXAMPLE_SUM_COMPUTATION
Definition: example.cpp:33
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::Example::m_initSucceeded
bool m_initSucceeded
Definition: example.hh:80
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: example.cpp:38
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: example.cpp:40
dynamicgraph::sot::talos_balance::Example::Example
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Example(const std::string &name)
Definition: example.cpp:52
dynamicgraph::sot::talos_balance::Example::m_robot_util
RobotUtilShrPtr m_robot_util
true if the entity has been successfully initialized
Definition: example.hh:81
PROFILE_EXAMPLE_NBJOINTS_COMPUTATION
#define PROFILE_EXAMPLE_NBJOINTS_COMPUTATION
Definition: example.cpp:35
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