NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
behaviour_sensors.h
Go to the documentation of this file.
1 // Behaviour Control Framework - Sensor classes
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
9 // Ensure header is only included once
10 #ifndef BEHAVIOUR_SENSORS_H
11 #define BEHAVIOUR_SENSORS_H
12 
13 // Includes
15 
16 // Behaviour control namespace
17 namespace behaviourcontrol
18 {
27  {
28  public:
29  // Constants
30  static const index_t DEF_SLIST_CAPACITY;
31 
32  // Constructors
34  virtual ~SensorManager();
35 
36  // Constant properties
39 
40  // Initialisation functions
41  protected:
42  virtual ret_t init() { return RET_OK; }
43  private:
44  ret_t initAllBase();
45 
46  private:
47  // Update function
48  void updateSensors();
49 
50  // Sensor declaration function
51  template <class SClass> void declareSensor(SClass* sensor);
52 
53  // Sensor list
54  std::vector<SensorBase*> SList;
55 
56  public:
57  // Write data to an external source (used only in interface layers)
58  virtual void writeExternalData() {}
59 
60  // Get functions
61  SensorManager* getBasePtr() { return this; }
62 
63  // Friend classes
64  friend class BehaviourManager;
65  friend class BehaviourLayer;
66  friend class SensorBase;
67  };
68 
76  class SensorBase
77  {
78  public:
79  // Constructors
80  SensorBase(SensorManager* SMBase, const std::string& signalName);
81  virtual ~SensorBase();
82 
83  // Constant properties
87  const std::string signalName;
88 
89  // Initialisation function
90  private:
91  ret_t initBase();
92 
93  public:
94  // Template type information
95  virtual const std::type_info* getTypeInfo() const = 0;
96  virtual bool isCompatibleWith(const ActuatorBase* ABase) const = 0;
97 
98  // Data bind and update functions
99  protected:
100  virtual ret_t bindTo(const ActuatorBase* ABase) = 0;
101  virtual void getLatestData() = 0;
102  public:
103  virtual bool isBound() const = 0;
104 
105  public:
106  // Get functions
107  SensorBase* getBasePtr() { return this; }
108 
109  // Friend classes
110  friend class SensorManager;
111  };
112 
121  template <class T>
122  class Sensor : public SensorBase
123  {
124  public:
125  // Constructors
126  Sensor(SensorManager* SMBase, const std::string& signalName);
127  virtual ~Sensor();
128 
129  // Template type information
130  const std::type_info* const typeInfo;
131  virtual const std::type_info* getTypeInfo() const { return typeInfo; }
132  virtual bool isCompatibleWith(const ActuatorBase* ABase) const;
133 
134  // Data bind, update and read functions
135  protected:
136  virtual ret_t bindTo(const ActuatorBase* ABase);
137  virtual void getLatestData();
138  public:
139  virtual bool isBound() const { return (sourceAct != NULL); }
140  bool wasWrittenTo() const { return actWasWrittenTo; }
141  const T& read() const { return data; }
142 
143  private:
144  // Internal variables
145  const Actuator<T>* sourceAct;
146  T data;
147  bool actWasWrittenTo;
148  };
149 }
150 
151 #endif /* BEHAVIOUR_SENSORS_H */
152 // EOF
BehaviourManager *const MBase
Pointer to the parent behaviour manager.
Definition: behaviour_sensors.h:84
int ret_t
Used to represent an error code/function return value.
Definition: behaviour_common.h:142
virtual ~SensorManager()
Sensor manager object destructor.
Definition: behaviour_sensors.cpp:31
Implements a single behaviour layer.
Definition: behaviour_layer.h:26
Implements a single actuator of a given data type.
Definition: behaviour_actuators.h:131
virtual bool isBound() const =0
Abstract function that should be made to return whether this sensor has been bound to an actuator...
Sensor(SensorManager *SMBase, const std::string &signalName)
Default constructor.
Definition: behaviour_template_defns.h:60
Signals successful execution of a function, with no error conditions encountered. ...
Definition: behaviour_common.h:69
virtual void getLatestData()=0
Abstract function that should be made to retrieve the data from the bound actuator, and store it locally in the sensor.
static const index_t DEF_SLIST_CAPACITY
Default capacity of the list that stores the child sensors of the sensor manager. ...
Definition: behaviour_sensors.h:30
virtual const std::type_info * getTypeInfo() const =0
Abstract callback that should be overridden to return the type information of the sensor (i...
SensorBase(SensorManager *SMBase, const std::string &signalName)
Default constructor.
Definition: behaviour_sensors.cpp:75
bool wasWrittenTo() const
Valid after every call to getLatestData() (called by SensorManager::updateSensors() during the update...
Definition: behaviour_sensors.h:140
SensorBase * getBasePtr()
Return a pointer to the underlying SensorBase object in the case of a derived sensor class...
Definition: behaviour_sensors.h:107
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_sensors.h:38
virtual ret_t bindTo(const ActuatorBase *ABase)
Bind to the actuator ABase. This must be called with an ABase that is actually pointing to an Actuato...
Definition: behaviour_template_defns.h:88
SensorManager *const SMBase
Pointer to the parent sensor manager.
Definition: behaviour_sensors.h:86
virtual ret_t bindTo(const ActuatorBase *ABase)=0
Abstract function that should be made to bind the sensor to the ABase actuator.
virtual bool isCompatibleWith(const ActuatorBase *ABase) const =0
Abstract callback that should evaluate whether the current sensor is compatible the actuator ABase (c...
virtual ret_t init()
Initialisation callback for the sensor manager. This function is called from BehaviourLayer::initAll(...
Definition: behaviour_sensors.h:42
virtual ~Sensor()
Destructor.
Definition: behaviour_template_defns.h:71
const T & read() const
Get the data from the last sensor update (i.e. get the data that was most recently copied from the so...
Definition: behaviour_sensors.h:141
virtual const std::type_info * getTypeInfo() const
Abstract callback that should be overridden to return the type information of the sensor (i...
Definition: behaviour_sensors.h:131
virtual bool isBound() const
Return whether this sensor has successfully been bound to an actuator.
Definition: behaviour_sensors.h:139
Implements a single actuator.
Definition: behaviour_actuators.h:76
virtual bool isCompatibleWith(const ActuatorBase *ABase) const
Abstract callback that should evaluate whether the current sensor is compatible the actuator ABase (c...
Definition: behaviour_template_defns.h:77
Implements a single behaviour manager.
Definition: behaviour_manager.h:27
BehaviourManager *const MBase
Pointer to the parent behaviour manager.
Definition: behaviour_sensors.h:37
virtual void getLatestData()
Get the latest data from the source actuator.
Definition: behaviour_template_defns.h:123
BehaviourLayer *const LBase
Pointer to the parent behaviour layer.
Definition: behaviour_sensors.h:85
Implements a single sensor.
Definition: behaviour_sensors.h:76
SensorManager * getBasePtr()
Return a pointer to the underlying SensorManager class object in the case of a derived sensor manager...
Definition: behaviour_sensors.h:61
Implements a manager of a particular group of sensors.
Definition: behaviour_sensors.h:26
virtual void writeExternalData()
Interface layer specific callback that is intended to be overridden by the user to write any availabl...
Definition: behaviour_sensors.h:58
SensorManager(BehaviourLayer *LBase)
Default constructor.
Definition: behaviour_sensors.cpp:19
const std::string signalName
The name of the actuator that this sensor should bind to. This name is used as the lookup key for the...
Definition: behaviour_sensors.h:87
Common definitions include file for the internal Behaviour Control Framework source code...
virtual ~SensorBase()
SensorBase object destructor.
Definition: behaviour_sensors.cpp:86