EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Gain.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_GAIN_HPP_
2 #define ORG_EEROS_CONTROL_GAIN_HPP_
3 
5 
6 namespace eeros {
7  namespace control {
8 
9  template <typename Tout = double, typename Tgain = double, bool elementWise = false>
10  class Gain : public Block1i1o<Tout> {
11 
12  public:
13  Gain() : enabled(true) {
14  gain = 1;
15  }
16 
17  Gain(Tgain c) : enabled(true) {
18  gain = c;
19  }
20 
21  virtual void run() {
22  if(enabled) {
23  this->out.getSignal().setValue(gain * this->in.getSignal().getValue());
24  }
25  else {
26  this->out.getSignal().setValue(this->in.getSignal().getValue());
27  }
29  }
30 
31  virtual void enable() {
32  enabled = true;
33  }
34 
35  virtual void disable() {
36  enabled = false;
37  }
38 
39  virtual void setGain(Tgain c) {
40  gain = c;
41  }
42 
43  protected:
44  Tgain gain;
45  bool enabled;
46  };
47 
48  template <typename Tout, typename Tgain>
49  class Gain<Tout, Tgain, true> : public Block1i1o<Tout> {
50 
51  public:
52  Gain() : enabled(true) {
53  gain = 1;
54  }
55 
56  Gain(Tgain c) : enabled(true) {
57  gain = c;
58  }
59 
60  virtual void run() {
61  if(enabled) {
62  this->out.getSignal().setValue(this->in.getSignal().getValue().multiplyElementWise(gain));
63  }
64  else {
65  this->out.getSignal().setValue(this->in.getSignal().getValue());
66  }
68  }
69 
70  virtual void enable() {
71  enabled = true;
72  }
73 
74  virtual void disable() {
75  enabled = false;
76  }
77 
78  virtual void setGain(Tgain c) {
79  gain = c;
80  }
81 
82  protected:
83  Tgain gain;
84  bool enabled;
85  };
86  };
87 };
88 
89 #endif /* ORG_EEROS_CONTROL_GAIN_HPP_ */
bool enabled
Definition: Gain.hpp:45
Gain(Tgain c)
Definition: Gain.hpp:56
virtual void disable()
Definition: Gain.hpp:74
virtual Signal< T > & getSignal()
Definition: Output.hpp:13
Tgain gain
Definition: Gain.hpp:83
virtual void run()
Definition: Gain.hpp:60
virtual T getValue() const
Definition: Signal.hpp:46
virtual void disable()
Definition: Gain.hpp:35
virtual void setGain(Tgain c)
Definition: Gain.hpp:78
Gain(Tgain c)
Definition: Gain.hpp:17
bool enabled
Definition: Gain.hpp:84
virtual void run()
Definition: Gain.hpp:21
virtual void setGain(Tgain c)
Definition: Gain.hpp:39
Output< Tout > out
Definition: Block1i1o.hpp:26
Tgain gain
Definition: Gain.hpp:44
virtual void enable()
Definition: Gain.hpp:70
virtual void setValue(T newValue)
Definition: Signal.hpp:50
virtual void enable()
Definition: Gain.hpp:31
virtual void setTimestamp(timestamp_t newTimestamp)
Definition: Signal.hpp:63
Input< Tout > in
Definition: Block1i1o.hpp:25
Definition: Block1i1o.hpp:12
virtual Signal< T > & getSignal()
Definition: Input.hpp:35
virtual timestamp_t getTimestamp() const
Definition: Signal.hpp:59
Gain()
Definition: Gain.hpp:13
Definition: Gain.hpp:10