NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
behaviour_manager.h
Go to the documentation of this file.
1 // Behaviour Control Framework - BehaviourManager class
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
9 // Ensure header is only included once
10 #ifndef BEHAVIOUR_MANAGER_H
11 #define BEHAVIOUR_MANAGER_H
12 
13 // Includes
15 
16 // Behaviour control namespace
17 namespace behaviourcontrol
18 {
28  {
29  public:
30  // Constants
31  static const index_t DEF_LLIST_CAPACITY;
32  static const std::string DEF_MANAGER_NAME;
33 
34  // Constructors
35  explicit BehaviourManager(const std::string& name = nullString);
36  virtual ~BehaviourManager();
37 
38  // Constant properties
39  const std::string name;
40 
41  // Initialisation functions
42  public:
44  bool wasInitialised() const { return initialised; }
45  bool isInitialising() const { return initialising; }
46  protected:
47  virtual ret_t init() { return RET_OK; }
48  private:
49  ret_t initBase();
50  bool initialised;
51  bool initialising;
52 
53  // Step functions
54  public:
55  void step();
56  int cycleID() const { return icycleID; }
57  protected:
58  virtual void preStepCallback() {}
59  virtual void postStepCallback() {}
60  private:
61  int icycleID;
62 
63  // Error notification functions
64  public:
65  void reportError(const std::string& msg, bool fatal, const std::string& funcName, const std::string& fileName, int line);
66  virtual void reportErrorUser(const std::string& msg, bool fatal, const std::string& funcName, const std::string& fileName, int line) {}
67  void clearErrorStatus();
68  bool hadError() const { return fatalErrorOccurred; }
69  bool hadWarning() const { return nonfatalErrorOccurred; }
70  private:
71  bool fatalErrorOccurred;
72  bool nonfatalErrorOccurred;
73 
74  public:
75  // Helper functions
76  std::string toString(const std::string& linePrefix = nullString) const;
77 
78  // Get functions
79  const ActuatorBase* findActuator(const std::string& signalName) const;
80  BehaviourManager* getBasePtr() { return this; }
81 
82  private:
83  // Layer declaration function
84  template <class LClass> void declareLayer(LClass* layer);
85 
86  // Layer list
87  std::vector<BehaviourLayer*> LList;
88 
89  // Friend classes
90  friend class BehaviourLayer;
91  friend class SensorBase;
92  };
93 }
94 
95 #endif /* BEHAVIOUR_MANAGER_H */
96 // EOF
bool wasInitialised() const
Boolean flag specifying whether the manager has been initialised yet or not.
Definition: behaviour_manager.h:44
int ret_t
Used to represent an error code/function return value.
Definition: behaviour_common.h:142
virtual ret_t init()
Initialisation callback for the behaviour manager. This function is called from initialiseArchitectur...
Definition: behaviour_manager.h:47
Implements a single behaviour layer.
Definition: behaviour_layer.h:26
virtual void preStepCallback()
Callback that is invoked at the beginning of the step() function so that the user can inject code...
Definition: behaviour_manager.h:58
bool isInitialising() const
Boolean flag specifying whether the manager is currently initialising or not.
Definition: behaviour_manager.h:45
Signals successful execution of a function, with no error conditions encountered. ...
Definition: behaviour_common.h:69
void clearErrorStatus()
Reset the error status flags so that functions like initialiseArchitecture() and step() can be attemp...
Definition: behaviour_manager.cpp:243
virtual void reportErrorUser(const std::string &msg, bool fatal, const std::string &funcName, const std::string &fileName, int line)
Error handler function that is intended to be overridden by the user to process and/or display warnin...
Definition: behaviour_manager.h:66
static const index_t DEF_LLIST_CAPACITY
Default capacity of the list that stores the child behaviour layers of the manager.
Definition: behaviour_manager.h:31
const std::string name
Human-friendly string name of the behaviour manager.
Definition: behaviour_manager.h:39
const ActuatorBase * findActuator(const std::string &signalName) const
Finds an actuator within the architecture, given its string name as a lookup key. ...
Definition: behaviour_manager.cpp:261
virtual void postStepCallback()
Callback that is invoked at the end of the step() function so that the user can inject code...
Definition: behaviour_manager.h:59
std::size_t index_t
Used to represent an array or vector index (must be an unsigned type)
Definition: behaviour_common.h:140
ret_t initialiseArchitecture()
Function that should be called by the user to initialise the entire behaviour manager architecture...
Definition: behaviour_manager.cpp:61
BehaviourManager(const std::string &name=nullString)
Default constructor.
Definition: behaviour_manager.cpp:28
static const std::string DEF_MANAGER_NAME
Default behaviour manager name used to generate a unique one, in the case that no name is provided by...
Definition: behaviour_manager.h:32
bool hadError() const
Boolean flag that specifies whether an error has occurred with the architecture.
Definition: behaviour_manager.h:68
Implements a single actuator.
Definition: behaviour_actuators.h:76
bool hadWarning() const
Boolean flag that specifies whether an error or warning has occurred with the architecture.
Definition: behaviour_manager.h:69
void reportError(const std::string &msg, bool fatal, const std::string &funcName, const std::string &fileName, int line)
Function used to signal that a warning or an error has occurred. After setting the appropriate error ...
Definition: behaviour_manager.cpp:228
int cycleID() const
The numeric ID of the current step cycle of the behaviour manager. Prior to the first step this ID is...
Definition: behaviour_manager.h:56
Implements a single behaviour manager.
Definition: behaviour_manager.h:27
const std::string nullString
Used to avoid the need for null string literals throughout the code.
Definition: behaviour_common.h:148
virtual ~BehaviourManager()
Behaviour manager object destructor.
Definition: behaviour_manager.cpp:41
Implements a single sensor.
Definition: behaviour_sensors.h:76
void step()
Function that should be called by the user to execute one step of the entire behaviour manager archit...
Definition: behaviour_manager.cpp:170
Common definitions include file for the internal Behaviour Control Framework source code...
std::string toString(const std::string &linePrefix=nullString) const
Generates a multiline string representation of the architecture, summarising all of the main componen...
Definition: behaviour_manager.cpp:336
BehaviourManager * getBasePtr()
Return a pointer to the underlying BehaviourManager class object in the case of a derived behaviour m...
Definition: behaviour_manager.h:80