StateBase Class Referenceabstract

This class is the implementation of the Slice Definition of a state. More...

#include <ArmarXCore/statechart/StateBase.h>

+ Inheritance diagram for StateBase:

Classes

struct  eUnexpectedEvent
 
struct  Impl
 

Public Types

enum  StatePhase {
  ePreDefined , eStatechartDefinitions , eSubstatesDefinitions , eParametersDefinitions ,
  eDefined , eEntering , eEntered , eBreaking ,
  eExiting , eExited
}
 enum that specifies the phase in which the state is currently in used to control the usage of state-functions in the correct context More...
 

Public Member Functions

void __checkPhase (const std::vector< StatePhase > &allowedTypes, const char *functionName) const
 
void __checkPhase (StatePhase allowedType, const char *functionName) const
 Helper function for checking if a function was called in valid position of the statechart.
 
void __checkPhaseMin (StatePhase allowedType, const char *functionName) const
 
void __copyDefaultValuesToInput ()
 
StringVariantContainerBaseMap __getSetInputAndLocalParameters () const
 Combines both maps to one map and returns a new map of only the set parameters.
 
virtual bool __hasActiveSubstate ()
 Virtual function to indicate wheter a state has an active substate or not. To be overridden by RemoteState to deligate the call to the real state.
 
virtual bool __hasSubstates ()
 Virtual function to indicate wheter a state has substates or not. To be overridden by RemoteState to deligate the call to the real state.
 
void __setParentState (StateBase *parentState)
 
void __throwUnknownParameter (const StateParameterMap &paramMap, const std::string &key) const
 
void __updateGlobalStateId ()
 
virtual void __updateGlobalStateIdRecursive ()
 
bool addParameter (StateParameterMap &paramMap, const std::string &key, VariantTypeId type, bool optional, VariantPtr defaultValue=VariantPtr()) const
 
bool addParameterContainer (StateParameterMap &paramMap, const std::string &key, const ContainerType &containerType, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr()) const
 
void clearSelfPointer ()
 
virtual StateBasePtr clone () const =0
 Pure virtual function to clone of the derived class type.
 
virtual StateBasePtr createEmptyCopy () const =0
 
virtual void deepCopy (const StateBase &sourceState, bool reset=true)
 Function to copy the states with all it substates and transitions.
 
virtual void defineParameters ()
 Virtual function, in which input/local/output parameters can be specified.
 
virtual void defineState ()
 Virtual function, in which this state can be configured.
 
virtual void defineSubstates ()
 Virtual function, in which substates, transition and mappings can be added.
 
StateBasePtr findSubstateByName (const std::string &substateName)
 Utility function to find a substate of this state by the name.
 
template<typename ContextType>
ContextType * getContext () const
 
StatechartContextInterface * getContext (bool checkNULL=true) const
 
std::string getGlobalHierarchyString () const
 
virtual StateParameterMap getInputParameters ()=0
 Not const because RemoteState implementation gets the current parameters via Ice and sets them.
 
std::string getLocalHierarchyString () const
 Function to get a string that contains als parent states and this state. (e.g. "Robot->Functional->Idling")
 
Ice::Int getLocalUniqueId () const
 
virtual StateParameterMap & getOutputParameters ()
 
void getParameter (const StateParameterMap &paramMap, const std::string &key, VariantPtr &value) const
 
void getParameterContainer (const StateParameterMap &paramMap, const std::string &key, VariantContainerBasePtr &valueContainer) const
 
const std::string & getStateClassName () const
 
std::string getStateName () const
 getStateName
 
StatePhase getStatePhase () const
 
EventPtr getTriggeredEndstateEvent () const
 This function returns the event that was triggered by entering an endstate.
 
void inheritInputParameters ()
 
bool init (StatechartContextInterface *context, StatechartManager *manager)
 Function to initialize this state. Must be called in the highest level of the hierarchy - and only there.
 
virtual bool isInitialized () const
 Returns the status of this state. Only if a state is initialized, it can be used.
 
bool isParameterSet (const StateParameterMap &paramMap, const std::string &key) const
 
virtual void onBreak ()
 Virtual function, in which the behaviour of state is defined, when it is abnormally exited. Can be overridden, but it is optional.
An abnormal exit only occurs in hierarchy-levels greater 1.
When a parent state is left before the substates are finished, the OnBreak()-function is called in the active substate and in all it's active substates.
If this function is not implemented, the normal OnExit()-function is called.

 
virtual void onEnter ()
 Virtual function, in which the behaviour of state is defined, when it is entered.
Can be overridden, but it is optional.
 
virtual void onExit ()
 Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden, but it is optional.
 
StateBase & operator= (const StateBase &source)
 
virtual void refetchSubstates ()
 This functions updates the substates.
 
void reset ()
 Function to reset the state: clear name, clear substatesList, clear transition etc.
 
virtual void run ()
 Virtual function, that can be reimplemented to calculate complex operations.
 
void setContext (StatechartContextInterface *context)
 
void setInitialized (bool enable)
 
void setParameter (StateParameterMap &paramMap, const std::string &key, const Variant &variant)
 
void setParameterContainer (StateParameterMap &paramMap, const std::string &key, const VariantContainerBase &valueContainer)
 
void setParameterContainer (StateParameterMap &paramMap, const std::string &key, const VariantContainerBasePtr &valueContainer)
 
void setStateClassName (std::string className)
 setStateClassName() sets the string, that contains a stringrepresentation of this class. Should not be called usually. The classname gets automatically set in the constructor of the derived class StateTemplate<T>.
 
void setStatePhase (StatePhase newPhase)
 
 StateBase ()
 
 StateBase (const StateBase &source)
 
virtual bool waitForInitialization (int timeoutMS=-1) const
 
 ~StateBase () override
 
- Public Member Functions inherited from Logging
SpamFilterDataPtr deactivateSpam (float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
 disables the logging for the current line for the given amount of seconds.
 
MessageTypeT getEffectiveLoggingLevel () const
 
 Logging ()
 
void setLocalMinimumLoggingLevel (MessageTypeT level)
 With setLocalMinimumLoggingLevel the minimum verbosity-level of log-messages can be set.
 
void setTag (const LogTag &tag)
 
void setTag (const std::string &tagName)
 
virtual ~Logging ()
 

Static Public Member Functions

static std::vector< StateBasePtr > GetActiveStateLeafs (StateBasePtr toplevelState)
 

Public Attributes

std::unique_ptr< Impl > impl
 

Additional Inherited Members

- Protected Member Functions inherited from Logging
bool checkLogLevel (MessageTypeT level) const
 
const LogSenderPtr & getLogSender () const
 Retrieve log sender.
 
LogSenderPtr loghelper (const char *file, int line, const char *function) const
 
- Protected Attributes inherited from Logging
MessageTypeT minimumLoggingLevel
 
SpamFilterDataPtr spamFilter
 
LogTag tag
 

Detailed Description

This class is the implementation of the Slice Definition of a state.

It is the baseclass for most statechart related classes. Basic functionality like data member handling is implemented here.

Member Enumeration Documentation

◆ StatePhase

enum StatePhase

enum that specifies the phase in which the state is currently in used to control the usage of state-functions in the correct context

Enumerator
ePreDefined 
eStatechartDefinitions 
eSubstatesDefinitions 
eParametersDefinitions 
eDefined 
eEntering 
eEntered 
eBreaking 
eExiting 
eExited 

Constructor & Destructor Documentation

◆ StateBase() [1/2]

StateBase ( )

◆ StateBase() [2/2]

StateBase ( const StateBase & source)

◆ ~StateBase()

~StateBase ( )
override

Member Function Documentation

◆ __checkPhase() [1/2]

void __checkPhase ( const std::vector< StatePhase > & allowedTypes,
const char * functionName ) const

◆ __checkPhase() [2/2]

void __checkPhase ( StateBase::StatePhase allowedType,
const char * functionName ) const

Helper function for checking if a function was called in valid position of the statechart.

Exceptions
LocalExceptionif allowedType does not match the current phase type

◆ __checkPhaseMin()

void __checkPhaseMin ( StateBase::StatePhase allowedType,
const char * functionName ) const

◆ __copyDefaultValuesToInput()

void __copyDefaultValuesToInput ( )

◆ __getSetInputAndLocalParameters()

StringVariantContainerBaseMap __getSetInputAndLocalParameters ( ) const

Combines both maps to one map and returns a new map of only the set parameters.

◆ __hasActiveSubstate()

bool __hasActiveSubstate ( )
virtual

Virtual function to indicate wheter a state has an active substate or not. To be overridden by RemoteState to deligate the call to the real state.

Reimplemented in RemoteState.

◆ __hasSubstates()

bool __hasSubstates ( )
virtual

Virtual function to indicate wheter a state has substates or not. To be overridden by RemoteState to deligate the call to the real state.

Reimplemented in RemoteState.

◆ __setParentState()

void __setParentState ( StateBase * parentState)

◆ __throwUnknownParameter()

void __throwUnknownParameter ( const StateParameterMap & paramMap,
const std::string & key ) const

◆ __updateGlobalStateId()

void __updateGlobalStateId ( )

◆ __updateGlobalStateIdRecursive()

void __updateGlobalStateIdRecursive ( )
virtual

Reimplemented in RemoteState.

◆ addParameter()

bool addParameter ( StateParameterMap & paramMap,
const std::string & key,
VariantTypeId type,
bool optional,
VariantPtr defaultValue = VariantPtr() ) const

◆ addParameterContainer()

bool addParameterContainer ( StateParameterMap & paramMap,
const std::string & key,
const ContainerType & containerType,
bool optional,
VariantContainerBasePtr defaultValue = VariantContainerBasePtr() ) const

◆ clearSelfPointer()

void clearSelfPointer ( )

◆ clone()

◆ createEmptyCopy()

virtual StateBasePtr createEmptyCopy ( ) const
pure virtual

◆ deepCopy()

void deepCopy ( const StateBase & sourceState,
bool reset = true )
virtual

Function to copy the states with all it substates and transitions.

Creates new copies of all substates and copies them as well.

◆ defineParameters()

◆ defineState()

virtual void defineState ( )
inlinevirtual

Virtual function, in which this state can be configured.

Function gets automatically called in init();

Reimplemented in Statechart_Robot, Statechart_StatechartPerfomanceTest, Statechart_StateParameterExample, StatechartClient, StatechartInstallConditionExample, StateRun, and TimeoutExampleStatechart.

◆ defineSubstates()

virtual void defineSubstates ( )
inlinevirtual

◆ findSubstateByName()

StateBasePtr findSubstateByName ( const std::string & substateName)

Utility function to find a substate of this state by the name.

If somehow multiple state with the same name exist, the first state is returned.

Parameters
substateName
Returns
Pointer to the requested state, or NULL if not found.

◆ GetActiveStateLeafs()

std::vector< StateBasePtr > GetActiveStateLeafs ( StateBasePtr toplevelState)
static

◆ getContext() [1/2]

template<typename ContextType>
ContextType * getContext ( ) const
inline

◆ getContext() [2/2]

StatechartContextInterface * getContext ( bool checkNULL = true) const

◆ getGlobalHierarchyString()

std::string getGlobalHierarchyString ( ) const

◆ getInputParameters()

virtual StateParameterMap getInputParameters ( )
pure virtual

Not const because RemoteState implementation gets the current parameters via Ice and sets them.

Implemented in RemoteState, and State.

◆ getLocalHierarchyString()

std::string getLocalHierarchyString ( ) const

Function to get a string that contains als parent states and this state. (e.g. "Robot->Functional->Idling")

◆ getLocalUniqueId()

Ice::Int getLocalUniqueId ( ) const

◆ getOutputParameters()

StateParameterMap & getOutputParameters ( )
virtual

Reimplemented in RemoteState, and State.

◆ getParameter()

void getParameter ( const StateParameterMap & paramMap,
const std::string & key,
VariantPtr & value ) const

◆ getParameterContainer()

void getParameterContainer ( const StateParameterMap & paramMap,
const std::string & key,
VariantContainerBasePtr & valueContainer ) const

◆ getStateClassName()

const std::string & getStateClassName ( ) const

◆ getStateName()

std::string getStateName ( ) const

getStateName

Returns

◆ getStatePhase()

StateBase::StatePhase getStatePhase ( ) const

◆ getTriggeredEndstateEvent()

EventPtr getTriggeredEndstateEvent ( ) const

This function returns the event that was triggered by entering an endstate.

This is useful in the onExit() function to determine which endstate of the substates was triggered.

Returns
Event that was triggered, NULL if no endstate was reached

◆ inheritInputParameters()

void inheritInputParameters ( )

◆ init()

bool init ( StatechartContextInterface * context,
StatechartManager * manager )

Function to initialize this state. Must be called in the highest level of the hierarchy - and only there.

◆ isInitialized()

bool isInitialized ( ) const
virtual

Returns the status of this state. Only if a state is initialized, it can be used.

Returns
Status of state.

Reimplemented in RemoteState.

◆ isParameterSet()

bool isParameterSet ( const StateParameterMap & paramMap,
const std::string & key ) const

◆ onBreak()

void onBreak ( )
virtual

Virtual function, in which the behaviour of state is defined, when it is abnormally exited. Can be overridden, but it is optional.
An abnormal exit only occurs in hierarchy-levels greater 1.
When a parent state is left before the substates are finished, the OnBreak()-function is called in the active substate and in all it's active substates.
If this function is not implemented, the normal OnExit()-function is called.

See also
onExit()

Reimplemented in MoveJointsPosControl, MoveJointsPosVelControl, MoveJointsVelControl, CheckForceTorqueSensors, CheckObjectInHand, CheckTactileSensors, DetectCollision, StateRun, and LookBetweenHandAndObject.

◆ onEnter()

◆ onExit()

◆ operator=()

StateBase & operator= ( const StateBase & source)

◆ refetchSubstates()

void refetchSubstates ( )
virtual

This functions updates the substates.

For local states only calls the substates refetch function, but for remoteStates requests the data via Ice.

Reimplemented in RemoteState.

◆ reset()

void reset ( )

Function to reset the state: clear name, clear substatesList, clear transition etc.

◆ run()

void run ( )
virtual

Virtual function, that can be reimplemented to calculate complex operations.

It runs in it's own thread.

This function is called after onEnter(). This function can continue to run even if the state has been left (onExit() has been called), but all calculations will be discarded (Output- and Localparameters will be reseted).
Calls to external components will still be executed!
Calls to sendEvent() will be ignored, after the state has been left.

Note
Before re-entering this state, the state waits for this function from the last state-visit to complete. The implementation of run should constantly check, if StateController::isRunningTaskStopped() returns true and exit the run-function in that case.

Reimplemented in MoveJointsPosControl, MoveJointsPosVelControl, CheckForceTorqueSensors, CheckObjectInHand, CheckTactileSensors, DetectCollision, CalculateJointAngleConfiguration, and RemoteStateOffererBase.

◆ setContext()

void setContext ( StatechartContextInterface * context)

◆ setInitialized()

void setInitialized ( bool enable)

◆ setParameter()

void setParameter ( StateParameterMap & paramMap,
const std::string & key,
const Variant & variant )

◆ setParameterContainer() [1/2]

void setParameterContainer ( StateParameterMap & paramMap,
const std::string & key,
const VariantContainerBase & valueContainer )

◆ setParameterContainer() [2/2]

void setParameterContainer ( StateParameterMap & paramMap,
const std::string & key,
const VariantContainerBasePtr & valueContainer )

◆ setStateClassName()

void setStateClassName ( std::string className)

setStateClassName() sets the string, that contains a stringrepresentation of this class. Should not be called usually. The classname gets automatically set in the constructor of the derived class StateTemplate<T>.

Parameters
classNameStringrepresentation of the classname (e.g. StateBase for this class)

◆ setStatePhase()

void setStatePhase ( StateBase::StatePhase newPhase)

◆ waitForInitialization()

bool waitForInitialization ( int timeoutMS = -1) const
virtual

Reimplemented in RemoteState.

Member Data Documentation

◆ impl

std::unique_ptr<Impl> impl

The documentation for this class was generated from the following files: