EEROS  1.0.0.0
API for the EEROS Real-Time Robotics Framework
BaseSequence.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_SEQUENCER_BASESEQUENCE_HPP_
2 #define ORG_EEROS_SEQUENCER_BASESEQUENCE_HPP_
3 
8 #include <vector>
9 
10 
11 namespace eeros {
12  namespace sequencer {
13 
14  using namespace eeros::logger;
15  class Sequencer;
16 
17  enum class SequenceState {
18  idle, // upon creation
19  running, // active and running
20  paused, // not used
21  aborting, // to be stopped, due to restarting of caller sequence
22  aborted, // stopped, due to restarting of caller sequence
23  terminated, // precondition failed, exitcondition successful
24  restarting, // repeat
25  };
26 
27  class BaseSequence {
28  friend class Monitor;
29  friend class Sequencer;
30  public:
31  BaseSequence(Sequencer& seq, BaseSequence* caller, bool blocking);
32  virtual ~BaseSequence();
33 
34  virtual int start() = 0;
35  virtual bool checkPreCondition();
36  virtual bool checkExitCondition();
37 
38  void setName(std::string name);
39  std::string getName() const;
40  void setId(int id);
41  int getId() const; // steps allways have id=-99
42 
43  BaseSequence* getCallerSequence();
44  std::vector<BaseSequence*> getCallerStack() const;
45 
46  SequenceState getRunningState() const;
47  void setPollingTime(int timeInMilliseconds);
48 
49  // Monitors
50  std::vector<Monitor*> monitors;
51  void addMonitor(Monitor* monitor);
52  std::vector<Monitor*> getMonitors() const;
53 
54  // Timeout
55  void setTimeoutTime(double timeoutInSec); // in seconds. For this sequence
56  void resetTimeout();
57  void setTimeoutBehavior(SequenceProp behavior);
58  void setTimeoutExceptionSequence(BaseSequence& sequence);
59 
60  // Abort
61  void resetAbort();
62 
63  protected:
64  virtual int action(); // handles different checks like preconditions
65  virtual int operator() () = 0; // has to be implemented in derived class
66 
67  std::string name;
68  Sequencer& seq; // reference to sequencer
69  BaseSequence* caller; // calling sequence
70  bool blocking; // standard run mode
71  bool exceptionIsActive = false; // one of its monitors fired
72  bool inExcProcessing = false; // this sequence already started an exception sequence of one of its monitors
75 
76  private:
77  void checkMonitorsOfBlockedCallers();
78  void checkMonitorsOfThisSequence();
79  void checkMonitor(Monitor* monitor);
80  void setActiveException(Monitor* activeMonitor);
81  void clearActiveException();
82  void checkActiveException();
83 
84  int id;
85  std::vector<BaseSequence*> callerStack; // vector with all caller sequences. Latest element is latest caller
86  std::vector<BaseSequence*> callerStackBlocking; // vector with all sequences, which are blocked by this sequence. Element[0] is the oldest blocked caller
87  bool callerStackCreated = false;
88  Monitor monitorTimeout;
89  ConditionTimeout conditionTimeout;
90  Monitor monitorAbort;
91  ConditionAbort conditionAbort;
92  int pollingTime; //in milliseconds for checkExitCondition monitors)
93  Monitor* activeException;
94  };
95 
96  /********** Print functions **********/
97  std::ostream& operator<<(std::ostream& os, SequenceState state);
98 
99  }; // namespace sequencer
100 }; // namespace eeros
101 
102 #endif // ORG_EEROS_SEQUENCER_BASESEQUENCE_HPP_
SequenceState state
Definition: BaseSequence.hpp:73
Definition: Logger.hpp:15
Logger log
Definition: BaseSequence.hpp:74
SequenceProp
Definition: Monitor.hpp:12
Definition: Monitor.hpp:18
std::vector< Monitor * > monitors
Definition: BaseSequence.hpp:50
Sequencer & seq
Definition: BaseSequence.hpp:68
Definition: ConditionAbort.hpp:9
Definition: Config.hpp:14
BaseSequence * caller
Definition: BaseSequence.hpp:69
std::ostream & operator<<(std::ostream &os, SequenceState state)
Definition: BaseSequence.cpp:210
bool blocking
Definition: BaseSequence.hpp:70
Definition: Sequencer.hpp:15
std::string name
Definition: BaseSequence.hpp:67
SequenceState
Definition: BaseSequence.hpp:17
Definition: ConditionTimeout.hpp:10
Definition: LogEntry.hpp:6
Definition: BaseSequence.hpp:27