Skip to content

Commit e400b01

Browse files
committed
Update bindings of IntegratorEuler
1 parent 64c2890 commit e400b01

File tree

4 files changed

+77
-20
lines changed

4 files changed

+77
-20
lines changed

include/sot/core/integrator-abstract.hh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public:
6767
"pushDenomCoef",
6868
makeCommandVoid1(
6969
*this, &IntegratorAbstract::pushDenomCoef,
70-
docCommandVoid1("Push a new denomicator coefficient", typeName)));
70+
docCommandVoid1("Push a new denominator coefficient", typeName)));
7171

7272
addCommand(
7373
"popNumCoef",
@@ -76,7 +76,7 @@ public:
7676
addCommand(
7777
"popDenomCoef",
7878
makeCommandVoid0(*this, &IntegratorAbstract::popDenomCoef,
79-
docCommandVoid0("Pop a new denomicator coefficient")));
79+
docCommandVoid0("Pop a new denominator coefficient")));
8080
}
8181

8282
virtual ~IntegratorAbstract() {}
@@ -91,11 +91,33 @@ public:
9191
void popNumCoef() { numerator.pop_back(); }
9292
void popDenomCoef() { denominator.pop_back(); }
9393

94+
const std::vector<coefT>& numCoeffs() const { return numerator; }
95+
void numCoeffs(const std::vector<coefT>& coeffs) { numerator = coeffs; }
96+
97+
const std::vector<coefT>& denomCoeffs() const { return denominator; }
98+
void denomCoeffs(const std::vector<coefT>& coeffs) { denominator = coeffs; }
99+
94100
public:
95101
dg::SignalPtr<sigT, int> SIN;
96102

97103
dg::SignalTimeDependent<sigT, int> SOUT;
98104

105+
virtual void display(std::ostream &os) const
106+
{
107+
os << this->getClassName() << ": " << getName() << '\n'
108+
<< " ";
109+
if (numerator.empty() || denominator.empty()) {
110+
os << "ill-formed.";
111+
return;
112+
}
113+
os << numerator[0];
114+
for (std::size_t i = 1; i < numerator.size(); ++i)
115+
os << " + " << numerator[i] << " s^" << i;
116+
os << "\n " << denominator[0];
117+
for (std::size_t i = 1; i < denominator.size(); ++i)
118+
os << " + " << denominator[i] << " s^" << i;
119+
}
120+
99121
protected:
100122
std::vector<coefT> numerator;
101123
std::vector<coefT> denominator;

include/sot/core/integrator-euler.hh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ public:
168168
double getSamplingPeriod() const { return dt; }
169169

170170
void initialize() {
171+
if (denominator.empty() || numerator.empty())
172+
throw dg::ExceptionSignal(
173+
dg::ExceptionSignal::GENERIC,
174+
"The numerator or the denominator is empty.");
175+
176+
// Check that denominator.back is the identity
177+
if (!internal::integratorEulerCoeffIsIdentity(denominator.back()))
178+
throw dg::ExceptionSignal(
179+
dg::ExceptionSignal::GENERIC,
180+
"The coefficient of the highest order derivative of denominator "
181+
"should be 1 (the last pushDenomCoef should be the identity).");
182+
171183
std::size_t numsize = numerator.size();
172184
inputMemory.resize(numsize);
173185

@@ -181,13 +193,6 @@ public:
181193
for (std::size_t i = 0; i < denomsize; ++i) {
182194
outputMemory[i] = inputMemory[0];
183195
}
184-
185-
// Check that denominator.back is the identity
186-
if (!internal::integratorEulerCoeffIsIdentity(denominator.back()))
187-
throw dg::ExceptionSignal(
188-
dg::ExceptionSignal::GENERIC,
189-
"The coefficient of the highest order derivative of denominator "
190-
"should be 1 (the last pushDenomCoef should be the identity).");
191196
}
192197
};
193198

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <dynamic-graph/python/module.hh>
2+
3+
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
4+
#include <dynamic-graph/python/dynamic-graph-py.hh>
5+
6+
#include <eigenpy/registration.hpp>
7+
8+
#include <sot/core/integrator-euler.hh>
9+
10+
namespace dg = dynamicgraph;
11+
namespace dgc = dynamicgraph::command;
12+
namespace dgs = dynamicgraph::sot;
13+
using dg::Vector;
14+
using dg::Matrix;
15+
16+
template<typename S, typename C> void exposeIntegratorEuler()
17+
{
18+
typedef dgs::IntegratorEuler<S, C> IE_t;
19+
typedef std::vector<C> Coeffs_t;
20+
21+
const std::string cName =
22+
dgc::Value::typeName(dgc::ValueHelper<C>::TypeID);
23+
24+
dg::python::exposeEntity<IE_t>()
25+
.add_property("numerators",
26+
+[](const IE_t& e) { return dg::python::to_py_list(e.numCoeffs().begin(), e.numCoeffs().end()); },
27+
+[](IE_t& e, bp::object iterable) { e.numCoeffs(dg::python::to_std_vector<C>(iterable)); })
28+
.add_property("denominators",
29+
+[](const IE_t& e) { return dg::python::to_py_list(e.denomCoeffs().begin(), e.denomCoeffs().end()); },
30+
+[](IE_t& e, bp::object iterable) { e.denomCoeffs(dg::python::to_std_vector<C>(iterable)); })
31+
;
32+
}
33+
34+
BOOST_PYTHON_MODULE(wrap)
35+
{
36+
bp::import("dynamic_graph");
37+
38+
exposeIntegratorEuler<double, double>();
39+
exposeIntegratorEuler<Vector, double>();
40+
exposeIntegratorEuler<Vector, Matrix>();
41+
}

src/matrix/integrator-euler-python.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)