NimbRo ROS Soccer Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
behaviour.h
Go to the documentation of this file.
1 // Behaviour Control Framework - Behaviour class
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
9 // Ensure header is only included once
10 #ifndef BEHAVIOUR_H
11 #define BEHAVIOUR_H
12 
13 // Includes
15 
16 // Behaviour control namespace
17 namespace behaviourcontrol
18 {
26  class Behaviour
27  {
28  public:
29  // Constants
30  static const index_t DEF_ILIST_CAPACITY;
31  static const std::string DEF_BEHAVIOUR_NAME;
32 
33  // Constructors
34  explicit Behaviour(BehaviourLayer* LBase, const std::string& name = nullString);
35  virtual ~Behaviour();
36 
37  // Constant properties
40  const std::string Mname;
41  const std::string Lname;
42  const std::string name;
43 
44  private:
45  // Inhibition lists
46  static void addInhibition(Behaviour* BBaseA, Behaviour* BBaseB);
47  std::vector<Behaviour*> inhibits;
48  std::vector<Behaviour*> isInhibitedBy;
49 
50  // Initialisation functions
51  protected:
52  virtual ret_t init() { return RET_OK; }
53 
54  // Update and execute functions
55  protected:
56  virtual void update() {}
57  virtual void execute() {}
58  virtual void inhibited() {}
59  bool wasJustActivated() const { return justActivated; }
60  bool wasJustDeactivated() const { return justDeactivated; }
61  private:
62  bool justActivated;
63  bool justDeactivated;
64 
65  // Activation levels
66  public:
67  level_t getA() const { return trueA; }
68  protected:
69  virtual level_t computeActivationLevel() { return 0.0; }
70  private:
71  level_t rawA;
72  level_t trueA;
73 
74  public:
75  // Get functions
76  std::string getUniqueName(const BehaviourLayer* LBase) const;
77  Behaviour* getBasePtr() { return this; }
78 
79  // Friend classes
80  friend class BehaviourLayer;
81  };
82 }
83 
84 #endif /* BEHAVIOUR_H */
85 // EOF
Implements a single behaviour.
Definition: behaviour.h:26
int ret_t
Used to represent an error code/function return value.
Definition: behaviour_common.h:142
const std::string name
Human-friendly string name of the behaviour.
Definition: behaviour.h:42
std::string getUniqueName(const BehaviourLayer *LBase) const
Returns a unique behaviour name.
Definition: behaviour.cpp:94
virtual void inhibited()
A callback for the behaviour object that is invoked instead of execute() when the behaviour is deacti...
Definition: behaviour.h:58
BehaviourLayer *const LBase
Pointer to the parent behaviour layer.
Definition: behaviour.h:39
Implements a single behaviour layer.
Definition: behaviour_layer.h:26
Signals successful execution of a function, with no error conditions encountered. ...
Definition: behaviour_common.h:69
BehaviourManager *const MBase
Pointer to the parent behaviour manager.
Definition: behaviour.h:38
const std::string Lname
Human-friendly string name of the parent behaviour layer.
Definition: behaviour.h:41
level_t getA() const
Returns the current true activation level of the behaviour. The return value is valid only when calle...
Definition: behaviour.h:67
std::size_t index_t
Used to represent an array or vector index (must be an unsigned type)
Definition: behaviour_common.h:140
virtual void execute()
Execute callback for the behaviour object. This function is called from BehaviourLayer::executeAll()...
Definition: behaviour.h:57
virtual ret_t init()
Initialisation callback for the behaviour. This function is called from BehaviourLayer::initAll(), and is intended to be overridden for the purpose of initialising the derived behaviour object.
Definition: behaviour.h:52
Behaviour * getBasePtr()
Return a pointer to the underlying Behaviour class object in the case of a derived behaviour class...
Definition: behaviour.h:77
static const index_t DEF_ILIST_CAPACITY
Default capacity of the inhibition lists that are used to store which behaviours are inhibitors and i...
Definition: behaviour.h:30
Implements a single behaviour manager.
Definition: behaviour_manager.h:27
virtual ~Behaviour()
Behaviour object destructor.
Definition: behaviour.cpp:52
const std::string nullString
Used to avoid the need for null string literals throughout the code.
Definition: behaviour_common.h:148
bool wasJustActivated() const
Returns true when called from the execute() callback, and the behaviour was just activated. The return value is always true when called from inhibited().
Definition: behaviour.h:59
bool wasJustDeactivated() const
Returns true when called from the inhibited() callback, and the behaviour was just inhibited...
Definition: behaviour.h:60
const std::string Mname
Human-friendly string name of the parent behaviour manager.
Definition: behaviour.h:40
virtual level_t computeActivationLevel()
Callback for the computation of the raw behaviour activation level. Valid return values are false...
Definition: behaviour.h:69
virtual void update()
Update callback for the behaviour object. This function is called from BehaviourLayer::updateAll(), which is used in BehaviourLayer::step().
Definition: behaviour.h:56
float level_t
Used to represent an activation level (raw activation levels should always be in the range [0...
Definition: behaviour_common.h:141
Behaviour(BehaviourLayer *LBase, const std::string &name=nullString)
Default constructor.
Definition: behaviour.cpp:29
Common definitions include file for the internal Behaviour Control Framework source code...
static const std::string DEF_BEHAVIOUR_NAME
Default behaviour name used to generate a unique one, in the case that no name is provided by a deriv...
Definition: behaviour.h:31