EEROS  1.0.0.0
API for the EEROS Real-Time Robotics Framework
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  this->out.getSignal().clear();
15  }
16 
17  virtual void run() {
18  if(first) { // first run, no previous value available -> set output to zero
19  prev = this->in.getSignal();
20  this->out.getSignal().setValue(0.0);
21  this->out.getSignal().setTimestamp(this->in.getSignal().getTimestamp());
22  first = false;
23  }
24  else {
25  double tin = this->in.getSignal().getTimestamp() / 1000000000.0;
26  double tprev = this->prev.getTimestamp() / 1000000000.0;
27  T valin = this->in.getSignal().getValue();
28  T valprev = this->prev.getValue();
29 
30  T valOut;
31  if ((tin - tprev) == 0) valOut = valprev;
32  else valOut = (valin - valprev) / (tin - tprev);
33 
34  this->out.getSignal().setValue(valOut);
35  this->out.getSignal().setTimestamp((this->in.getSignal().getTimestamp() + this->prev.getTimestamp()) / 2);
36 
37  prev = this->in.getSignal();
38  }
39  }
40 
41  protected:
43  bool first;
44  };
45  };
46 };
47 #endif /* ORG_EEROS_CONTROL_D_HPP_ */
Input< T > in
Definition: Block1i1o.hpp:27
Definition: Config.hpp:14
bool first
Definition: D.hpp:43
Output< T > out
Definition: Block1i1o.hpp:28
D()
Definition: D.hpp:13
Definition: Block1i1o.hpp:12
Definition: Signal.hpp:17
virtual void run()
Definition: D.hpp:17
Signal< T > prev
Definition: D.hpp:42
Definition: D.hpp:10