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;
35 #define PROFILE_SIMPLE_ADMITTANCECONTROLLER_QREF_COMPUTATION \
36 "SimpleAdmittanceController: qRef computation "
38 #define PROFILE_SIMPLE_ADMITTANCECONTROLLER_DQREF_COMPUTATION \
39 "SimpleAdmittanceController: dqRef computation "
41 #define INPUT_SIGNALS m_KpSIN << m_stateSIN << m_tauSIN << m_tauDesSIN
43 #define OUTPUT_SIGNALS m_qRefSOUT << m_dqRefSOUT
51 "SimpleAdmittanceController");
65 m_initSucceeded(false) {
69 addCommand(
"init", makeCommandVoid2(
71 docCommandVoid2(
"Initialize the entity.",
"time step",
72 "Number of elements")));
73 addCommand(
"setPosition",
75 docCommandVoid1(
"Set initial reference position.",
76 "Initial position")));
77 addCommand(
"useExternalState",
79 docDirectSetter(
"use external state",
"bool")));
80 addCommand(
"isUsingExternalState",
82 docDirectGetter(
"use external state",
"bool")));
86 if (n < 1)
return SEND_MSG(
"n must be at least 1", MSG_TYPE_ERROR);
87 if (!m_KpSIN.isPlugged())
88 return SEND_MSG(
"Init failed: signal Kp is not plugged", MSG_TYPE_ERROR);
89 if (!m_tauSIN.isPlugged())
90 return SEND_MSG(
"Init failed: signal tau is not plugged", MSG_TYPE_ERROR);
91 if (!m_tauDesSIN.isPlugged())
92 return SEND_MSG(
"Init failed: signal tauDes is not plugged",
113 if (!m_initSucceeded) {
114 SEND_WARNING_STREAM_MSG(
115 "Cannot compute signal dqRef before initialization!");
118 if (s.size() != m_n) s.resize(m_n);
122 const Vector& tauDes = m_tauDesSIN(iter);
126 assert(
tau.size() == m_n &&
"Unexpected size of signal tau");
127 assert(tauDes.size() == m_n &&
"Unexpected size of signal tauDes");
128 assert(
Kp.size() == m_n &&
"Unexpected size of signal Kp");
130 s =
Kp.cwiseProduct(tauDes -
tau);
138 if (!m_initSucceeded) {
139 SEND_WARNING_STREAM_MSG(
140 "Cannot compute signal qRef before initialization!");
143 if (s.size() != m_n) s.resize(m_n);
147 const Vector& dqRef = m_dqRefSOUT(iter);
149 assert(dqRef.size() == m_n &&
"Unexpected size of signal dqRef");
152 if (!m_stateSIN.isPlugged()) {
153 SEND_MSG(
"Signal state is requested, but is not plugged", MSG_TYPE_ERROR);
156 const Vector& state = m_stateSIN(iter);
157 assert(state.size() == m_n &&
"Unexpected size of signal state");
177 os <<
"SimpleAdmittanceController " << getName();
179 getProfiler().report_all(3, os);
180 }
catch (ExceptionSignal e) {