EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Sum.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_SUM_HPP_
2 #define ORG_EEROS_CONTROL_SUM_HPP_
3 
4 #include <vector>
8 
9 namespace eeros {
10  namespace control {
11 
12  template < uint8_t N = 2, typename T = double >
13  class Sum : public Block {
14 
15  public:
16  Sum() {
17  for(uint8_t i = 0; i < N; i++) {
18  negated[i] = false;
19  }
20  }
21 
22  virtual void run() {
23  T sum; sum = 0; // TODO works only with primitive types or eeros::math::Matrix -> make specialization and use fill() for compatibility with std::array;
24  for(uint8_t i = 0; i < N; i++) {
25  if(negated[i]) sum -= in[i].getSignal().getValue();
26  else sum += in[i].getSignal().getValue();
27  }
28  out.getSignal().setValue(sum);
29  out.getSignal().setTimestamp(in[0].getSignal().getTimestamp());
30  }
31 
32  virtual Input<T>& getIn(uint8_t index) {
33  return in[index];
34  }
35 
36  virtual Output<T>& getOut() {
37  return out;
38  }
39 
40 
41  virtual void negateInput(uint8_t index) {
42  negated[index] = true;
43  }
44 
45  protected:
48  bool negated[N];
49  };
50 
51  };
52 };
53 
54 #endif /* ORG_EEROS_CONTROL_SUM_HPP_ */
Definition: Sum.hpp:13
Sum()
Definition: Sum.hpp:16
virtual void negateInput(uint8_t index)
Definition: Sum.hpp:41
Output< T > out
Definition: Sum.hpp:47
Definition: Block.hpp:10
virtual Output< T > & getOut()
Definition: Sum.hpp:36
Input< T > in[N]
Definition: Sum.hpp:46
bool negated[N]
Definition: Sum.hpp:48
Definition: Output.hpp:10
int i
Definition: RingBufferTest.cpp:12
Definition: Input.hpp:11
virtual void run()
Definition: Sum.hpp:22
virtual Input< T > & getIn(uint8_t index)
Definition: Sum.hpp:32