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_JOINTPOSITIONCONTROLLER_DQREF_COMPUTATION \
35 "JointPositionController: dqRef computation "
37 #define INPUT_SIGNALS m_KpSIN << m_stateSIN << m_qDesSIN << m_dqDesSIN
39 #define OUTPUT_SIGNALS m_dqRefSOUT
47 "JointPositionController");
59 m_initSucceeded(false) {
64 docCommandVoid1(
"Initialize the entity.",
69 if (n < 1)
return SEND_MSG(
"n must be at least 1", MSG_TYPE_ERROR);
70 if (!m_KpSIN.isPlugged())
71 return SEND_MSG(
"Init failed: signal Kp is not plugged", MSG_TYPE_ERROR);
72 if (!m_stateSIN.isPlugged())
73 return SEND_MSG(
"Init failed: signal q is not plugged", MSG_TYPE_ERROR);
74 if (!m_qDesSIN.isPlugged())
75 return SEND_MSG(
"Init failed: signal qDes is not plugged", MSG_TYPE_ERROR);
76 if (!m_dqDesSIN.isPlugged())
77 return SEND_MSG(
"Init failed: signal dqDes is not plugged", MSG_TYPE_ERROR);
88 if (!m_initSucceeded) {
89 SEND_WARNING_STREAM_MSG(
90 "Cannot compute signal dqRef before initialization!");
93 if (s.size() != m_n) s.resize(m_n);
97 const Vector& state = m_stateSIN(iter);
98 const Vector& qDes = m_qDesSIN(iter);
99 const Vector& dqDes = m_dqDesSIN(iter);
102 assert(state.size() == m_n + 6 &&
"Unexpected size of signal state");
103 assert(qDes.size() == m_n &&
"Unexpected size of signal qDes");
104 assert(dqDes.size() == m_n &&
"Unexpected size of signal dqDes");
105 assert(
Kp.size() == m_n &&
"Unexpected size of signal Kp");
107 s = dqDes +
Kp.cwiseProduct(qDes - state.tail(m_n));
121 os <<
"JointPositionController " << getName();
123 getProfiler().report_all(3, os);
124 }
catch (ExceptionSignal e) {