10 #ifndef __SOT_INTEGRATOR_EULER_H__ 11 #define __SOT_INTEGRATOR_EULER_H__ 18 #include <dynamic-graph/command-getter.h> 19 #include <dynamic-graph/command-setter.h> 48 template <
class sigT,
class coefT>
52 virtual const std::string &getClassName(
void)
const;
68 "sotIntegratorEuler(" + name +
69 ")::output(vector)::derivativesout") {
70 this->signalRegistration(derivativeSOUT);
72 using namespace dynamicgraph::command;
74 setSamplingPeriod(0.005);
76 this->addCommand(
"setSamplingPeriod",
77 new Setter<IntegratorEuler, double>(
79 "Set the time during two sampling."));
80 this->addCommand(
"getSamplingPeriod",
81 new Getter<IntegratorEuler, double>(
83 "Get the time during two sampling."));
90 "Initialize internal memory from current value of input")));
106 sotDEBUG(15) <<
"# In {" << std::endl;
110 const std::vector<coefT> &num = numerator;
111 const std::vector<coefT> &denom = denominator;
114 tmp1 = inputMemory[0];
115 inputMemory[0] = SIN.access(time);
116 sum = num[0] * inputMemory[0];
120 int numsize = (int)num.size();
121 for (
int i = 1; i < numsize; ++i) {
122 tmp2 = inputMemory[i - 1] - tmp1;
124 tmp1 = inputMemory[i];
125 inputMemory[i] = tmp2;
126 sum += (num[i] * inputMemory[i]);
131 int denomsize = (int)denom.size() - 1;
132 for (
int i = 0; i < denomsize; ++i) {
133 sum -= (denom[i] * outputMemory[i]);
139 outputMemory[denomsize] = sum;
140 for (
int i = denomsize - 1; i >= 0; --i) {
141 outputMemory[i] += (outputMemory[i + 1] * dt);
145 inputMemory[0] = SIN.access(time);
146 res = outputMemory[0];
148 sotDEBUG(15) <<
"# Out }" << std::endl;
153 if (outputMemory.size() < 2)
154 throw dynamicgraph::ExceptionSignal(
155 dynamicgraph::ExceptionSignal::GENERIC,
156 "Integrator does not compute the derivative.");
158 SOUT.recompute(time);
159 res = outputMemory[1];
171 if (denominator.empty() || numerator.empty())
172 throw dynamicgraph::ExceptionSignal(
173 dynamicgraph::ExceptionSignal::GENERIC,
174 "The numerator or the denominator is empty.");
178 throw dynamicgraph::ExceptionSignal(
179 dynamicgraph::ExceptionSignal::GENERIC,
180 "The coefficient of the highest order derivative of denominator " 181 "should be 1 (the last pushDenomCoef should be the identity).");
183 std::size_t numsize = numerator.size();
184 inputMemory.resize(numsize);
186 inputMemory[0] = SIN.accessCopy();
187 for (std::size_t i = 1; i < numsize; ++i) {
188 inputMemory[i] = inputMemory[0];
191 std::size_t denomsize = denominator.size();
192 outputMemory.resize(denomsize);
193 for (std::size_t i = 0; i < denomsize; ++i) {
194 outputMemory[i] = inputMemory[0];
bool integratorEulerCoeffIsIdentity(const coefT c)
Definition: integrator-euler.hh:30
double dt
Definition: integrator-euler.hh:101
void initialize()
Definition: integrator-euler.hh:170
double invdt
Definition: integrator-euler.hh:102
integrates an ODE. If Y is the output and X the input, the following equation is integrated: a_p * d(...
Definition: integrator-abstract.hh:45
sigT & derivative(sigT &res, int time)
Definition: integrator-euler.hh:152
static const std::string CLASS_NAME
Definition: integrator-euler.hh:54
static std::string getTypeName(void)
Definition: integrator-euler.hh:53
dynamicgraph::SignalTimeDependent< sigT, int > derivativeSOUT
Definition: integrator-euler.hh:99
#define sotDEBUG(level)
Definition: debug.hh:167
integrates an ODE using a naive Euler integration. TODO: change the integration method. For the moment, the highest derivative of the output signal is computed using the previous values of the other derivatives and the input signal, then integrated n times, which will most certainly induce a huge drift for ODEs with a high order at the denominator.
Definition: integrator-euler.hh:49
IntegratorEuler(const std::string &name)
Definition: integrator-euler.hh:63
double getSamplingPeriod() const
Definition: integrator-euler.hh:168
virtual ~IntegratorEuler(void)
Definition: integrator-euler.hh:93
void setSamplingPeriod(const double &period)
Definition: integrator-euler.hh:163
Definition: abstract-sot-external-interface.hh:17
std::vector< sigT > inputMemory
Definition: integrator-euler.hh:96
std::vector< sigT > outputMemory
Definition: integrator-euler.hh:97
sigT & integrate(sigT &res, int time)
Definition: integrator-euler.hh:105