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>
25 #include "sot/core/stop-watch.hh"
29 namespace talos_balance {
30 namespace dg = ::dynamicgraph;
32 using namespace dg::command;
35 #define PROFILE_SIMPLE_PID_DX_REF_COMPUTATION \
36 "SimplePID: dx_ref computation "
38 #define INPUT_SIGNALS \
39 m_KpSIN << m_KiSIN << m_decayFactorSIN << m_xSIN << m_x_desSIN << m_dx_desSIN
41 #define OUTPUT_SIGNALS m_dx_refSOUT
57 CONSTRUCT_SIGNAL_IN(decayFactor, double),
62 m_initSucceeded(false) {
66 addCommand(
"init", makeCommandVoid2(
68 docCommandVoid2(
"Initialize the entity.",
"time step",
69 "number of elements")));
70 addCommand(
"resetIntegralError",
72 docCommandVoid0(
"Set integral error to zero.")));
88 if (!m_initSucceeded) {
89 SEND_WARNING_STREAM_MSG(
90 "Cannot compute signal dx_ref before initialization!");
97 const Vector& Ki = m_KiSIN(iter);
98 const double& decayFactor = m_decayFactorSIN(iter);
100 const Vector&
x = m_xSIN(iter);
101 const Vector& x_des = m_x_desSIN(iter);
103 const Vector& dx_des = m_dx_desSIN(iter);
108 dx_des +
Kp.cwiseProduct(x_err) + Ki.cwiseProduct(m_integralError);
111 m_integralError += (x_err - decayFactor * m_integralError) * m_dt;
127 os <<
"SimplePID " << getName();
129 getProfiler().report_all(3, os);
130 }
catch (ExceptionSignal e) {