derivator.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_DERIVATOR_H__
11 #define __SOT_DERIVATOR_H__
12 
13 /* --------------------------------------------------------------------- */
14 /* --- INCLUDE --------------------------------------------------------- */
15 /* --------------------------------------------------------------------- */
16 
17 /* Matrix */
19 
20 /* SOT */
22 #include <dynamic-graph/entity.h>
23 
24 #include <sot/core/flags.hh>
26 #include <sot/core/pool.hh>
27 
28 /* STD */
29 #include <string>
30 
31 namespace dynamicgraph {
32 namespace sot {
33 
34 /* --------------------------------------------------------------------- */
35 /* --- CLASS ----------------------------------------------------------- */
36 /* --------------------------------------------------------------------- */
37 
38 template <class T>
41 
42  protected:
45  double timestep;
46  static const double TIMESTEP_DEFAULT; //= 1.;
47 
48  public: /* --- CONSTRUCTION --- */
49  static std::string getTypeName(void) { return "Unknown"; }
50 
51  Derivator(const std::string &name)
52  : dynamicgraph::Entity(name),
53  memory(),
54  initialized(false),
55  timestep(TIMESTEP_DEFAULT),
56  SIN(NULL, "sotDerivator<" + getTypeName() + ">(" + name + ")::input(" +
57  getTypeName() + ")::sin"),
58  SOUT(boost::bind(&Derivator<T>::computeDerivation, this, _1, _2), SIN,
59  "sotDerivator<" + getTypeName() + ">(" + name + ")::output(" +
60  getTypeName() + ")::sout"),
61  timestepSIN("sotDerivator<" + getTypeName() + ">(" + name +
62  ")::input(double)::dt") {
66  }
67 
68  virtual ~Derivator(void){};
69 
70  public: /* --- SIGNAL --- */
74 
75  protected:
76  T &computeDerivation(T &res, int time) {
77  if (initialized) {
78  res = memory;
79  res *= -1;
80  memory = SIN(time);
81  res += memory;
82  if (timestep != 1.) res *= (1. / timestep);
83  } else {
84  initialized = true;
85  memory = SIN(time);
86  res = memory;
87  res *= 0;
88  }
89  return res;
90  }
91 };
92 // TODO Derivation of unit quaternion?
93 template <>
95  VectorQuaternion &res, int time) {
96  if (initialized) {
97  res = memory;
98  res.coeffs() *= -1;
99  memory = SIN(time);
100  res.coeffs() += memory.coeffs();
101  if (timestep != 1.) res.coeffs() *= (1. / timestep);
102  } else {
103  initialized = true;
104  memory = SIN(time);
105  res = memory;
106  res.coeffs() *= 0;
107  }
108  return res;
109 }
110 
111 } /* namespace sot */
112 } /* namespace dynamicgraph */
113 
114 #endif // #ifndef __SOT_DERIVATOR_H__
Eigen::Quaternion< double > SOT_CORE_EXPORT VectorQuaternion
int T
void signalRegistration(const SignalArray< int > &signals)
dynamicgraph::SignalPtr< T, int > SIN
Definition: derivator.hh:68
static std::string getTypeName(void)
Definition: derivator.hh:49
Derivator(const std::string &name)
Definition: derivator.hh:51
static const double TIMESTEP_DEFAULT
Definition: derivator.hh:46
void setKeepReference(const bool &b)
virtual void setReferenceNonConstant(T *t, Mutex *mutexref=NULL)
dynamicgraph::Signal< double, int > timestepSIN
Definition: derivator.hh:73
dynamicgraph::SignalTimeDependent< T, int > SOUT
Definition: derivator.hh:72
T & computeDerivation(T &res, int time)
Definition: derivator.hh:76


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26