NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
behaviour_actuators.h
Go to the documentation of this file.
1 // Behaviour Control Framework - Actuator classes
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
9 // Ensure header is only included once
10 #ifndef BEHAVIOUR_ACTUATORS_H
11 #define BEHAVIOUR_ACTUATORS_H
12 
13 // Includes
15 
16 // Behaviour control namespace
17 namespace behaviourcontrol
18 {
27  {
28  public:
29  // Constants
30  static const index_t DEF_ALIST_CAPACITY;
31 
32  // Constructors
34  virtual ~ActuatorManager();
35 
36  // Constant properties
39 
40  // Initialisation functions
41  protected:
42  virtual ret_t init() { return RET_OK; }
43  private:
44  ret_t initBase();
45 
46  private:
47  // Update function
48  void updateActuators();
49 
50  // Actuator declaration function
51  template <class AClass> void declareActuator(AClass* actuator);
52 
53  // Actuator list
54  std::vector<ActuatorBase*> AList;
55 
56  public:
57  // Read data from an external source (used only in interface layers)
58  virtual void readExternalData() {}
59 
60  // Get functions
61  ActuatorManager* getBasePtr() { return this; }
62 
63  // Friend classes
64  friend class BehaviourManager;
65  friend class BehaviourLayer;
66  friend class ActuatorBase;
67  };
68 
77  {
78  public:
79  // Constants
80  static const std::string DEF_ACTUATOR_SIGNAL_NAME;
81 
82  // Constructors
83  explicit ActuatorBase(ActuatorManager* AMBase, const std::string& signalName = nullString);
84  virtual ~ActuatorBase();
85 
86  // Constant properties
90  const std::string signalName;
91 
92  private:
93  // Update function
94  virtual void update() {};
95 
96  public:
97  // Template type information
98  virtual const std::type_info* getTypeInfo() const = 0;
99  virtual bool isCompatibleWith(const SensorBase* SBase) const = 0;
100 
101  // Get functions
102  std::string getUniqueName(const ActuatorManager* AMBase) const;
103  ActuatorBase* getBasePtr() { return this; }
104 
105  // Friend classes
106  friend class ActuatorManager;
107  };
108 
130  template <class T>
131  class Actuator : public ActuatorBase
132  {
133  public:
134  // Constructors
135  explicit Actuator(ActuatorManager* AMBase, const std::string& signalName = nullString, bool aggregatable = AGGREGATABLE);
136  virtual ~Actuator();
137 
138  // Template type information
139  const bool aggregatable;
140  const std::type_info* const typeInfo;
141  virtual const std::type_info* getTypeInfo() const { return typeInfo; }
142  virtual bool isCompatibleWith(const SensorBase* SBase) const;
143 
144  // Data read and write functions
145  const T& read() const { return data; }
146  void write(const T& newdata, const Behaviour* BBase);
147  void writeAgg(const T& newdata, const Behaviour* BBase);
148  void writeHard(const T& newdata);
149  bool wasWrittenTo() const { return weightSum > 0.0; }
150 
151  private:
152  // Update function
153  virtual void update() { weightSum = 0.0; lastModifier = NULL; };
154 
155  // Internal variables
156  T data;
157  level_t weightSum;
158  const Behaviour* lastModifier;
159  };
160 }
161 
162 #endif /* BEHAVIOUR_ACTUATORS_H */
163 // EOF
Implements a single behaviour.
Definition: behaviour.h:26
ActuatorBase(ActuatorManager *AMBase, const std::string &signalName=nullString)
Default constructor.
Definition: behaviour_actuators.cpp:70
virtual bool isCompatibleWith(const SensorBase *SBase) const =0
Abstract callback that should evaluate whether the current actuator is compatible the sensor SBase (c...
bool wasWrittenTo() const
Returns whether the actuator has been written to since the last update (update() is called at the beg...
Definition: behaviour_actuators.h:149
ActuatorManager * getBasePtr()
Return a pointer to the underlying ActuatorManager class object in the case of a derived actuator man...
Definition: behaviour_actuators.h:61
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 actuator manager. This function is called from BehaviourLayer::initAl...
Definition: behaviour_actuators.h:42
virtual ~Actuator()
Actuator object destructor.
Definition: behaviour_template_defns.h:190
ActuatorManager(BehaviourLayer *LBase)
Default constructor.
Definition: behaviour_actuators.cpp:20
Implements a single behaviour layer.
Definition: behaviour_layer.h:26
static const index_t DEF_ALIST_CAPACITY
Default capacity of the list that stores the child actuators of the actuator manager.
Definition: behaviour_actuators.h:30
Implements a single actuator of a given data type.
Definition: behaviour_actuators.h:131
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
const bool AGGREGATABLE
Used in the Actuator constructor to explicitly specify an aggregatable actuator.
Definition: behaviour_common.h:151
const std::string signalName
The name of the actuator, used as the lookup key for the BehaviourManager::findActuator() function...
Definition: behaviour_actuators.h:90
virtual void readExternalData()
Interface layer specific callback that is intended to be overridden by the user to retrieve any avail...
Definition: behaviour_actuators.h:58
std::size_t index_t
Used to represent an array or vector index (must be an unsigned type)
Definition: behaviour_common.h:140
BehaviourLayer *const LBase
Pointer to the parent behaviour layer.
Definition: behaviour_actuators.h:38
static const std::string DEF_ACTUATOR_SIGNAL_NAME
Default actuator signal name used to generate a unique one, in the case that no name is provided by a...
Definition: behaviour_actuators.h:80
ActuatorBase * getBasePtr()
Return a pointer to the underlying ActuatorBase object in the case of a derived actuator class...
Definition: behaviour_actuators.h:103
void writeAgg(const T &newdata, const Behaviour *BBase)
General purpose write function to be used by behaviours to write to aggregatable actuators. Do not use this function on non-aggregatable actuators.
Definition: behaviour_template_defns.h:237
BehaviourLayer *const LBase
Pointer to the parent behaviour layer.
Definition: behaviour_actuators.h:88
ActuatorManager *const AMBase
Pointer to the parent actuator manager.
Definition: behaviour_actuators.h:89
virtual ~ActuatorManager()
Actuator manager object destructor.
Definition: behaviour_actuators.cpp:32
virtual const std::type_info * getTypeInfo() const =0
Update callback for the ActuatorBase object. Refer to the default override defined in Actuator::updat...
void writeHard(const T &newdata)
Special write function that can be used during initialisation to set up the value of an actuator...
Definition: behaviour_template_defns.h:274
std::string getUniqueName(const ActuatorManager *AMBase) const
Returns a unique actuator name.
Definition: behaviour_actuators.cpp:96
BehaviourManager *const MBase
Pointer to the parent behaviour manager.
Definition: behaviour_actuators.h:37
Implements a single actuator.
Definition: behaviour_actuators.h:76
Actuator(ActuatorManager *AMBase, const std::string &signalName=nullString, bool aggregatable=AGGREGATABLE)
Default constructor.
Definition: behaviour_template_defns.h:178
Implements a single behaviour manager.
Definition: behaviour_manager.h:27
virtual ~ActuatorBase()
ActuatorBase object destructor.
Definition: behaviour_actuators.cpp:81
const std::string nullString
Used to avoid the need for null string literals throughout the code.
Definition: behaviour_common.h:148
void write(const T &newdata, const Behaviour *BBase)
General purpose write function to be used by behaviours to write to non-aggregatable actuators...
Definition: behaviour_template_defns.h:207
virtual bool isCompatibleWith(const SensorBase *SBase) const
Abstract callback that should evaluate whether the current actuator is compatible the sensor SBase (c...
Definition: behaviour_template_defns.h:196
Implements a single sensor.
Definition: behaviour_sensors.h:76
virtual const std::type_info * getTypeInfo() const
Update callback for the ActuatorBase object. Refer to the default override defined in Actuator::updat...
Definition: behaviour_actuators.h:141
const T & read() const
Get function for the current data contained in the actuator.
Definition: behaviour_actuators.h:145
float level_t
Used to represent an activation level (raw activation levels should always be in the range [0...
Definition: behaviour_common.h:141
BehaviourManager *const MBase
Pointer to the parent behaviour manager.
Definition: behaviour_actuators.h:87
Common definitions include file for the internal Behaviour Control Framework source code...
const std::type_info *const typeInfo
The type information of the actuator data type.
Definition: behaviour_actuators.h:140
const bool aggregatable
Flag that specifies whether the actuator is aggregatable.
Definition: behaviour_actuators.h:139