sot-core  4.11.2
Hierarchical task solver plug-in for dynamic-graph.
integrator-abstract.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #ifndef __SOT_INTEGRATOR_ABSTRACT_H__
11 #define __SOT_INTEGRATOR_ABSTRACT_H__
12 
13 /* --------------------------------------------------------------------- */
14 /* --- INCLUDE --------------------------------------------------------- */
15 /* --------------------------------------------------------------------- */
16 
17 /* Matrix */
18 #include <dynamic-graph/linear-algebra.h>
19 
20 /* SOT */
21 #include <dynamic-graph/all-signals.h>
22 #include <dynamic-graph/command-bind.h>
23 #include <dynamic-graph/entity.h>
24 #include <dynamic-graph/pool.h>
25 #include <sot/core/debug.hh>
26 #include <sot/core/flags.hh>
27 
28 /* STD */
29 #include <string>
30 
31 /* --------------------------------------------------------------------- */
32 /* --- CLASS ----------------------------------------------------------- */
33 /* --------------------------------------------------------------------- */
34 
35 namespace dynamicgraph {
36 namespace sot {
37 
44 template <class sigT, class coefT>
45 class IntegratorAbstract : public dynamicgraph::Entity {
46 public:
47  IntegratorAbstract(const std::string &name)
48  : dynamicgraph::Entity(name),
49  SIN(NULL, "sotIntegratorAbstract(" + name + ")::input(vector)::sin"),
50  SOUT(boost::bind(&IntegratorAbstract<sigT, coefT>::integrate, this, _1,
51  _2),
52  SIN, "sotIntegratorAbstract(" + name + ")::output(vector)::sout") {
53  signalRegistration(SIN << SOUT);
54 
55  using namespace dynamicgraph::command;
56 
57  const std::string typeName =
58  Value::typeName(dynamicgraph::command::ValueHelper<coefT>::TypeID);
59 
60  addCommand(
61  "pushNumCoef",
62  makeCommandVoid1(
64  docCommandVoid1("Push a new numerator coefficient", typeName)));
65  addCommand(
66  "pushDenomCoef",
67  makeCommandVoid1(
69  docCommandVoid1("Push a new denominator coefficient", typeName)));
70 
71  addCommand(
72  "popNumCoef",
73  makeCommandVoid0(*this, &IntegratorAbstract::popNumCoef,
74  docCommandVoid0("Pop a new numerator coefficient")));
75  addCommand(
76  "popDenomCoef",
77  makeCommandVoid0(*this, &IntegratorAbstract::popDenomCoef,
78  docCommandVoid0("Pop a new denominator coefficient")));
79  }
80 
81  virtual ~IntegratorAbstract() {}
82 
83  virtual sigT &integrate(sigT &res, int time) = 0;
84 
85 public:
86  void pushNumCoef(const coefT &numCoef) { numerator.push_back(numCoef); }
87  void pushDenomCoef(const coefT &denomCoef) {
88  denominator.push_back(denomCoef);
89  }
90  void popNumCoef() { numerator.pop_back(); }
91  void popDenomCoef() { denominator.pop_back(); }
92 
93  const std::vector<coefT> &numCoeffs() const { return numerator; }
94  void numCoeffs(const std::vector<coefT> &coeffs) { numerator = coeffs; }
95 
96  const std::vector<coefT> &denomCoeffs() const { return denominator; }
97  void denomCoeffs(const std::vector<coefT> &coeffs) { denominator = coeffs; }
98 
99 public:
100  dynamicgraph::SignalPtr<sigT, int> SIN;
101 
102  dynamicgraph::SignalTimeDependent<sigT, int> SOUT;
103 
104  virtual void display(std::ostream &os) const {
105  os << this->getClassName() << ": " << getName() << '\n' << " ";
106  if (numerator.empty() || denominator.empty()) {
107  os << "ill-formed.";
108  return;
109  }
110  os << numerator[0];
111  for (std::size_t i = 1; i < numerator.size(); ++i)
112  os << " + " << numerator[i] << " s^" << i;
113  os << "\n " << denominator[0];
114  for (std::size_t i = 1; i < denominator.size(); ++i)
115  os << " + " << denominator[i] << " s^" << i;
116  }
117 
118 protected:
119  std::vector<coefT> numerator;
120  std::vector<coefT> denominator;
121 };
122 
123 } /* namespace sot */
124 } /* namespace dynamicgraph */
125 
126 #endif
const std::vector< coefT > & denomCoeffs() const
Definition: integrator-abstract.hh:96
const std::vector< coefT > & numCoeffs() const
Definition: integrator-abstract.hh:93
dynamicgraph::SignalPtr< sigT, int > SIN
Definition: integrator-abstract.hh:100
void popDenomCoef()
Definition: integrator-abstract.hh:91
std::vector< coefT > numerator
Definition: integrator-abstract.hh:119
void pushDenomCoef(const coefT &denomCoef)
Definition: integrator-abstract.hh:87
void denomCoeffs(const std::vector< coefT > &coeffs)
Definition: integrator-abstract.hh:97
std::vector< coefT > denominator
Definition: integrator-abstract.hh:120
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
virtual sigT & integrate(sigT &res, int time)=0
virtual ~IntegratorAbstract()
Definition: integrator-abstract.hh:81
void numCoeffs(const std::vector< coefT > &coeffs)
Definition: integrator-abstract.hh:94
dynamicgraph::SignalTimeDependent< sigT, int > SOUT
Definition: integrator-abstract.hh:102
void popNumCoef()
Definition: integrator-abstract.hh:90
IntegratorAbstract(const std::string &name)
Definition: integrator-abstract.hh:47
virtual void display(std::ostream &os) const
Definition: integrator-abstract.hh:104
Definition: abstract-sot-external-interface.hh:17
void pushNumCoef(const coefT &numCoef)
Definition: integrator-abstract.hh:86