EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Switch.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_SWITCH_HPP_
2 #define ORG_EEROS_CONTROL_SWITCH_HPP_
3 
7 
8 namespace eeros {
9  namespace control {
10 
11  template < uint8_t N = 2, typename T = double >
12  class Switch : public Block {
13  public:
14  Switch(uint8_t initInputIndex) : currentInput(initInputIndex) { }
15 
16  virtual void run() {
17  this->out.getSignal().setValue(this->in[currentInput].getSignal().getValue());
18  this->out.getSignal().setTimestamp(this->in[currentInput].getSignal().getTimestamp());
19  }
20 
21  virtual Input<T>& getIn(uint8_t index) {
22  return in[index];
23  }
24 
25  virtual Output<T>& getOut() {
26  return out;
27  }
28 
29  virtual bool switchToInput(uint8_t index) {
30  if(index >= 0 && index < N) {
31  currentInput = index;
32  return true;
33  }
34  return false;
35  }
36 
37  virtual uint8_t getCurrentInput() const {
38  return currentInput;
39  }
40 
41  protected:
44  uint8_t currentInput;
45  };
46  };
47 };
48 
49 #endif /* ORG_EEROS_CONTROL_SWITCH_HPP_ */
Definition: Switch.hpp:12
virtual Input< T > & getIn(uint8_t index)
Definition: Switch.hpp:21
Definition: Block.hpp:10
Definition: Output.hpp:10
virtual bool switchToInput(uint8_t index)
Definition: Switch.hpp:29
virtual uint8_t getCurrentInput() const
Definition: Switch.hpp:37
virtual Output< T > & getOut()
Definition: Switch.hpp:25
Output< T > out
Definition: Switch.hpp:43
virtual void run()
Definition: Switch.hpp:16
Switch(uint8_t initInputIndex)
Definition: Switch.hpp:14
uint8_t currentInput
Definition: Switch.hpp:44
Definition: Input.hpp:11
Input< T > in[N]
Definition: Switch.hpp:42