Skip to content

Commit 83df0f2

Browse files
committed
Fix IntegratorEuler (mix between numerator and denominator)
1 parent e3c8cae commit 83df0f2

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

include/sot/core/integrator-euler.hh

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,24 @@ class IntegratorEuler
6666
IntegratorEuler( const std::string& name )
6767
: IntegratorAbstract<sigT,coefT>( name )
6868
{
69+
using namespace dg::command;
70+
6971
setSamplingPeriod (0.005);
7072

7173
SOUT.addDependency(SIN);
7274
this->addCommand ("setSamplingPeriod",
73-
new dg::command::Setter<IntegratorEuler,double> (*this,
75+
new Setter<IntegratorEuler,double> (*this,
7476
&IntegratorEuler::setSamplingPeriod,
7577
"Set the time during two sampling."));
7678
this->addCommand ("getSamplingPeriod",
77-
new dg::command::Getter<IntegratorEuler,double> (*this,
79+
new Getter<IntegratorEuler,double> (*this,
7880
&IntegratorEuler::getSamplingPeriod,
7981
"Get the time during two sampling."));
82+
83+
this->addCommand ("initialize",
84+
makeCommandVoid0 (*this, &IntegratorEuler::initialize,
85+
docCommandVoid0 ("Initialize internal memory from current value of input")
86+
));
8087
}
8188

8289
virtual ~IntegratorEuler( void ) {}
@@ -106,28 +113,28 @@ public:
106113
// End of step 1. Here, sum is b_0 X
107114

108115
// Step 2
109-
int denomsize = denom.size();
110-
for(int i = 1; i < denomsize; ++i)
116+
int numsize = num.size();
117+
for(int i = 1; i < numsize; ++i)
111118
{
112119
tmp2 = inputMemory[i-1] - tmp1;
113120
tmp2 *= invdt;
114121
tmp1 = inputMemory[i];
115122
inputMemory[i] = tmp2;
116-
sum += (denom[i] * inputMemory[i]);
123+
sum += (num[i] * inputMemory[i]);
117124
}
118125
// End of step 2. Here, sum is b_m * d(m)X / dt^m + ... - b_0 X
119126

120127
// Step 3
121-
int numsize = num.size() - 1;
122-
for(int i = 0; i < numsize; ++i)
128+
int denomsize = denom.size() - 1;
129+
for(int i = 0; i < denomsize; ++i)
123130
{
124-
sum -= (num[i] * outputMemory[i]);
131+
sum -= (denom[i] * outputMemory[i]);
125132
}
126133
// End of step 3. Here, sum is b_m * d(m)X / dt^m + ... - b_0 X - a_0 Y - ... a_n-1 d(n-1)Y / dt^(n-1)
127134

128135
// Step 4
129-
outputMemory[numsize] = sum;
130-
for(int i = numsize - 1; i >= 0; --i)
136+
outputMemory[denomsize] = sum;
137+
for(int i = denomsize-1; i >= 0; --i)
131138
{
132139
outputMemory[i] += (outputMemory[i+1] * dt);
133140
}
@@ -150,6 +157,25 @@ public:
150157
{
151158
return dt;
152159
}
160+
161+
void initialize ()
162+
{
163+
std::size_t numsize = numerator.size();
164+
inputMemory.resize(numsize);
165+
166+
inputMemory[0] = SIN.accessCopy();
167+
for(std::size_t i = 1; i < numsize; ++i)
168+
{
169+
inputMemory[i] = inputMemory[0];
170+
}
171+
172+
std::size_t denomsize = denominator.size();
173+
outputMemory.resize(denomsize);
174+
for(std::size_t i = 0; i < denomsize; ++i)
175+
{
176+
outputMemory[i] = inputMemory[0];
177+
}
178+
}
153179
};
154180

155181
} /* namespace sot */} /* namespace dynamicgraph */

src/matrix/integrator-euler.t.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,24 @@ using namespace dynamicgraph;
2929
std::string sotClassType<sotSigType,sotCoefType>:: \
3030
getTypeName( void ) { return #sotSigType; } \
3131
template<> \
32-
const std::string sotClassType<sotSigType,sotCoefType>::CLASS_NAME \
33-
= std::string(className)+"<"+#sotSigType+","+#sotCoefType+">"; \
32+
const std::string sotClassType<sotSigType,sotCoefType>::CLASS_NAME = className; \
3433
template<> \
3534
const std::string& sotClassType<sotSigType,sotCoefType>:: \
36-
getClassName( void ) const { return CLASS_NAME; } \
35+
getClassName( void ) const { return CLASS_NAME; } \
3736
extern "C" { \
38-
Entity *regFunction##_##sotSigType( const std::string& objname ) \
37+
Entity *regFunction##_##sotSigType( const std::string& objname ) \
3938
{ \
4039
return new sotClassType<sotSigType,sotCoefType>( objname ); \
4140
} \
42-
EntityRegisterer \
43-
regObj##_##sotSigType(std::string(className)+"<"+#sotSigType+","+#sotCoefType+">", \
41+
EntityRegisterer \
42+
regObj##_##sotSigType(sotClassType<sotSigType,sotCoefType>::CLASS_NAME, \
4443
&regFunction##_##sotSigType ); \
4544
}
4645

4746
using namespace std;
4847
namespace dynamicgraph {
4948
namespace sot {
5049
SOT_FACTORY_TEMPLATE_ENTITY_PLUGIN_EULER(IntegratorEuler,Vector,Matrix,
51-
"integratorEuler")
50+
"IntegratorEulerVectorMatrix")
5251
} // namespace sot
5352
} // namespace dynamicgraph

0 commit comments

Comments
 (0)