![]() |
NimbRo ROS Soccer Package
|
Implements a single behaviour manager. More...
#include <behaviour_manager.h>
Inherited by behaviourcontroltest::MyM.
Public Member Functions | |
BehaviourManager (const std::string &name=nullString) | |
Default constructor. More... | |
virtual | ~BehaviourManager () |
Behaviour manager object destructor. | |
ret_t | initialiseArchitecture () |
Function that should be called by the user to initialise the entire behaviour manager architecture, including all child layers, behaviours, sensor managers, actuator managers, and so on. More... | |
bool | wasInitialised () const |
Boolean flag specifying whether the manager has been initialised yet or not. | |
bool | isInitialising () const |
Boolean flag specifying whether the manager is currently initialising or not. | |
void | step () |
Function that should be called by the user to execute one step of the entire behaviour manager architecture. More... | |
int | cycleID () const |
The numeric ID of the current step cycle of the behaviour manager. Prior to the first step this ID is 0. The ID is incremented by one in each call to step() . | |
void | reportError (const std::string &msg, bool fatal, const std::string &funcName, const std::string &fileName, int line) |
Function used to signal that a warning or an error has occurred. After setting the appropriate error flags, this function invokes the reportErrorUser() function. It is recommended to use this function only indirectly via the Error Macros. More... | |
virtual void | reportErrorUser (const std::string &msg, bool fatal, const std::string &funcName, const std::string &fileName, int line) |
Error handler function that is intended to be overridden by the user to process and/or display warnings and errors raised by the framework. A non-fatal error is a warning. | |
void | clearErrorStatus () |
Reset the error status flags so that functions like initialiseArchitecture() and step() can be attempted to be called again. | |
bool | hadError () const |
Boolean flag that specifies whether an error has occurred with the architecture. | |
bool | hadWarning () const |
Boolean flag that specifies whether an error or warning has occurred with the architecture. | |
std::string | toString (const std::string &linePrefix=nullString) const |
Generates a multiline string representation of the architecture, summarising all of the main components. More... | |
const ActuatorBase * | findActuator (const std::string &signalName) const |
Finds an actuator within the architecture, given its string name as a lookup key. More... | |
BehaviourManager * | getBasePtr () |
Return a pointer to the underlying BehaviourManager class object in the case of a derived behaviour manager class. | |
Public Attributes | |
const std::string | name |
Human-friendly string name of the behaviour manager. | |
Static Public Attributes | |
static const index_t | DEF_LLIST_CAPACITY = 4 |
Default capacity of the list that stores the child behaviour layers of the manager. | |
static const std::string | DEF_MANAGER_NAME = "BehaviourManager" |
Default behaviour manager name used to generate a unique one, in the case that no name is provided by a derived behaviour manager class. | |
Protected Member Functions | |
virtual ret_t | init () |
Initialisation callback for the behaviour manager. This function is called from initialiseArchitecture() , and is intended to be overridden for the purpose of initialising the derived behaviour manager object. | |
virtual void | preStepCallback () |
Callback that is invoked at the beginning of the step() function so that the user can inject code. | |
virtual void | postStepCallback () |
Callback that is invoked at the end of the step() function so that the user can inject code. | |
Friends | |
class | BehaviourLayer |
class | SensorBase |
Implements a single behaviour manager.
This class implements a base class for all behaviour managers that are used in an architecture. In a single process application typically only one behaviour manager is required.
|
explicit |
Default constructor.
Note that although the default value for the name
parameter is nullString
, this will not actually become the behaviour manager's name if the parameter is omitted. This is just used to signal to the class's internals that it should use the default name (DEF_MANAGER_NAME) when none is provided.
name | The human-friendly name to give the behaviour manager (null means use default) |
const ActuatorBase * BehaviourManager::findActuator | ( | const std::string & | signalName | ) | const |
Finds an actuator within the architecture, given its string name as a lookup key.
Note that this function returns the first actuator of the requested name. The layers are searched in order from the first layer in the manager's layer list (BehaviourManager::LList
) to the last. NULL
is returned if no actuator of the requested name was found, or if signalName
was a null string.
signalName | The actuator name to search for. |
ret_t BehaviourManager::initialiseArchitecture | ( | ) |
Function that should be called by the user to initialise the entire behaviour manager architecture, including all child layers, behaviours, sensor managers, actuator managers, and so on.
The initialisation order is as follows:
initBase()
BehaviourLayer::initAllBase()
init()
BehaviourLayer::initAll()
The function can only be called once, or RET_ALREADY_INITIALISED is returned.
ret_t
type that specifies whether the initialisation was successful. void BehaviourManager::reportError | ( | const std::string & | msg, |
bool | fatal, | ||
const std::string & | funcName, | ||
const std::string & | fileName, | ||
int | line | ||
) |
Function used to signal that a warning or an error has occurred. After setting the appropriate error flags, this function invokes the reportErrorUser()
function. It is recommended to use this function only indirectly via the Error Macros.
msg | A std::string message that describes the error. |
fatal | A flag specifying whether the error is fatal (i.e. an error) or non-fatal (i.e. just a warning). |
funcName | The name of the function in which the error was encountered (generally __func__ , __FUNCTION__ or similar). |
fileName | The name of the file in which the error was encountered (generally __FILE__ ). |
line | The line number at which the error was encountered (generally __LINE__ ). |
void BehaviourManager::step | ( | ) |
Function that should be called by the user to execute one step of the entire behaviour manager architecture.
This function is generally placed in a timed loop that controls the step rate of the architecture. This function does nothing if a fatal error has previously been encountered.
The order of execution is as follows:
preStepCallback()
ActuatorManager::updateActuators()
BehaviourLayer::update()
ActuatorManager::readExternalData()
BehaviourLayer::step()
:SensorManager::updateSensors()
ActuatorManager::updateActuators()
BehaviourLayer::update()
Behaviour::update()
Behaviour::computeActivationLevel()
Behaviour::getA()
)Behaviour::getA() > 0.0
then execute the activated behaviour: Behaviour::execute()
Behaviour::inhibited()
BehaviourLayer::postExecuteCallback()
SensorManager::updateSensors()
SensorManager::writeExternalData()
BehaviourLayer::postExecuteCallback()
postStepCallback()
std::string BehaviourManager::toString | ( | const std::string & | linePrefix = nullString | ) | const |
Generates a multiline string representation of the architecture, summarising all of the main components.
This function displays the whole object hierarchy of the given manager. A sample output is shown below.
Defined Behaviour Architecture ============================== The MyM behaviour manager contains: (0) RosIL (Interface) (1) MyL1 (0) MyB2 (1) MyB1 (2) MyL2 (0) MyB3 (1) MyB4 RosIL Layer =========== RosIL has a sensor manager with the following sensors: (0) MyL2/mode (1) MyL2/count (2) MyL2/target RosIL has an actuator manager with the following actuators: (0) ROS/mode (1) ROS/targetX (2) ROS/targetY MyL1 Layer ========== MyL1 has a sensor manager with the following sensors: (0) ROS/mode (1) ROS/targetX (2) ROS/targetY MyL1 has an actuator manager with the following actuators: (0) MyL1/mode (1) MyL1/xgoal (2) MyL1/vgoal MyL2 Layer ========== MyL2 has a sensor manager with the following sensors: (0) MyL1/mode (1) MyL1/xgoal (2) MyL1/vgoal MyL2 has an actuator manager with the following actuators: (0) MyL2/mode (1) MyL2/count (2) MyL2/target