16 #ifndef BEHAVIOUR_TEMPLATE_DEFNS_H
17 #define BEHAVIOUR_TEMPLATE_DEFNS_H
23 namespace behaviourcontrol
30 template <
class SClass>
31 void SensorManager::declareSensor(SClass* sensor)
34 BOOST_STATIC_ASSERT_MSG((boost::is_base_of<SensorBase, SClass>::value),
"SClass template parameter must be a derived class of behaviourcontrol::SensorBase");
37 ASSERT_WARNING(sensor != NULL,
MBase,
"Failed to declare the requested sensor as a child of the '" +
LBase->
name +
"' layer sensor manager - Provided sensor pointer was null!");
38 ASSERT_WARNING(!
MBase->
isInitialising(),
MBase,
"Attempted to declare the '" + sensor->signalName +
"'sensor as a child of the '" +
LBase->
name +
"' layer sensor manager during initialisation - All sensor declarations should be in the sensor manager constructor!");
39 ASSERT_WARNING(!
MBase->
wasInitialised(),
MBase,
"Attempted to declare the '" + sensor->signalName +
"'sensor as a child of the '" +
LBase->
name +
"' layer sensor manager after initialisation - All sensor declarations should be in the sensor manager constructor!");
42 SList.push_back(sensor->getBasePtr());
62 , typeInfo(&typeid(T))
65 , actWasWrittenTo(false)
95 if(MBase->wasInitialised())
97 REPORT_WARNING(MBase,
"Request to bind to actuator '" + ABase->
signalName +
"' denied - The behaviour manager has already been successfully initialised!");
102 if(!isCompatibleWith(ABase))
104 REPORT_WARNING(MBase,
"Request to bind to actuator '" + ABase->
signalName +
"' denied - This actuator has the wrong data type ('" + std::string(ABase->
getTypeInfo()->name()) +
"')!");
109 try { sourceAct =
dynamic_cast<const Actuator<T>*
>(ABase); }
113 REPORT_WARNING(MBase,
"Request to bind to actuator '" + ABase->
signalName +
"' failed - Dynamic cast to type 'const Actuator<T> *' for T = '" + std::string(ABase->
getTypeInfo()->name()) +
"' failed!");
125 if(sourceAct != NULL)
127 data = sourceAct->read();
128 actWasWrittenTo = sourceAct->wasWrittenTo();
137 template <
class AClass>
138 void ActuatorManager::declareActuator(AClass* actuator)
141 BOOST_STATIC_ASSERT_MSG((boost::is_base_of<ActuatorBase, AClass>::value),
"AClass template parameter must be a derived class of behaviourcontrol::ActuatorBase");
144 ASSERT_WARNING(actuator != NULL,
MBase,
"Failed to declare the requested actuator as a child of the '" +
LBase->
name +
"' layer actuator manager - Provided actuator pointer was null!");
145 ASSERT_WARNING(!
MBase->
isInitialising(),
MBase,
"Attempted to declare the '" + actuator->signalName +
"'actuator as a child of the '" +
LBase->
name +
"' layer actuator manager during initialisation - All actuator declarations should be in the actuator manager constructor!");
146 ASSERT_WARNING(!
MBase->
wasInitialised(),
MBase,
"Attempted to declare the '" + actuator->signalName +
"'actuator as a child of the '" +
LBase->
name +
"' layer actuator manager after initialisation - All actuator declarations should be in the actuator manager constructor!");
149 AList.push_back(actuator->getBasePtr());
180 , aggregatable(aggregatable)
181 , typeInfo(&typeid(T))
214 ASSERT_WARNING(MBase->wasInitialised(), MBase,
"A call to write() was attempted on the actuator '" + signalName +
"' (part of the '" + LBase->name +
"' layer) before or during initialisation - consider using writeHard() instead!");
215 ASSERT_WARNING(BBase != NULL, MBase,
"Attempted to write to the actuator '" + signalName +
"' with null behaviour pointer!");
216 ASSERT_WARNING(BBase != lastModifier, MBase,
"The behaviour '" + BBase->
name +
"' attempted multiple writes to the actuator '" + signalName +
"'!");
217 ASSERT_WARNING(!LBase->isInterface, MBase,
"A call to write() was attempted on an actuator ('" + signalName +
"') that belongs to an interface layer ('" + LBase->name +
"') - consider using writeHard() instead!");
224 weight = BBase->
getA();
225 lastModifier = BBase;
228 if(weight <= 0.0)
return;
241 bool firstWrite = (weightSum <= 0.0);
244 ASSERT_WARNING(MBase->wasInitialised(), MBase,
"A call to write() was attempted on the actuator '" + signalName +
"' (part of the '" + LBase->name +
"' layer) before or during initialisation - consider using writeHard() instead!");
245 ASSERT_WARNING(BBase != NULL, MBase,
"Attempted to write to the actuator '" + signalName +
"' with null behaviour pointer!");
246 ASSERT_WARNING(BBase != lastModifier, MBase,
"The behaviour '" + BBase->
name +
"' attempted multiple writes to the actuator '" + signalName +
"'!");
247 ASSERT_WARNING(!LBase->isInterface, MBase,
"A call to write() was attempted on an actuator ('" + signalName +
"') that belongs to an interface layer ('" + LBase->name +
"') - consider using writeHard() instead!");
248 ASSERT_WARNING(aggregatable, MBase,
"A call to writeAgg() was made for the non-aggregatable actuator '" + signalName +
"' (part of the '" + LBase->name +
"' layer) - consider using write() instead!");
251 weight = BBase->
getA();
252 lastModifier = BBase;
255 if(weight <= 0.0)
return;
270 data = data*(1-p) + newdata*p;
277 bool firstWrite = (weightSum <= 0.0);
280 ASSERT_WARNING((LBase->isInterface || !MBase->wasInitialised()), MBase,
"A call to writeHard() was attempted on the actuator '" + signalName +
"' (part of non-interface layer '" + LBase->name +
"') after initialisation - consider using write() instead!");
281 ASSERT_WARNING((firstWrite || MBase->wasInitialised()), MBase,
"More than one write to the actuator '" + signalName +
"' was detected during initialisation (part of the '" + LBase->name +
"' layer)!");
297 template <
class LClass>
298 void BehaviourManager::declareLayer(LClass* layer)
301 BOOST_STATIC_ASSERT_MSG((boost::is_base_of<BehaviourLayer, LClass>::value),
"LClass template parameter must be a derived class of behaviourcontrol::BehaviourLayer");
304 ASSERT_WARNING(layer != NULL,
this,
"Failed to declare the requested layer as a child of the '" +
name +
"' behaviour manager - Provided layer pointer was null!");
305 ASSERT_WARNING(!
isInitialising(),
this,
"Attempted to declare the '" + layer->name +
"'layer as a child of the '" +
name +
"' behaviour manager during initialisation - All layer declarations should be in the behaviour manager constructor!");
306 ASSERT_WARNING(!
wasInitialised(),
this,
"Attempted to declare the '" + layer->name +
"'layer as a child of the '" +
name +
"' behaviour manager after initialisation - All layer declarations should be in the behaviour manager constructor!");
309 LList.push_back(layer->getBasePtr());
317 template <
class BClass>
318 void BehaviourLayer::declareBehaviour(BClass* behaviour)
321 BOOST_STATIC_ASSERT_MSG((boost::is_base_of<Behaviour, BClass>::value),
"BClass template parameter must be a derived class of behaviourcontrol::Behaviour");
324 ASSERT_WARNING(behaviour != NULL,
MBase,
"Failed to declare the requested behaviour as a child of the '" +
name +
"' layer - Provided behaviour pointer was null!");
325 ASSERT_WARNING(!
MBase->
isInitialising(),
MBase,
"Attempted to declare the '" + behaviour->
name +
"'behaviour as a child of the '" +
name +
"' layer during initialisation - All behaviour declarations should be in the layer constructor!");
326 ASSERT_WARNING(!
MBase->
wasInitialised(),
MBase,
"Attempted to declare the '" + behaviour->
name +
"'behaviour as a child of the '" +
name +
"' layer after initialisation - All behaviour declarations should be in the layer constructor!");
329 BList.push_back(behaviour->getBasePtr());
bool wasInitialised() const
Boolean flag specifying whether the manager has been initialised yet or not.
Definition: behaviour_manager.h:44
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
virtual ~Actuator()
Actuator object destructor.
Definition: behaviour_template_defns.h:190
Implements a single actuator of a given data type.
Definition: behaviour_actuators.h:131
Sensor(SensorManager *SMBase, const std::string &signalName)
Default constructor.
Definition: behaviour_template_defns.h:60
BehaviourManager *const MBase
Pointer to the parent behaviour manager.
Definition: behaviour_layer.h:48
bool isInitialising() const
Boolean flag specifying whether the manager is currently initialising or not.
Definition: behaviour_manager.h:45
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
virtual const std::type_info * getTypeInfo() const =0
Abstract callback that should be overridden to return the type information of the sensor (i...
#define REPORT_WARNING(MBasePtr, msg)
Reports a std::string warning message msg to the behaviour manager pointed to by MBasePtr (fatal = fa...
Definition: behaviour_common.h:40
const std::string name
Human-friendly string name of the behaviour manager.
Definition: behaviour_manager.h:39
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
const std::string signalName
The name of the actuator, used as the lookup key for the BehaviourManager::findActuator() function...
Definition: behaviour_actuators.h:90
BehaviourLayer *const LBase
Pointer to the parent behaviour layer.
Definition: behaviour_actuators.h:38
Signals that a duplicate call of a once-only initialisation function was attempted.
Definition: behaviour_common.h:73
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
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
virtual ~Sensor()
Destructor.
Definition: behaviour_template_defns.h:71
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
BehaviourManager *const MBase
Pointer to the parent behaviour manager.
Definition: behaviour_actuators.h:37
#define ASSERT_WARNING(cond, MBasePtr, msg)
Reports a std::string warning message msg to the behaviour manager pointed to by MBasePtr if cond eva...
Definition: behaviour_common.h:44
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
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
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
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
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
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
Common definitions include file for the internal Behaviour Control Framework source code...
Signals that an attempt to bind a sensor to an actuator failed because of an actuator/sensor data typ...
Definition: behaviour_common.h:76