EEROS  1.0.0.0
API for the EEROS Real-Time Robotics Framework
Constant.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_CONSTANT_HPP_
2 #define ORG_EEROS_CONTROL_CONSTANT_HPP_
3 
4 #include <type_traits>
6 #include <eeros/core/System.hpp>
7 
8 namespace eeros {
9  namespace control {
10 
11  template < typename T = double >
12  class Constant : public Block1o<T> {
13  public:
15  _clear<T>();
16  }
17 
18  Constant(T v) : value(v) { }
19 
20  virtual void run() {
21  this->out.getSignal().setValue(value);
22  this->out.getSignal().setTimestamp(System::getTimeNs());
23  }
24 
25  virtual void setValue(T newValue) {
26  value = newValue;
27  }
28 
29  virtual T getValue() {
30  return value;
31  }
32 
33  template <typename X>
34  friend std::ostream& operator<<(std::ostream& os, Constant<X>& c);
35 
36  protected:
37  T value;
38 
39  private:
40  template <typename S> typename std::enable_if<std::is_integral<S>::value>::type _clear() {
41  value = std::numeric_limits<int32_t>::min();
42  }
43  template <typename S> typename std::enable_if<std::is_floating_point<S>::value>::type _clear() {
44  value = std::numeric_limits<double>::quiet_NaN();
45  }
46  template <typename S> typename std::enable_if<!std::is_arithmetic<S>::value && std::is_integral<typename S::value_type>::value>::type _clear() {
47  value.fill(std::numeric_limits<int32_t>::min());
48  }
49  template <typename S> typename std::enable_if< !std::is_arithmetic<S>::value && std::is_floating_point<typename S::value_type>::value>::type _clear() {
50  value.fill(std::numeric_limits<double>::quiet_NaN());
51  }
52  };
53 
54  /********** Print functions **********/
55  template <typename T>
56  std::ostream& operator<<(std::ostream& os, Constant<T>& c) {
57  os << "Block constant: '" << c.getName() << "' init val = " << c.value;
58  }
59  };
60 };
61 
62 #endif /* ORG_EEROS_CONTROL_CONSTANT_HPP_ */
Constant()
Definition: Constant.hpp:14
T value
Definition: Constant.hpp:37
Definition: Block1o.hpp:12
Definition: Config.hpp:14
static uint64_t getTimeNs()
Definition: System_POSIX.cpp:41
Definition: Constant.hpp:12
Output< T > out
Definition: Block1o.hpp:23
virtual void setValue(T newValue)
Definition: Constant.hpp:25
virtual void run()
Definition: Constant.hpp:20
virtual T getValue()
Definition: Constant.hpp:29
Constant(T v)
Definition: Constant.hpp:18