NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
behaviour_common.h
Go to the documentation of this file.
1 // Behaviour Control Framework - Common definitions
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
9 // Ensure header is only included once
10 #ifndef BEHAVIOUR_COMMON_H
11 #define BEHAVIOUR_COMMON_H
12 
13 // Includes
14 #include <cstddef> // For std::size_t
15 #include <vector> // For std::vector
16 #include <string> // For std::string
17 #include <sstream> // For std::ostringstream
18 #include <typeinfo> // For std::type_info
19 #include <boost/static_assert.hpp> // For BOOST_STATIC_ASSERT_MSG()
20 #include <boost/type_traits.hpp> // For checking template types
21 #include <boost/utility/enable_if.hpp> // For boost::enable_if
22 
23 // Define a macro to retrieve the executing function name
24 #if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
25 #define CURRENT_FUNC __FUNCTION__
26 #elif defined(__GNUC__) || defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) || (defined(__ICC) && (__ICC >= 600))
27 #define CURRENT_FUNC __func__
28 #else
29 #define CURRENT_FUNC "<unknown>"
30 #endif
31 
37 #define REPORT_ERROR(MBasePtr, msg) (MBasePtr)->reportError((msg),true,CURRENT_FUNC,__FILE__,__LINE__)
39 #define REPORT_ERROR_(MBase, msg) (MBase).reportError((msg),true,CURRENT_FUNC,__FILE__,__LINE__)
40 #define REPORT_WARNING(MBasePtr, msg) (MBasePtr)->reportError((msg),false,CURRENT_FUNC,__FILE__,__LINE__)
41 #define REPORT_WARNING_(MBase, msg) (MBase).reportError((msg),false,CURRENT_FUNC,__FILE__,__LINE__)
42 #define ASSERT_ERROR(cond, MBasePtr, msg) if(!(cond)) { REPORT_ERROR((MBasePtr),msg); return; }
43 #define ASSERT_ERROR_(cond, MBase, msg) if(!(cond)) { REPORT_ERROR_((MBase),msg); return; }
44 #define ASSERT_WARNING(cond, MBasePtr, msg) if(!(cond)) { REPORT_WARNING((MBasePtr),msg); return; }
45 #define ASSERT_WARNING_(cond, MBase, msg) if(!(cond)) { REPORT_WARNING_((MBase),msg); return; }
46 
48 // Behaviour control namespace
49 namespace behaviourcontrol
50 {
51  //
52  // Class declarations
53  //
54  class SensorManager;
55  class SensorBase;
56  template <class T> class Sensor;
57  class ActuatorManager;
58  class ActuatorBase;
59  template <class T> class Actuator;
60  class BehaviourManager;
61  class BehaviourLayer;
62  class Behaviour;
63 
64  //
65  // Enumerations
66  //
68  {
69  RET_OK = 0,
78  };
79 
80  //
81  // Type definitions
82  //
83 
97  typedef Sensor<bool> SensorBool;
108 
123  typedef Actuator<bool> ActuatorBool;
134 
139  typedef std::size_t index_t;
141  typedef float level_t;
142  typedef int ret_t;
143 
145  //
146  // Constants
147  //
148  const std::string nullString = "";
149  const level_t LVL_ACTIVE = 1.0;
150  const level_t LVL_INACTIVE = 0.0;
151  const bool AGGREGATABLE = true;
152  const bool NOT_AGGREGATABLE = false;
153 
154  //
155  // Functions
156  //
157 
158  // Function: addIfUnique()
168  template <class T>
169  void addIfUnique(std::vector<T>& V, T& value)
170  {
171  // Declare variables
172  bool duplicate;
173  index_t i;
174 
175  // Check whether an equivalent element already exists in the vector
176  duplicate = false;
177  for(i = 0;i < V.size();i++)
178  {
179  if(V[i] == value)
180  {
181  duplicate = true;
182  break;
183  }
184  }
185 
186  // Add the element to the vector if no duplicate was found
187  if(!duplicate)
188  V.push_back(value);
189  }
190 }
191 
192 #endif /* BEHAVIOUR_COMMON_H */
193 // EOF
Implements a single behaviour.
Definition: behaviour.h:26
Actuator< long double > ActuatorLDouble
An actuator of data type long double
Definition: behaviour_common.h:133
int ret_t
Used to represent an error code/function return value.
Definition: behaviour_common.h:142
Actuator< unsigned long long > ActuatorULLong
An actuator of data type unsigned long long
Definition: behaviour_common.h:130
Sensor< double > SensorDouble
An sensor of data type double
Definition: behaviour_common.h:106
Signals that an action was attempted despite a pre-existing fatal error condition.
Definition: behaviour_common.h:72
Sensor< unsigned int > SensorUInt
An sensor of data type unsigned int
Definition: behaviour_common.h:100
Sensor< unsigned long long > SensorULLong
An sensor of data type unsigned long long
Definition: behaviour_common.h:104
Implements a single behaviour layer.
Definition: behaviour_layer.h:26
Implements a single actuator of a given data type.
Definition: behaviour_actuators.h:131
const level_t LVL_INACTIVE
Used to signal that a behaviour wishes to be fully deactivated.
Definition: behaviour_common.h:150
Sensor< long > SensorLong
An sensor of data type long
Definition: behaviour_common.h:101
Actuator< int > ActuatorInt
An actuator of data type int
Definition: behaviour_common.h:125
Actuator< bool > ActuatorBool
An actuator of data type bool
Definition: behaviour_common.h:124
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
Actuator< unsigned int > ActuatorUInt
An actuator of data type unsigned int
Definition: behaviour_common.h:126
Actuator< double > ActuatorDouble
An actuator of data type double
Definition: behaviour_common.h:132
const bool AGGREGATABLE
Used in the Actuator constructor to explicitly specify an aggregatable actuator.
Definition: behaviour_common.h:151
Actuator< unsigned long > ActuatorULong
An actuator of data type unsigned long
Definition: behaviour_common.h:128
Signals that an attempt to bind a sensor to an actuator failed because no actuator of a suitable name...
Definition: behaviour_common.h:75
std::size_t index_t
Used to represent an array or vector index (must be an unsigned type)
Definition: behaviour_common.h:140
Signals that a duplicate call of a once-only initialisation function was attempted.
Definition: behaviour_common.h:73
Sensor< int > SensorInt
An sensor of data type int
Definition: behaviour_common.h:99
Sensor< unsigned long > SensorULong
An sensor of data type unsigned long
Definition: behaviour_common.h:102
Sensor< float > SensorFloat
An sensor of data type float
Definition: behaviour_common.h:105
Sensor< bool > SensorBool
An sensor of data type bool
Definition: behaviour_common.h:98
Actuator< float > ActuatorFloat
An actuator of data type float
Definition: behaviour_common.h:131
Sensor< long long > SensorLLong
An sensor of data type long long
Definition: behaviour_common.h:103
Actuator< long long > ActuatorLLong
An actuator of data type long long
Definition: behaviour_common.h:129
FuncReturnID
Used to specify return values and error codes of certain behaviour control framework functions...
Definition: behaviour_common.h:67
Implements a single actuator.
Definition: behaviour_actuators.h:76
Signals an unknown or unspecified error.
Definition: behaviour_common.h:70
const bool NOT_AGGREGATABLE
Used in the Actuator constructor to specify a non-aggregatable actuator.
Definition: behaviour_common.h:152
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
Signals that an attempt to bind a sensor to an actuator failed because of a null sensor signal name...
Definition: behaviour_common.h:74
Actuator< long > ActuatorLong
An actuator of data type long
Definition: behaviour_common.h:127
void addIfUnique(std::vector< T > &V, T &value)
Add an element to a std::vector if an equivalent element (A == B) is not already in there...
Definition: behaviour_common.h:169
Sensor< long double > SensorLDouble
An sensor of data type long double
Definition: behaviour_common.h:107
Signals that an unexpected null pointer was encountered (usually as a function parameter) ...
Definition: behaviour_common.h:71
float level_t
Used to represent an activation level (raw activation levels should always be in the range [0...
Definition: behaviour_common.h:141
Signals that a cycle was detected in the behaviour inhibition definitions of a layer.
Definition: behaviour_common.h:77
Signals that an attempt to bind a sensor to an actuator failed because of an actuator/sensor data typ...
Definition: behaviour_common.h:76
const level_t LVL_ACTIVE
Used to signal that a behaviour wishes to be fully activated.
Definition: behaviour_common.h:149
Implements a single sensor of a given data type.
Definition: behaviour_common.h:56