EEROS  1.0.0.0
API for the EEROS Real-Time Robotics Framework
Step.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_STEP_HPP_
2 #define ORG_EEROS_CONTROL_STEP_HPP_
3 
5 #include <eeros/core/System.hpp>
6 
7 namespace eeros {
8  namespace control {
9 
10  template < typename T = double >
11  class Step : public Block1o<T> {
12 
13  public:
15  first = true;
16  }
17 
18 
19  virtual void run() {
20  if(first) {
22  this->out.getSignal().setValue(initValue);
23  first = false;
24  }
25  else if(!stepDone && System::getTime() >= delayTime) {
26  this->out.getSignal().setValue(initValue + stepHeight);
27  stepDone = true;
28  }
29  this->out.getSignal().setTimestamp(System::getTimeNs());
30  }
31 
32  virtual void reset() {
33  stepDone = false;
34  first = true;
35  }
36 
37  virtual void setInitValue(T initValue) {
38  this->initValue = initValue;
39  }
40 
41  virtual void setStepHeight(T stepHeight) {
42  this->stepHeight = stepHeight;
43  }
44 
45  virtual void setDelayTime(double delayTime) {
46  this->delayTime = delayTime;
47  }
48 
49  template <typename X>
50  friend std::ostream& operator<<(std::ostream& os, Step<X>& step);
51 
52  protected:
55  double delayTime;
56  bool stepDone;
57  bool first;
58  };
59 
60  /********** Print functions **********/
61  template <typename T>
62  std::ostream& operator<<(std::ostream& os, Step<T>& step) {
63  os << "Block step: '" << step.getName() << "' init val = " << step.initValue << " step height = " << step.stepHeight << " delay time = " << step.delayTime;
64  }
65 
66  };
67 };
68 
69 #endif /* ORG_EEROS_CONTROL_STEP_HPP_ */
Definition: Step.hpp:11
bool stepDone
Definition: Step.hpp:56
static double getTime()
Definition: System_POSIX.cpp:31
T stepHeight
Definition: Step.hpp:54
virtual void setStepHeight(T stepHeight)
Definition: Step.hpp:41
bool first
Definition: Step.hpp:57
Definition: Block1o.hpp:12
Definition: Config.hpp:14
static uint64_t getTimeNs()
Definition: System_POSIX.cpp:41
virtual void reset()
Definition: Step.hpp:32
Output< T > out
Definition: Block1o.hpp:23
virtual void setInitValue(T initValue)
Definition: Step.hpp:37
virtual void setDelayTime(double delayTime)
Definition: Step.hpp:45
double delayTime
Definition: Step.hpp:55
T initValue
Definition: Step.hpp:53
virtual void run()
Definition: Step.hpp:19
Step(T initValue=0, T stepHeight=1, double delayTime=1)
Definition: Step.hpp:14