EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
D.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_D_HPP_
2 #define ORG_EEROS_CONTROL_D_HPP_
3 
5 
6 namespace eeros {
7  namespace control {
8 
9  template < typename T = double >
10  class D: public Block1i1o<T> {
11 
12  public:
13  D() : first(true) { }
14 
15  virtual void run() {
16  if(first) { // first run, no previous value available -> set output to zero
17  prev = this->in.getSignal();
18  this->out.getSignal().clear();
19  this->out.getSignal().setTimestamp(this->in.getSignal().getTimestamp());
20  first = false;
21  }
22  else {
23  double tin = this->in.getSignal().getTimestamp() / 1000000000.0;
24  double tprev = this->prev.getTimestamp() / 1000000000.0;
25  T valin = this->in.getSignal().getValue();
26  T valprev = this->prev.getValue();
27 
28  this->out.getSignal().setValue((valin - valprev) / (tin - tprev));
29  this->out.getSignal().setTimestamp((this->in.getSignal().getTimestamp() + this->prev.getTimestamp()) / 2);
30 
31  prev = this->in.getSignal();
32  }
33  }
34 
35  protected:
37  bool first;
38  };
39  };
40 };
41 #endif /* ORG_EEROS_CONTROL_D_HPP_ */
Output< T > out
Definition: Block1i1o.hpp:26
bool first
Definition: D.hpp:37
D()
Definition: D.hpp:13
Input< T > in
Definition: Block1i1o.hpp:25
Definition: Block1i1o.hpp:12
Definition: Signal.hpp:14
virtual void run()
Definition: D.hpp:15
Signal< T > prev
Definition: D.hpp:36
Definition: D.hpp:10