StateBase Class Referenceabstract

#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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual void defineParameters ()
 Virtual function, in which input/local/output parameters can be specified. More...
 
virtual void defineState ()
 Virtual function, in which this state can be configured. More...
 
virtual void defineSubstates ()
 Virtual function, in which substates, transition and mappings can be added. More...
 
StateBasePtr findSubstateByName (const std::string &substateName)
 Utility function to find a substate of this state by the name. More...
 
template<typename ContextType >
ContextType * getContext () const
 
StatechartContextInterfacegetContext (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. More...
 
std::string getLocalHierarchyString () const
 Function to get a string that contains als parent states and this state. (e.g. "Robot->Functional->Idling") More...
 
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 More...
 
StatePhase getStatePhase () const
 
EventPtr getTriggeredEndstateEvent () const
 This function returns the event that was triggered by entering an endstate. More...
 
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. More...
 
virtual bool isInitialized () const
 Returns the status of this state. Only if a state is initialized, it can be used. More...
 
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.
More...
 
virtual void onEnter ()
 Virtual function, in which the behaviour of state is defined, when it is entered.
Can be overridden, but it is optional. More...
 
virtual void onExit ()
 Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden, but it is optional. More...
 
StateBaseoperator= (const StateBase &source)
 
virtual void refetchSubstates ()
 This functions updates the substates. More...
 
void reset ()
 Function to reset the state: clear name, clear substatesList, clear transition etc. More...
 
virtual void run ()
 Virtual function, that can be reimplemented to calculate complex operations. More...
 
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>. More...
 
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. More...
 
MessageTypeT getEffectiveLoggingLevel () const
 
 Logging ()
 
void setLocalMinimumLoggingLevel (MessageTypeT level)
 With setLocalMinimumLoggingLevel the minimum verbosity-level of log-messages can be set. More...
 
void setTag (const LogTag &tag)
 
void setTag (const std::string &tagName)
 
virtual ~Logging ()
 

Static Public Member Functions

static std::vector< StateBasePtrGetActiveStateLeafs (StateBasePtr toplevelState)
 

Public Attributes

std::unique_ptr< Implimpl
 

Additional Inherited Members

- Protected Member Functions inherited from Logging
bool checkLogLevel (MessageTypeT level) const
 
const LogSenderPtrgetLogSender () const
 Retrieve log sender. More...
 
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.

Definition at line 59 of file StateBase.h.

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 

Definition at line 295 of file StateBase.h.

Constructor & Destructor Documentation

◆ StateBase() [1/2]

StateBase ( )

Definition at line 52 of file StateBase.cpp.

+ Here is the call graph for this function:

◆ StateBase() [2/2]

StateBase ( const StateBase source)

Definition at line 70 of file StateBase.cpp.

+ Here is the call graph for this function:

◆ ~StateBase()

~StateBase ( )
override

Definition at line 104 of file StateBase.cpp.

Member Function Documentation

◆ __checkPhase() [1/2]

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

Definition at line 175 of file StateBase.cpp.

+ Here is the call graph for this function:

◆ __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

Definition at line 136 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __checkPhaseMin()

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

Definition at line 230 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __copyDefaultValuesToInput()

void __copyDefaultValuesToInput ( )

Definition at line 846 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ __getSetInputAndLocalParameters()

StringVariantContainerBaseMap __getSetInputAndLocalParameters ( ) const

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

Definition at line 940 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __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.

Definition at line 311 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ __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.

Definition at line 300 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ __setParentState()

void __setParentState ( StateBase parentState)

Definition at line 252 of file StateBase.cpp.

+ Here is the call graph for this function:

◆ __throwUnknownParameter()

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

Definition at line 803 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __updateGlobalStateId()

void __updateGlobalStateId ( )

Definition at line 259 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __updateGlobalStateIdRecursive()

void __updateGlobalStateIdRecursive ( )
virtual

Reimplemented in RemoteState.

Definition at line 281 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addParameter()

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

Definition at line 615 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addParameterContainer()

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

Definition at line 639 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearSelfPointer()

void clearSelfPointer ( )

Definition at line 243 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ clone()

virtual StateBasePtr clone ( ) const
pure virtual

Pure virtual function to clone of the derived class type.

Implemented function should create a new instance with new and return the StateBasePtr. The new instance should contain a reseted, but initialized version of the original.

Implemented in State, NoUserCodeState, RemoteState, DynamicRemoteState, and RemoteStateWrapper.

◆ 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.

Definition at line 324 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ defineParameters()

virtual void defineParameters ( )
inlinevirtual

Virtual function, in which input/local/output parameters can be specified.

Reimplemented in XMLState, and DynamicRemoteState.

Definition at line 186 of file StateBase.h.

+ Here is the caller graph for this function:

◆ defineState()

virtual void defineState ( )
inlinevirtual

Virtual function, in which this state can be configured.

Function gets automatically called in init();

Definition at line 168 of file StateBase.h.

+ Here is the caller graph for this function:

◆ defineSubstates()

virtual void defineSubstates ( )
inlinevirtual

Virtual function, in which substates, transition and mappings can be added.

Reimplemented in XMLState.

Definition at line 177 of file StateBase.h.

+ Here is the caller graph for this function:

◆ 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.

Definition at line 862 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ GetActiveStateLeafs()

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

Definition at line 950 of file StateBase.cpp.

◆ getContext() [1/2]

ContextType* getContext ( ) const
inline

Definition at line 71 of file StateBase.h.

◆ getContext() [2/2]

StatechartContextInterface * getContext ( bool  checkNULL = true) const

Definition at line 499 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ getGlobalHierarchyString()

std::string getGlobalHierarchyString ( ) const

Definition at line 580 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ getInputParameters()

virtual StateParameterMap getInputParameters ( )
pure virtual

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

Implemented in State, and RemoteState.

◆ getLocalHierarchyString()

std::string getLocalHierarchyString ( ) const

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

Definition at line 563 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ getLocalUniqueId()

Ice::Int getLocalUniqueId ( ) const

Definition at line 551 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ getOutputParameters()

StateParameterMap & getOutputParameters ( )
virtual

Reimplemented in RemoteState, and State.

Definition at line 539 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ getParameter()

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

Definition at line 876 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParameterContainer()

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

Definition at line 768 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStateClassName()

const std::string & getStateClassName ( ) const

Definition at line 557 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ getStateName()

std::string getStateName ( ) const

getStateName

Returns

Definition at line 545 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ getStatePhase()

StateBase::StatePhase getStatePhase ( ) const

Definition at line 926 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ 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

Definition at line 920 of file StateBase.cpp.

◆ inheritInputParameters()

void inheritInputParameters ( )

Definition at line 821 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Definition at line 441 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Definition at line 608 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ isParameterSet()

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

Definition at line 789 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ 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 CheckObjectInHand, MoveJointsVelControl, MoveJointsPosControl, MoveJointsPosVelControl, LookBetweenHandAndObject, CheckForceTorqueSensors, CheckTactileSensors, and DetectCollision.

Definition at line 510 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onEnter()

void onEnter ( )
virtual

Virtual function, in which the behaviour of state is defined, when it is entered.
Can be overridden, but it is optional.

Reimplemented in ControlModeChooser, CalcVelocities, InstallTerminateConditions, WaitForUpdates, VisualServoWrapper, CloseHandWithJointAngles, CloseHandWithTorques, MoveJointsVelControl, SelectObject, CheckObjectInHand, Preshape, LiftObject, LocalizeObject, VisualServoObject, GraspingWithTorques, ValidateTcpPose, FindAndGraspObject, MoveJointsPosControl, MoveJointsPosVelControl, VisualServo, LookBetweenHandAndObject, CheckForceTorqueSensors, CheckTactileSensors, and DetectCollision.

Definition at line 516 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ onExit()

void onExit ( )
virtual

Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden, but it is optional.

See also
onBreak()

Reimplemented in CalcVelocities, CheckObjectInHand, InstallTerminateConditions, MoveJointsVelControl, WaitForUpdates, VisualServoWrapper, CloseHandWithJointAngles, CloseHandWithTorques, SelectObject, Preshape, LiftObject, MoveJointsPosControl, MoveJointsPosVelControl, LocalizeObject, VisualServoObject, GraspingWithTorques, LookBetweenHandAndObject, FindAndGraspObject, VisualServo, CheckForceTorqueSensors, CheckTactileSensors, and DetectCollision.

Definition at line 528 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ operator=()

StateBase & operator= ( const StateBase source)

Definition at line 97 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Definition at line 910 of file StateBase.cpp.

+ Here is the call graph for this function:

◆ reset()

void reset ( )

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

Definition at line 971 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ 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 RemoteStateOffererBase, CheckObjectInHand, CalculateJointAngleConfiguration, MoveJointsPosControl, MoveJointsPosVelControl, CheckForceTorqueSensors, CheckTactileSensors, and DetectCollision.

Definition at line 521 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ setContext()

void setContext ( StatechartContextInterface context)

Definition at line 533 of file StateBase.cpp.

◆ setInitialized()

void setInitialized ( bool  enable)

Definition at line 292 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ setParameter()

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

Definition at line 704 of file StateBase.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setParameterContainer() [1/2]

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

Definition at line 737 of file StateBase.cpp.

+ Here is the call graph for this function:

◆ setParameterContainer() [2/2]

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

Definition at line 729 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ 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)

Definition at line 903 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ setStatePhase()

void setStatePhase ( StateBase::StatePhase  newPhase)

Definition at line 933 of file StateBase.cpp.

+ Here is the caller graph for this function:

◆ waitForInitialization()

bool waitForInitialization ( int  timeoutMS = -1) const
virtual

Reimplemented in RemoteState.

Definition at line 586 of file StateBase.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ impl

std::unique_ptr<Impl> impl

Definition at line 288 of file StateBase.h.


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