![]() |
NimbRo ROS Soccer Package
|
Base class for all state controllers. More...
#include <state_controller.h>
Inherited by sitting_demo::SittingDemoSC, standing_demo::StandingDemoSC, and statecontrollertest::DemoSC.
Public Member Functions | |
StateController (const std::string &name) | |
Default constructor. | |
virtual | ~StateController () |
Destructor. | |
action_t | goToState (StatePtr state) |
Transition to the specified next state (for callback) More... | |
action_t | terminate () |
Terminate the execution of the state controller (for callback) More... | |
bool | belongsToMe (StateConstPtr state) const |
Check whether a state is owned by the calling state controller. | |
bool | isActive () const |
Return whether the state controller is active or not. | |
cycle_t | getCycle () const |
Return the current cycle count (zero after reset) | |
StateConstPtr | getCurState () const |
Return a constant reference to the current state. | |
ret_t | init (StatePtr state) |
Reset and initialise the state controller with a particular state (callback-protected) More... | |
ret_t | forceState (StatePtr state) |
Force a change of state of the state controller (callback-protected) More... | |
ret_t | step () |
Execute a single step of the state controller (callback-protected) More... | |
ret_t | loop () |
Execute state controller steps until either an error or clean termination occurs (callback-protected) More... | |
Public Attributes | |
const std::string | name |
The human-friendly name of the state controller. | |
Protected Member Functions | |
virtual bool | preStepCallback () |
A callback that is executed at the very beginning of the step() function, right after the cycle count is incremented, whenever the current state is not null. More... | |
virtual void | preActivateCallback (bool willCallActivate) |
A callback that is executed in the step() function immediately prior to the activation of a state (called with willCallActivate true if there is a new state to activate) | |
virtual void | preExecuteCallback () |
A callback that is executed in the step() function immediately prior to the execution of the current state (called without exception whenever there is a state to be executed) | |
virtual bool | postExecuteCallback () |
A callback that is executed in the step() function immediately after the execution of the current state (called without exception whenever there is a state that was just executed) More... | |
virtual void | onTerminateCallback () |
A callback that is executed in the step() function (before the resources are freed) when a state controller termination condition is encountered. | |
virtual void | postStepCallback () |
A callback that is executed at the very end of the step() function whenever the current state is not null (in particular, it is NOT called after onTerminateCallback() in the case of a termination condition, as termination resets the current state) | |
Friends | |
class | State |
Base class for all state controllers.
All state controllers implemented using this library need to derive from this abstract base class, which provides the underlying functionality.
Force a change of state of the state controller (callback-protected)
In current implementation, the only difference between the forceState()
and init()
functions is that forceState()
leaves the internal cycle count of the state controller untouched. In particular, the current state queue is cleared, and all contained states are deactivated, including the current state.
This function should almost never be required. Perform all state and queue changes within the states as a general rule - only call forceState()
if special circumstances mandate an external invasion on the state of the state controller. Use this function with care!
state | The state to transition the state controller into. |
ret_t
return ID specifying whether the function was successful and performed the required action. Calling this function from a callback (SCR_BAD_CALLBACK
), passing a null state (SCR_NULL_STATE
), and/or passing a state that belongs to another state controller (SCR_NOT_MY_STATE
) results in return values other than SCR_OK
. Transition to the specified next state (for callback)
The transition itself occurs in the next step. This function sets state
as the next and only element in the state queue. If state
is null then this function is equivalent to calling terminate()
. This function ignores calls that do not originate from a state callback.
state | An class instance of the new state to enter. |
PROCEED_NEXT_STATE
so that the following usage has the desired effect. Reset and initialise the state controller with a particular state (callback-protected)
The init()
function can be called at any time and be guaranteed to bring the state controller to a well-defined initial state, while releasing all the states and resources that it owned. It is recommended to always use this function with an inline NewStateInstance
call, as opposed to creating a state, assigning it to a variable in the calling function and then passing this variable as the argument to the init()
function. For example:
state | The state instance to initialise the state controller with. |
ret_t
return ID specifying whether the function was successful and performed the required action. Calling this function from a callback (SCR_BAD_CALLBACK
), passing a null state (SCR_NULL_STATE
), and/or passing a state that belongs to another state controller (SCR_NOT_MY_STATE
) results in return values other than SCR_OK
. ret_t StateController::loop | ( | ) |
Execute state controller steps until either an error or clean termination occurs (callback-protected)
ret_t
return ID indicating the success of the function. If the state controller terminated cleanly then the function returns SCR_OK
. Otherwise, this function echos the return code received from the offending internal call to step()
. For more information refer to the statecontroller::SCReturnID
enumeration.
|
inlineprotectedvirtual |
A callback that is executed in the step()
function immediately after the execution of the current state (called without exception whenever there is a state that was just executed)
true
if you want to force a state transition to the state at the head of the queue (which you can modify using the goToState()
function for example), otherwise return false
.
|
inlineprotectedvirtual |
A callback that is executed at the very beginning of the step()
function, right after the cycle count is incremented, whenever the current state is not null.
true
if you want to force a state transition to the state at the head of the queue (which you can modify using the goToState()
function for example), otherwise return false
. ret_t StateController::step | ( | ) |
Execute a single step of the state controller (callback-protected)
ret_t
return ID indicating the success of the function and/or the resulting state of the state controller (refer to the statecontroller::SCReturnID
enumeration). action_t StateController::terminate | ( | ) |
Terminate the execution of the state controller (for callback)
Termination occurs in the calling step, and irrespective of the state of the queue and the action that is possibly subsequently returned from the execute()
callback. This function only has an effect when used from within either the activate()
or execute()
callbacks of a state.
PROCEED_NEXT_STATE
so that the following usage has the desired effect.