sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
dummy-walking-pattern-generator.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_DUMMYWALKINGPATTERNGENERATOR_DCM_COMPUTATION \
35  "DummyWalkingPatternGenerator: dcm computation "
36 
37 #define INPUT_SIGNALS \
38  m_omegaSIN << m_rhoSIN << m_phaseSIN << m_footLeftSIN << m_footRightSIN \
39  << m_waistSIN << m_comSIN << m_vcomSIN << m_acomSIN << m_zmpSIN \
40  << m_referenceFrameSIN
41 
42 #define INNER_SIGNALS m_rfSINNER
43 
44 #define OUTPUT_SIGNALS \
45  m_comDesSOUT << m_vcomDesSOUT << m_acomDesSOUT << m_dcmDesSOUT \
46  << m_zmpDesSOUT << m_footLeftDesSOUT << m_footRightDesSOUT \
47  << m_waistDesSOUT << m_omegaDesSOUT << m_rhoDesSOUT \
48  << m_phaseDesSOUT
49 
52 typedef DummyWalkingPatternGenerator EntityClassName;
53 
54 /* --- DG FACTORY ---------------------------------------------------- */
55 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(DummyWalkingPatternGenerator,
56  "DummyWalkingPatternGenerator");
57 
58 /* ------------------------------------------------------------------- */
59 /* --- CONSTRUCTION -------------------------------------------------- */
60 /* ------------------------------------------------------------------- */
62  const std::string& name)
63  : Entity(name),
64  CONSTRUCT_SIGNAL_IN(omega, double),
65  CONSTRUCT_SIGNAL_IN(rho, double),
66  CONSTRUCT_SIGNAL_IN(phase, int),
67  CONSTRUCT_SIGNAL_IN(footLeft, MatrixHomogeneous),
68  CONSTRUCT_SIGNAL_IN(footRight, MatrixHomogeneous),
69  CONSTRUCT_SIGNAL_IN(waist, MatrixHomogeneous),
70  CONSTRUCT_SIGNAL_IN(com, dynamicgraph::Vector),
71  CONSTRUCT_SIGNAL_IN(vcom, dynamicgraph::Vector),
72  CONSTRUCT_SIGNAL_IN(acom, dynamicgraph::Vector),
73  CONSTRUCT_SIGNAL_IN(zmp, dynamicgraph::Vector),
74  CONSTRUCT_SIGNAL_IN(referenceFrame, MatrixHomogeneous),
75  CONSTRUCT_SIGNAL_INNER(rf, MatrixHomogeneous, m_referenceFrameSIN),
76  CONSTRUCT_SIGNAL_OUT(comDes, dynamicgraph::Vector,
77  m_comSIN << m_rfSINNER),
78  CONSTRUCT_SIGNAL_OUT(vcomDes, dynamicgraph::Vector,
79  m_vcomSIN << m_rfSINNER),
80  CONSTRUCT_SIGNAL_OUT(acomDes, dynamicgraph::Vector,
81  m_acomSIN << m_rfSINNER),
82  CONSTRUCT_SIGNAL_OUT(dcmDes, dynamicgraph::Vector,
83  m_omegaSIN << m_comDesSOUT << m_vcomDesSOUT),
84  CONSTRUCT_SIGNAL_OUT(zmpDes, dynamicgraph::Vector,
85  m_omegaSIN << m_comDesSOUT << m_acomDesSOUT
86  << m_rfSINNER << m_zmpSIN),
87  CONSTRUCT_SIGNAL_OUT(footLeftDes, MatrixHomogeneous,
88  m_footLeftSIN << m_rfSINNER),
89  CONSTRUCT_SIGNAL_OUT(footRightDes, MatrixHomogeneous,
90  m_footRightSIN << m_rfSINNER),
91  CONSTRUCT_SIGNAL_OUT(waistDes, MatrixHomogeneous,
92  m_waistSIN << m_rfSINNER),
93  CONSTRUCT_SIGNAL_OUT(omegaDes, double, m_omegaSIN),
94  CONSTRUCT_SIGNAL_OUT(rhoDes, double, m_rhoSIN),
95  CONSTRUCT_SIGNAL_OUT(phaseDes, int, m_phaseSIN),
96  m_initSucceeded(false) {
97  Entity::signalRegistration(INPUT_SIGNALS << OUTPUT_SIGNALS);
98 
99  /* Commands. */
100  addCommand("init",
101  makeCommandVoid0(*this, &DummyWalkingPatternGenerator::init,
102  docCommandVoid0("Initialize the entity.")));
103 }
104 
106  MatrixHomogeneous m, dynamicgraph::Vector v) {
107  return m.linear().transpose() * (v - m.translation());
108 }
109 
110 MatrixHomogeneous DummyWalkingPatternGenerator::actInv(MatrixHomogeneous m1,
111  MatrixHomogeneous m2) {
112  MatrixHomogeneous res;
113  res.linear() = m1.linear().transpose() * m2.linear();
114  res.translation() =
115  m1.linear().transpose() * (m2.translation() - m1.translation());
116  return res;
117 }
118 
120 
121 /* ------------------------------------------------------------------- */
122 /* --- SIGNALS ------------------------------------------------------- */
123 /* ------------------------------------------------------------------- */
124 
125 DEFINE_SIGNAL_INNER_FUNCTION(rf, MatrixHomogeneous) {
126  if (!m_initSucceeded) {
127  SEND_WARNING_STREAM_MSG("Cannot compute signal rf before initialization!");
128  return s;
129  }
130 
131  s = m_referenceFrameSIN.isPlugged() ? m_referenceFrameSIN(iter)
132  : MatrixHomogeneous::Identity();
133 
134  return s;
135 }
136 
138  if (!m_initSucceeded) {
139  SEND_WARNING_STREAM_MSG(
140  "Cannot compute signal comDes before initialization!");
141  return s;
142  }
143  if (s.size() != 3) s.resize(3);
144 
145  const Vector& com = m_comSIN(iter);
146  const MatrixHomogeneous& referenceFrame = m_rfSINNER(iter);
147 
148  assert(com.size() == 3 && "Unexpected size of signal com");
149 
150  s = actInv(referenceFrame, com);
151 
152  return s;
153 }
154 
156  if (!m_initSucceeded) {
157  SEND_WARNING_STREAM_MSG(
158  "Cannot compute signal vcomDes before initialization!");
159  return s;
160  }
161  if (s.size() != 3) s.resize(3);
162 
163  const Vector& vcom = m_vcomSIN(iter);
164  const MatrixHomogeneous& referenceFrame = m_rfSINNER(iter);
165 
166  assert(vcom.size() == 3 && "Unexpected size of signal vcom");
167 
168  s = referenceFrame.linear().transpose() * vcom;
169 
170  return s;
171 }
172 
174  if (!m_initSucceeded) {
175  SEND_WARNING_STREAM_MSG(
176  "Cannot compute signal acomDes before initialization!");
177  return s;
178  }
179  if (s.size() != 3) s.resize(3);
180 
181  const Vector& acom = m_acomSIN(iter);
182  const MatrixHomogeneous& referenceFrame = m_rfSINNER(iter);
183 
184  assert(acom.size() == 3 && "Unexpected size of signal acom");
185 
186  s = referenceFrame.linear().transpose() * acom;
187 
188  return s;
189 }
190 
192  if (!m_initSucceeded) {
193  SEND_WARNING_STREAM_MSG(
194  "Cannot compute signal dcmDes before initialization!");
195  return s;
196  }
197  if (s.size() != 3) s.resize(3);
198 
199  const double& omega = m_omegaSIN(iter);
200  const Vector& comDes = m_comDesSOUT(iter);
201  const Vector& vcomDes = m_vcomDesSOUT(iter);
202 
203  s = comDes + vcomDes / omega;
204 
205  return s;
206 }
207 
209  if (!m_initSucceeded) {
210  SEND_WARNING_STREAM_MSG(
211  "Cannot compute signal zmpDes before initialization!");
212  return s;
213  }
214  if (s.size() != 3) s.resize(3);
215 
216  Eigen::Vector3d zmpDes;
217 
218  if (m_zmpSIN.isPlugged()) {
219  const Vector& zmp = m_zmpSIN(iter);
220  const MatrixHomogeneous& referenceFrame = m_rfSINNER(iter);
221 
222  zmpDes[0] = zmp[0];
223  zmpDes[1] = zmp[1];
224  zmpDes[2] = zmp.size() > 2 ? zmp[2] : 0.;
225 
226  zmpDes = actInv(referenceFrame, zmpDes);
227  } else {
228  const double& omega = m_omegaSIN(iter);
229  const Vector& comDes = m_comDesSOUT(iter);
230  const Vector& acomDes = m_acomDesSOUT(iter);
231 
232  zmpDes = comDes - acomDes / (omega * omega);
233  zmpDes[2] = 0.0;
234  }
235 
236  s = zmpDes;
237 
238  return s;
239 }
240 
241 DEFINE_SIGNAL_OUT_FUNCTION(footLeftDes, MatrixHomogeneous) {
242  if (!m_initSucceeded) {
243  SEND_WARNING_STREAM_MSG(
244  "Cannot compute signal footLeftDes before initialization!");
245  return s;
246  }
247 
248  MatrixHomogeneous footLeft = m_footLeftSIN(iter);
249 
250  const MatrixHomogeneous& referenceFrame = m_rfSINNER(iter);
251 
252  s = actInv(referenceFrame, footLeft);
253 
254  return s;
255 }
256 
257 DEFINE_SIGNAL_OUT_FUNCTION(footRightDes, MatrixHomogeneous) {
258  if (!m_initSucceeded) {
259  SEND_WARNING_STREAM_MSG(
260  "Cannot compute signal footRightDes before initialization!");
261  return s;
262  }
263 
264  MatrixHomogeneous footRight = m_footRightSIN(iter);
265 
266  const MatrixHomogeneous& referenceFrame = m_rfSINNER(iter);
267 
268  s = actInv(referenceFrame, footRight);
269 
270  return s;
271 }
272 
273 DEFINE_SIGNAL_OUT_FUNCTION(waistDes, MatrixHomogeneous) {
274  if (!m_initSucceeded) {
275  SEND_WARNING_STREAM_MSG(
276  "Cannot compute signal waistDes before initialization!");
277  return s;
278  }
279 
280  const MatrixHomogeneous& waist = m_waistSIN(iter);
281  const MatrixHomogeneous& referenceFrame = m_rfSINNER(iter);
282 
283  s = actInv(referenceFrame, waist);
284 
285  return s;
286 }
287 
288 DEFINE_SIGNAL_OUT_FUNCTION(omegaDes, double) {
289  if (!m_initSucceeded) {
290  SEND_WARNING_STREAM_MSG(
291  "Cannot compute signal omegaDes before initialization!");
292  return s;
293  }
294 
295  s = m_omegaSIN(iter);
296  return s;
297 }
298 
299 DEFINE_SIGNAL_OUT_FUNCTION(rhoDes, double) {
300  if (!m_initSucceeded) {
301  SEND_WARNING_STREAM_MSG(
302  "Cannot compute signal rhoDes before initialization!");
303  return s;
304  }
305 
306  s = m_rhoSIN(iter);
307  return s;
308 }
309 
311  if (!m_initSucceeded) {
312  SEND_WARNING_STREAM_MSG(
313  "Cannot compute signal phaseDes before initialization!");
314  return s;
315  }
316 
317  s = m_phaseSIN(iter);
318  return s;
319 }
320 
321 /* --- COMMANDS ---------------------------------------------------------- */
322 
323 /* ------------------------------------------------------------------- */
324 /* --- ENTITY -------------------------------------------------------- */
325 /* ------------------------------------------------------------------- */
326 
327 void DummyWalkingPatternGenerator::display(std::ostream& os) const {
328  os << "DummyWalkingPatternGenerator " << getName();
329  try {
330  getProfiler().report_all(3, os);
331  } catch (ExceptionSignal e) {
332  }
333 }
334 } // namespace talos_balance
335 } // namespace sot
336 } // namespace dynamicgraph
sot_talos_balance.test.appli_dcmZmpControl.comDes
comDes
Definition: appli_dcmZmpControl.py:25
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
dynamicgraph
Definition: treeview.dox:24
sot_talos_balance.test.appli_dcmZmpControl.dcmDes
dcmDes
Definition: appli_dcmZmpControl.py:29
dynamicgraph::sot::talos_balance::DummyWalkingPatternGenerator::m_initSucceeded
bool m_initSucceeded
Definition: dummy-walking-pattern-generator.hh:109
dynamicgraph::sot::talos_balance::DummyWalkingPatternGenerator::init
void init()
Definition: dummy-walking-pattern-generator.cpp:119
OUTPUT_SIGNALS
#define OUTPUT_SIGNALS
Definition: dummy-walking-pattern-generator.cpp:44
dummy-walking-pattern-generator.hh
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::math::Vector
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: fwd.hh:36
sot_talos_balance.test.appli_dcmZmpControl.zmpDes
zmpDes
Definition: appli_dcmZmpControl.py:30
sot_talos_balance.test.appli_ankle_admittance.rf
rf
Definition: appli_ankle_admittance.py:92
dynamicgraph::sot::talos_balance::DummyWalkingPatternGenerator::display
virtual void display(std::ostream &os) const
Definition: dummy-walking-pattern-generator.cpp:327
dynamicgraph::sot::talos_balance::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(AdmittanceControllerEndEffector, "AdmittanceControllerEndEffector")
dynamicgraph::sot::talos_balance::DummyWalkingPatternGenerator::actInv
dynamicgraph::Vector actInv(MatrixHomogeneous m, dynamicgraph::Vector v)
true if the entity has been successfully initialized
Definition: dummy-walking-pattern-generator.cpp:105
sot_talos_balance.test.appli_ankle_admittance.omega
omega
Definition: appli_ankle_admittance.py:39
dynamicgraph::sot::talos_balance::DEFINE_SIGNAL_INNER_FUNCTION
DEFINE_SIGNAL_INNER_FUNCTION(w_force, dynamicgraph::Vector)
Definition: admittance-controller-end-effector.cpp:145
dynamicgraph::sot::talos_balance::DummyWalkingPatternGenerator::DummyWalkingPatternGenerator
EIGEN_MAKE_ALIGNED_OPERATOR_NEW DummyWalkingPatternGenerator(const std::string &name)
Definition: dummy-walking-pattern-generator.cpp:61
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
INPUT_SIGNALS
#define INPUT_SIGNALS
Definition: dummy-walking-pattern-generator.cpp:37