NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
behaviour_layer.h
Go to the documentation of this file.
1 // Behaviour Control Framework - BehaviourLayer class
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
9 // Ensure header is only included once
10 #ifndef BEHAVIOUR_LAYER_H
11 #define BEHAVIOUR_LAYER_H
12 
13 // Includes
15 
16 // Behaviour control namespace
17 namespace behaviourcontrol
18 {
27  {
28  public:
29  // Constants
30  static const index_t DEF_BLIST_CAPACITY;
31  static const index_t DEF_ILIST_CAPACITY;
32  static const std::string DEF_LAYER_NAME;
33 
34  // Structures
35  struct BBasePair
36  {
37  BBasePair() : A(NULL), B(NULL) {}
38  BBasePair(Behaviour* BBaseA, Behaviour* BBaseB) : A(BBaseA), B(BBaseB) {}
41  };
42 
43  // Constructors
44  explicit BehaviourLayer(BehaviourManager* MBase, const std::string& name = nullString, bool isInterface = false);
45  virtual ~BehaviourLayer();
46 
47  // Constant properties
49  const std::string Mname;
50  const std::string name;
51  const bool isInterface;
52 
53  private:
54  // Sensor and actuator managers
55  void setSensorManager(SensorManager* SMBase);
56  void setActuatorManager(ActuatorManager* AMBase);
57  SensorManager* SMBase;
58  ActuatorManager* AMBase;
59  bool haveSM;
60  bool haveAM;
61 
62  // Inhibition functions
63  protected:
64  void addInhibition(Behaviour* BBaseA, Behaviour* BBaseB);
65  void addChainInhibition(Behaviour* BBaseA, Behaviour* BBaseB);
66  private:
67  std::vector<BBasePair> IList;
68  std::vector<BBasePair> CIList;
69 
70  protected:
71  // Initialisation function
72  virtual ret_t init() { return RET_OK; }
73 
74  private:
75  // Internal initialisation functions
76  ret_t initAll();
77  ret_t initAllBase();
78  ret_t initBase();
79 
80  public:
81  // Get functions
82  SensorManager* getSMBase() { return (haveSM ? SMBase : NULL); }
83  ActuatorManager* getAMBase() { return (haveAM ? AMBase : NULL); }
84  bool hasSM() const { return haveSM; }
85  bool hasAM() const { return haveAM; }
86 
87  // Step functions
88  protected:
89  virtual void update() {}
90  virtual void postExecuteCallback() {}
91  private:
92  void step();
93  void updateAll();
94  void executeAll();
95 
96  private:
97  // Actuator functions
98  const ActuatorBase* findActuator(const std::string& signalName) const;
99 
100  // Behaviour declaration function
101  template <class BClass> void declareBehaviour(BClass* behaviour);
102 
103  // Behaviour list
104  std::vector<Behaviour*> BList;
105 
106  public:
107  // Get functions
108  std::string getUniqueName(const BehaviourManager* MBase) const;
109  BehaviourLayer* getBasePtr() { return this; }
110 
111  // Friend classes
112  friend class BehaviourManager;
113  friend class SensorManager;
114  friend class ActuatorManager;
115  friend class Behaviour;
116  };
117 }
118 
119 #endif /* BEHAVIOUR_LAYER_H */
120 // EOF
Implements a single behaviour.
Definition: behaviour.h:26
virtual ~BehaviourLayer()
Behaviour layer object destructor.
Definition: behaviour_layer.cpp:54
int ret_t
Used to represent an error code/function return value.
Definition: behaviour_common.h:142
Implements a single behaviour layer.
Definition: behaviour_layer.h:26
Data structure used to represent a basic inhibition pair, where behaviour A is taken to inhibit behav...
Definition: behaviour_layer.h:35
BehaviourManager *const MBase
Pointer to the parent behaviour manager.
Definition: behaviour_layer.h:48
ActuatorManager * getAMBase()
Get function for a pointer to the base class of the child actuator manager.
Definition: behaviour_layer.h:83
BBasePair(Behaviour *BBaseA, Behaviour *BBaseB)
Constructor that accepts initial values for BBaseA and BBaseB.
Definition: behaviour_layer.h:38
Signals successful execution of a function, with no error conditions encountered. ...
Definition: behaviour_common.h:69
Implements a manager of a particular group of actuators.
Definition: behaviour_actuators.h:26
void addChainInhibition(Behaviour *BBaseA, Behaviour *BBaseB)
Adds a chaining inhibition from behaviour BBaseA (inhibitor) to behaviour BBaseB (inhibitee).
Definition: behaviour_layer.cpp:122
static const index_t DEF_ILIST_CAPACITY
Default capacity of the lists that are used to store the chaining and non-chaining inhibition definit...
Definition: behaviour_layer.h:31
static const index_t DEF_BLIST_CAPACITY
Default capacity of the list that stores the child behaviours of the layer.
Definition: behaviour_layer.h:30
virtual void postExecuteCallback()
Callback that is invoked at the end of the executeAll() function so that the user can inject code...
Definition: behaviour_layer.h:90
Behaviour * B
The behaviour that is being inhibited.
Definition: behaviour_layer.h:40
static const std::string DEF_LAYER_NAME
Default behaviour layer name used to generate a unique one, in the case that no name is provided by a...
Definition: behaviour_layer.h:32
std::size_t index_t
Used to represent an array or vector index (must be an unsigned type)
Definition: behaviour_common.h:140
BehaviourLayer * getBasePtr()
Return a pointer to the underlying BehaviourLayer class object in the case of a derived behaviour lay...
Definition: behaviour_layer.h:109
virtual void update()
Update callback for the behaviour layer object. This function is called from updateAll(), which is used in step().
Definition: behaviour_layer.h:89
virtual ret_t init()
Initialisation callback for the behaviour layer. This function is called from initAll(), and is intended to be overridden for the purpose of initialising the derived behaviour layer object.
Definition: behaviour_layer.h:72
bool hasAM() const
Boolean flag specifying whether this layer has an actuator manager.
Definition: behaviour_layer.h:85
BBasePair()
Default constructor.
Definition: behaviour_layer.h:37
Behaviour * A
The inhibiting behaviour.
Definition: behaviour_layer.h:39
Implements a single actuator.
Definition: behaviour_actuators.h:76
const bool isInterface
A boolean flag specifying whether the layer is an interface layer or a normal behaviour layer...
Definition: behaviour_layer.h:51
const std::string Mname
Human-friendly string name of the parent behaviour manager.
Definition: behaviour_layer.h:49
Implements a single behaviour manager.
Definition: behaviour_manager.h:27
BehaviourLayer(BehaviourManager *MBase, const std::string &name=nullString, bool isInterface=false)
Default constructor.
Definition: behaviour_layer.cpp:34
const std::string nullString
Used to avoid the need for null string literals throughout the code.
Definition: behaviour_common.h:148
std::string getUniqueName(const BehaviourManager *MBase) const
Returns a unique behaviour layer name.
Definition: behaviour_layer.cpp:597
const std::string name
Human-friendly string name of the behaviour layer.
Definition: behaviour_layer.h:50
Implements a manager of a particular group of sensors.
Definition: behaviour_sensors.h:26
bool hasSM() const
Boolean flag specifying whether this layer has a sensor manager.
Definition: behaviour_layer.h:84
SensorManager * getSMBase()
Get function for a pointer to the base class of the child sensor manager.
Definition: behaviour_layer.h:82
void addInhibition(Behaviour *BBaseA, Behaviour *BBaseB)
Adds a non-chaining inhibition from behaviour BBaseA (inhibitor) to behaviour BBaseB (inhibitee)...
Definition: behaviour_layer.cpp:98
Common definitions include file for the internal Behaviour Control Framework source code...