sot-core  4.11.8
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 
26 #include <sot/core/debug.hh>
27 #include <sot/core/flags.hh>
28 
29 /* STD */
30 #include <string>
31 
32 /* --------------------------------------------------------------------- */
33 /* --- CLASS ----------------------------------------------------------- */
34 /* --------------------------------------------------------------------- */
35 
36 namespace dynamicgraph {
37 namespace sot {
38 
45 template <class sigT, class coefT>
46 class IntegratorAbstract : public dynamicgraph::Entity {
47  public:
48  IntegratorAbstract(const std::string &name)
49  : dynamicgraph::Entity(name),
50  SIN(NULL, "sotIntegratorAbstract(" + name + ")::input(vector)::sin"),
51  SOUT(boost::bind(&IntegratorAbstract<sigT, coefT>::integrate, this, _1,
52  _2),
53  SIN, "sotIntegratorAbstract(" + name + ")::output(vector)::sout") {
54  signalRegistration(SIN << SOUT);
55 
56  using namespace dynamicgraph::command;
57 
58  const std::string typeName =
59  Value::typeName(dynamicgraph::command::ValueHelper<coefT>::TypeID);
60 
61  addCommand(
62  "pushNumCoef",
63  makeCommandVoid1(
65  docCommandVoid1("Push a new numerator coefficient", typeName)));
66  addCommand(
67  "pushDenomCoef",
68  makeCommandVoid1(
70  docCommandVoid1("Push a new denominator coefficient", typeName)));
71 
72  addCommand(
73  "popNumCoef",
74  makeCommandVoid0(*this, &IntegratorAbstract::popNumCoef,
75  docCommandVoid0("Pop a new numerator coefficient")));
76  addCommand(
77  "popDenomCoef",
78  makeCommandVoid0(*this, &IntegratorAbstract::popDenomCoef,
79  docCommandVoid0("Pop a new denominator coefficient")));
80  }
81 
82  virtual ~IntegratorAbstract() {}
83 
84  virtual sigT &integrate(sigT &res, int time) = 0;
85 
86  public:
87  void pushNumCoef(const coefT &numCoef) { numerator.push_back(numCoef); }
88  void pushDenomCoef(const coefT &denomCoef) {
89  denominator.push_back(denomCoef);
90  }
91  void popNumCoef() { numerator.pop_back(); }
92  void popDenomCoef() { denominator.pop_back(); }
93 
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 
100  public:
101  dynamicgraph::SignalPtr<sigT, int> SIN;
102 
103  dynamicgraph::SignalTimeDependent<sigT, int> SOUT;
104 
105  virtual void display(std::ostream &os) const {
106  os << this->getClassName() << ": " << getName() << '\n' << " ";
107  if (numerator.empty() || denominator.empty()) {
108  os << "ill-formed.";
109  return;
110  }
111  os << numerator[0];
112  for (std::size_t i = 1; i < numerator.size(); ++i)
113  os << " + " << numerator[i] << " s^" << i;
114  os << "\n " << denominator[0];
115  for (std::size_t i = 1; i < denominator.size(); ++i)
116  os << " + " << denominator[i] << " s^" << i;
117  }
118 
119  protected:
120  std::vector<coefT> numerator;
121  std::vector<coefT> denominator;
122 };
123 
124 } /* namespace sot */
125 } /* namespace dynamicgraph */
126 
127 #endif
integrates an ODE. If Y is the output and X the input, the following equation is integrated: a_p * d(...
Definition: integrator-abstract.hh:46
void pushNumCoef(const coefT &numCoef)
Definition: integrator-abstract.hh:87
IntegratorAbstract(const std::string &name)
Definition: integrator-abstract.hh:48
void popDenomCoef()
Definition: integrator-abstract.hh:92
virtual void display(std::ostream &os) const
Definition: integrator-abstract.hh:105
void numCoeffs(const std::vector< coefT > &coeffs)
Definition: integrator-abstract.hh:95
void pushDenomCoef(const coefT &denomCoef)
Definition: integrator-abstract.hh:88
dynamicgraph::SignalPtr< sigT, int > SIN
Definition: integrator-abstract.hh:101
std::vector< coefT > numerator
Definition: integrator-abstract.hh:120
const std::vector< coefT > & numCoeffs() const
Definition: integrator-abstract.hh:94
const std::vector< coefT > & denomCoeffs() const
Definition: integrator-abstract.hh:97
virtual sigT & integrate(sigT &res, int time)=0
void popNumCoef()
Definition: integrator-abstract.hh:91
virtual ~IntegratorAbstract()
Definition: integrator-abstract.hh:82
dynamicgraph::SignalTimeDependent< sigT, int > SOUT
Definition: integrator-abstract.hh:103
void denomCoeffs(const std::vector< coefT > &coeffs)
Definition: integrator-abstract.hh:98
std::vector< coefT > denominator
Definition: integrator-abstract.hh:121
Definition: abstract-sot-external-interface.hh:17