19 #include <dynamic-graph/all-commands.h>
20 #include <dynamic-graph/command-bind.h>
21 #include <dynamic-graph/factory.h>
23 #include <sot/core/debug.hh>
24 #include <sot/core/stop-watch.hh>
28 namespace talos_balance {
29 namespace dg = ::dynamicgraph;
31 using namespace dg::command;
34 #define PROFILE_DCMCOMCONTROLLER_DDCOMREF_COMPUTATION \
35 "DcmComController: ddcomRef computation "
36 #define PROFILE_DCMCOMCONTROLLER_ZMPREF_COMPUTATION \
37 "DcmComController: zmpRef computation "
38 #define PROFILE_DCMCOMCONTROLLER_WRENCHREF_COMPUTATION \
39 "DcmComController: wrenchRef computation "
41 #define INPUT_SIGNALS \
42 m_KpSIN << m_KiSIN << m_decayFactorSIN << m_omegaSIN << m_massSIN \
43 << m_dcmSIN << m_dcmDesSIN << m_comDesSIN << m_ddcomDesSIN
45 #define OUTPUT_SIGNALS m_ddcomRefSOUT << m_zmpRefSOUT << m_wrenchRefSOUT
61 CONSTRUCT_SIGNAL_IN(decayFactor, double),
62 CONSTRUCT_SIGNAL_IN(
omega, double),
63 CONSTRUCT_SIGNAL_IN(
mass, double),
70 m_ddcomRefSOUT << m_comDesSIN << m_omegaSIN),
72 m_ddcomRefSOUT << m_comDesSIN << m_massSIN),
73 m_initSucceeded(false) {
78 docCommandVoid1(
"Initialize the entity.",
81 "resetDcmIntegralError",
83 docCommandVoid0(
"Set dcm integral error to zero.")));
87 if (!m_KpSIN.isPlugged())
88 return SEND_MSG(
"Init failed: signal Kp is not plugged", MSG_TYPE_ERROR);
89 if (!m_KiSIN.isPlugged())
90 return SEND_MSG(
"Init failed: signal Ki is not plugged", MSG_TYPE_ERROR);
91 if (!m_decayFactorSIN.isPlugged())
92 return SEND_MSG(
"Init failed: signal decayFactor is not plugged",
94 if (!m_omegaSIN.isPlugged())
95 return SEND_MSG(
"Init failed: signal omega is not plugged", MSG_TYPE_ERROR);
96 if (!m_massSIN.isPlugged())
97 return SEND_MSG(
"Init failed: signal mass is not plugged", MSG_TYPE_ERROR);
98 if (!m_dcmSIN.isPlugged())
99 return SEND_MSG(
"Init failed: signal dcm is not plugged", MSG_TYPE_ERROR);
100 if (!m_dcmDesSIN.isPlugged())
101 return SEND_MSG(
"Init failed: signal dcmDes is not plugged",
103 if (!m_comDesSIN.isPlugged())
104 return SEND_MSG(
"Init failed: signal comDes is not plugged",
106 if (!m_ddcomDesSIN.isPlugged())
107 return SEND_MSG(
"Init failed: signal ddcomDes is not plugged",
124 if (!m_initSucceeded) {
125 SEND_WARNING_STREAM_MSG(
126 "Cannot compute signal ddcomRef before initialization!");
129 if (s.size() != 3) s.resize(3);
134 const Vector& Ki = m_KiSIN(iter);
135 const double& decayFactor = m_decayFactorSIN(iter);
136 const double&
omega = m_omegaSIN(iter);
137 const Vector& dcm = m_dcmSIN(iter);
141 assert(
Kp.size() == 3 &&
"Unexpected size of signal Kp");
142 assert(Ki.size() == 3 &&
"Unexpected size of signal Ki");
143 assert(dcm.size() == 3 &&
"Unexpected size of signal dcm");
144 assert(
dcmDes.size() == 3 &&
"Unexpected size of signal dcmDes");
145 assert(
ddcomDes.size() == 3 &&
"Unexpected size of signal ddcomDes");
147 const Eigen::Vector3d dcmError =
dcmDes - dcm;
149 const Eigen::Vector3d ddcomRef =
ddcomDes +
150 omega *
Kp.cwiseProduct(dcmError) +
151 omega * Ki.cwiseProduct(m_dcmIntegralError);
154 m_dcmIntegralError += (dcmError - decayFactor * m_dcmIntegralError) * m_dt;
164 if (!m_initSucceeded) {
165 SEND_WARNING_STREAM_MSG(
166 "Cannot compute signal zmpRef before initialization!");
169 if (s.size() != 3) s.resize(3);
173 const double&
omega = m_omegaSIN(iter);
176 const Vector& ddcomRef = m_ddcomRefSOUT(iter);
178 assert(
comDes.size() == 3 &&
"Unexpected size of signal comDes");
191 if (!m_initSucceeded) {
192 SEND_WARNING_STREAM_MSG(
193 "Cannot compute signal wrenchRef before initialization!");
196 if (s.size() != 6) s.resize(6);
200 const double&
mass = m_massSIN(iter);
203 const Vector& ddcomRef = m_ddcomRefSOUT(iter);
205 assert(
comDes.size() == 3 &&
"Unexpected size of signal comDes");
207 Eigen::Vector3d gravity;
208 gravity << 0.0, 0.0, -9.81;
210 const Eigen::Vector3d forceRef =
mass * (ddcomRef - gravity);
212 Eigen::Matrix<double, 6, 1> wrenchRef;
213 wrenchRef.head<3>() = forceRef;
214 const Eigen::Vector3d comDes3 =
comDes;
215 wrenchRef.tail<3>() = comDes3.cross(wrenchRef.head<3>());
231 os <<
"DcmComController " << getName();
233 getProfiler().report_all(3, os);
234 }
catch (ExceptionSignal e) {