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_COMADMITTANCECONTROLLER_DDCOMREF_COMPUTATION \
35 "ComAdmittanceController: ddcomRef computation "
36 #define PROFILE_COMADMITTANCECONTROLLER_STATEREF_COMPUTATION \
37 "ComAdmittanceController: stateRef computation "
38 #define PROFILE_COMADMITTANCECONTROLLER_DCOMREF_COMPUTATION \
39 "ComAdmittanceController: dcomRef computation "
40 #define PROFILE_COMADMITTANCECONTROLLER_COMREF_COMPUTATION \
41 "ComAdmittanceController: comRef computation "
43 #define INPUT_SIGNALS m_KpSIN << m_zmpSIN << m_zmpDesSIN << m_ddcomDesSIN
45 #define INNER_SIGNALS m_stateRefSINNER
47 #define OUTPUT_SIGNALS m_comRefSOUT << m_dcomRefSOUT << m_ddcomRefSOUT
55 "ComAdmittanceController");
73 m_initSucceeded(false) {
78 docCommandVoid1(
"Initialize the entity.",
80 addCommand(
"setPosition",
82 docCommandVoid1(
"Set initial reference position.",
83 "Initial position")));
84 addCommand(
"setVelocity",
86 docCommandVoid1(
"Set initial reference velocity.",
87 "Initial velocity")));
88 addCommand(
"setState",
91 docCommandVoid2(
"Set initial reference position and velocity.",
92 "Initial position",
"Initial velocity")));
96 if (!m_KpSIN.isPlugged())
97 return SEND_MSG(
"Init failed: signal Kp is not plugged", MSG_TYPE_ERROR);
98 if (!m_ddcomDesSIN.isPlugged())
99 return SEND_MSG(
"Init failed: signal ddcomDes is not plugged",
101 if (!m_zmpSIN.isPlugged())
102 return SEND_MSG(
"Init failed: signal zmp is not plugged", MSG_TYPE_ERROR);
103 if (!m_zmpDesSIN.isPlugged())
104 return SEND_MSG(
"Init failed: signal zmpDes is not plugged",
131 if (!m_initSucceeded) {
132 SEND_WARNING_STREAM_MSG(
133 "Cannot compute signal ddcomRef before initialization!");
136 if (s.size() != 3) s.resize(3);
141 const Vector& zmp = m_zmpSIN(iter);
145 assert(
ddcomDes.size() == 3 &&
"Unexpected size of signal ddcomDes");
146 assert(zmp.size() == 3 &&
"Unexpected size of signal zmp");
147 assert(
zmpDes.size() == 3 &&
"Unexpected size of signal zmpDes");
148 assert(
Kp.size() == 3 &&
"Unexpected size of signal Kp");
158 if (!m_initSucceeded) {
159 SEND_WARNING_STREAM_MSG(
160 "Cannot compute signal stateRef before initialization!");
163 if (s.size() != 6) s.resize(6);
167 const Vector& ddcomRef = m_ddcomRefSOUT(iter);
169 assert(ddcomRef.size() == 3 &&
"Unexpected size of signal ddcomRef");
171 const Eigen::Vector3d dcomRef = m_state.tail<3>();
173 m_state.head<3>() += dcomRef * m_dt + 0.5 * ddcomRef * m_dt * m_dt;
174 m_state.tail<3>() += ddcomRef * m_dt;
184 if (!m_initSucceeded) {
185 SEND_WARNING_STREAM_MSG(
186 "Cannot compute signal dcomRef before initialization!");
189 if (s.size() != 3) s.resize(3);
193 const Vector& stateRef = m_stateRefSINNER(iter);
195 assert(stateRef.size() == 6 &&
"Unexpected size of signal stateRef");
197 s = stateRef.head<3>();
205 if (!m_initSucceeded) {
206 SEND_WARNING_STREAM_MSG(
207 "Cannot compute signal dcomRef before initialization!");
210 if (s.size() != 3) s.resize(3);
214 const Vector& stateRef = m_stateRefSINNER(iter);
216 assert(stateRef.size() == 6 &&
"Unexpected size of signal stateRef");
218 s = stateRef.tail<3>();
232 os <<
"ComAdmittanceController " << getName();
234 getProfiler().report_all(3, os);
235 }
catch (ExceptionSignal e) {