Orocos Real-Time Toolkit  2.9.0
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
RTT::scripting::StateMachine Class Reference

A hierarchical StateMachine which is loaded in the Program Processor. More...

#include <rtt/scripting/StateMachine.hpp>

Inheritance diagram for RTT::scripting::StateMachine:
RTT::base::ExecutableInterface RTT::scripting::ParsedStateMachine

Classes

struct  Status
 Enumerates all possible state machine statuses. More...
 

Public Types

typedef std::vector< StateMachinePtrChildList
 

Public Member Functions

virtual ~StateMachine ()
 The destructor is virtual since ParsedStateMachine still inherits this class. More...
 
 StateMachine (StateMachinePtr parent, const std::string &name="Default")
 Create a new StateMachine with an optional parent. More...
 
void trace (bool on_off)
 Turn log(Debug) messages on or off to track state transitions. More...
 
bool requestState (const std::string &statename)
 Request a transition to a given state. More...
 
bool inState (const std::string &state) const
 Check if the state machine is in a given state. More...
 
bool inStrictState (const std::string &state) const
 Check if the state machine is in a given state and not in the entry or exit program. More...
 
const std::string & getCurrentStateName () const
 Return name of current state, empty string if not active. More...
 
bool isStrictlyActive () const
 Strictly active, means active and not in a transition. More...
 
bool inInitialState () const
 Inspect if we are in the initial state. More...
 
bool inFinalState () const
 Inspect if we are in the final state. More...
 
bool stepDone () const
 When isPaused(), return true if no step is pending, when isReactive(), return isStrictlyActive() More...
 
bool isActive () const
 Returns true if the state machine is activated. More...
 
bool isStopped () const
 Returns true if the state machine is in the final state, after a stop() directive. More...
 
bool inError () const
 Get the error status of this StateMachine. More...
 
bool isReactive () const
 Query if the state machine is currently reacting only to events. More...
 
bool isAutomatic () const
 Query if the state machine is reacting to events and evaluating transition conditions. More...
 
bool isPaused () const
 Query if the state machine is paused. More...
 
bool activate ()
 Start this StateMachine. More...
 
bool pause ()
 Pause the state machine. More...
 
bool step ()
 Execute a single action if the state machine is paused or evaluate the transition conditions if the state machine is reactive. More...
 
bool automatic ()
 Enter automatic mode: evaluating the transition conditions continuously. More...
 
bool start ()
 Enter automatic mode: evaluating the transition conditions continuously. More...
 
bool stop ()
 Bring the state machine to the safe final state and wait for events or requests. More...
 
bool reset ()
 Reset the state machine from the final state to the initial state and wait for events or requests. More...
 
bool reactive ()
 Switch to reactive mode from automatic mode. More...
 
bool deactivate ()
 Stop this StateMachine. More...
 
bool execute ()
 Used by the StateMachineProcessor to execute the next action(s) or state transitions. More...
 
void loading ()
 Informs this object that it got loaded in an ExecutionEngine. More...
 
void unloading ()
 Informs this object that it got unloaded from an ExecutionEngine. More...
 
StateInterfacerequestNextState (bool stepping=false)
 Search from the current state a candidate next state. More...
 
StateInterfacerequestNextStateStep ()
 Go stepwise through evaluations to find out next state. More...
 
bool requestFinalState ()
 Request going to the Final State. More...
 
bool requestInitialState ()
 Request going to the Initial State. More...
 
StateInterfacenextState ()
 Search from the current state a candidate next state. More...
 
std::vector< std::string > getStateList () const
 Get a list of the names of all the present states. More...
 
StateInterfacegetState (const std::string &name) const
 Lookup a State by name. More...
 
Status::StateMachineStatus getStatus () const
 Get the status of this state machine. More...
 
std::string getStatusStr () const
 Get the status in a readable string format. More...
 
void addState (StateInterface *s)
 Add a State. More...
 
bool requestStateChange (StateInterface *s_n)
 Request a state transition to a new state. More...
 
bool executePending (bool stepping=false)
 Execute any pending State (exit, entry, handle) programs. More...
 
void preconditionSet (StateInterface *state, ConditionInterface *cnd, int line)
 Express a precondition for entering a state. More...
 
void transitionSet (StateInterface *from, StateInterface *to, ConditionInterface *cnd, int priority, int line)
 Express a possible transition from one state to another under a certain condition. More...
 
void transitionSet (StateInterface *from, StateInterface *to, ConditionInterface *cnd, boost::shared_ptr< ProgramInterface > transprog, int priority, int line)
 Express a possible transition from one state to another under a certain condition. More...
 
bool createEventTransition (ServicePtr sp, ExecutionEngine *target_engine, const std::string &ename, std::vector< base::DataSourceBase::shared_ptr > args, StateInterface *from, StateInterface *to, ConditionInterface *guard, boost::shared_ptr< ProgramInterface > transprog, StateInterface *elseto=0, boost::shared_ptr< ProgramInterface > elseprog=boost::shared_ptr< ProgramInterface >())
 Express a possible transition from one state to another when an Event is fired under a certain condition (guard). More...
 
void setInitialState (StateInterface *s)
 Set the initial state of this StateMachine. More...
 
void setFinalState (StateInterface *s)
 Set the final state of this StateMachine. More...
 
StateInterfacecurrentState () const
 Retrieve the current state of the state machine. More...
 
ProgramInterfacecurrentProgram () const
 Retrieve the current program in execution. More...
 
StateInterfacegetInitialState () const
 Retrieve the initial state of the state machine. More...
 
StateInterfacegetFinalState () const
 Retrieve the final state of the state machine. More...
 
void setInitCommand (base::ActionInterface *c)
 This was added for extra (non-user visible) initialisation when the StateMachine is activated. More...
 
base::ActionInterfacegetInitCommand () const
 
StateMachinePtr getParent () const
 Get the parent, returns zero if no parent. More...
 
void setParent (StateMachinePtr parent)
 
const ChildListgetChildren () const
 Get a list of all child state machines. More...
 
void addChild (StateMachinePtr child)
 
const std::string & getName () const
 This method must be overloaded to get a useful hierarchy. More...
 
int getLineNumber () const
 Returns the current program line in execution,. More...
 
virtual std::string getText () const
 Return the text to which getLineNumber() refers. More...
 
bool inTransition () const
 Inspect if the StateMachine is performing a state transition. More...
 
bool interruptible () const
 Inspect if the StateMachine is interruptible by events. More...
 
void loaded (ExecutionEngine *ee)
 Called by the ExecutionEngine ee or before synchronous execution to tell this object it is being loaded. More...
 
void unloaded ()
 Called by the ExecutionEngine ee or after synchronous execution to tell this object it is being unloaded. More...
 
bool isLoaded ()
 Returns true if this object is loaded in an ExecutionEngine. More...
 
ExecutionEnginegetEngine ()
 Returns the ExecutionEngine this object is loaded into or null otherwise. More...
 

Protected Types

typedef std::vector< boost::tuple< ConditionInterface *, StateInterface *, int, int, boost::shared_ptr< ProgramInterface > > > TransList
 The key is the current state, the value is the transition condition to another state with a certain priority (int), on a line (int), with a transition program. More...
 
typedef std::map< StateInterface *, TransListTransitionMap
 
typedef std::multimap< StateInterface *, std::pair< ConditionInterface *, int > > PreConditionMap
 
typedef std::vector< boost::tuple< ServicePtr, std::string, std::vector< base::DataSourceBase::shared_ptr >, StateInterface *, ConditionInterface *, boost::shared_ptr< ProgramInterface >, Handle, StateInterface *, boost::shared_ptr< ProgramInterface > > > EventList
 
typedef std::map< StateInterface *, EventListEventMap
 
typedef boost::weak_ptr< StateMachineStateMachineParentPtr
 

Protected Member Functions

void changeState (StateInterface *s, ProgramInterface *tprog, bool stepping=false)
 
void leaveState (StateInterface *s)
 
void enterState (StateInterface *s)
 
void runState (StateInterface *s)
 
void handleState (StateInterface *s)
 
bool executeProgram (ProgramInterface *&cp, bool stepping)
 
int checkConditions (StateInterface *state, bool stepping=false)
 
void enableGlobalEvents ()
 
void disableGlobalEvents ()
 
void enableEvents (StateInterface *s)
 
void disableEvents (StateInterface *s)
 

Protected Attributes

std::vector< StateMachinePtr_children
 
StateMachineParentPtr _parent
 
std::string _name
 
Status::StateMachineStatus smStatus
 
TransitionMap stateMap
 A map keeping track of all States and conditional transitions between two states. More...
 
PreConditionMap precondMap
 A map keeping track of all preconditions of a state. More...
 
EventMap eventMap
 A map keeping track of all events of a state. More...
 
ExecutionEngineengine
 

Detailed Description

A hierarchical StateMachine which is loaded in the Program Processor.

A StateMachine can have children and one parent.

Todo:
Implement the whole transition mechanism with the Strategy software pattern to allow cleaner implementation.

Definition at line 72 of file StateMachine.hpp.

Member Typedef Documentation

Definition at line 109 of file StateMachine.hpp.

typedef std::vector< boost::tuple<ServicePtr, std::string, std::vector<base::DataSourceBase::shared_ptr>, StateInterface*, ConditionInterface*, boost::shared_ptr<ProgramInterface>, Handle, StateInterface*, boost::shared_ptr<ProgramInterface> > > RTT::scripting::StateMachine::EventList
protected

Definition at line 98 of file StateMachine.hpp.

Definition at line 99 of file StateMachine.hpp.

typedef std::multimap< StateInterface*, std::pair<ConditionInterface*, int> > RTT::scripting::StateMachine::PreConditionMap
protected

Definition at line 92 of file StateMachine.hpp.

Definition at line 101 of file StateMachine.hpp.

Definition at line 91 of file StateMachine.hpp.

typedef std::vector< boost::tuple<ConditionInterface*, StateInterface*, int, int, boost::shared_ptr<ProgramInterface> > > RTT::scripting::StateMachine::TransList
protected

The key is the current state, the value is the transition condition to another state with a certain priority (int), on a line (int), with a transition program.

Definition at line 90 of file StateMachine.hpp.

Constructor & Destructor Documentation

RTT::StateMachine::~StateMachine ( )
virtual

The destructor is virtual since ParsedStateMachine still inherits this class.

Definition at line 75 of file StateMachine.cpp.

References _name, RTT::base::ExecutableInterface::getEngine(), RTT::base::ExecutableInterface::isLoaded(), RTT::ExecutionEngine::removeFunction(), and TRACE.

RTT::StateMachine::StateMachine ( StateMachinePtr  parent,
const std::string &  name = "Default" 
)

Create a new StateMachine with an optional parent.

Set parent to zero for the top state machine. The initial Status of a StateMachine is always inactive.

Definition at line 66 of file StateMachine.cpp.

References addState().

Member Function Documentation

bool RTT::StateMachine::activate ( )
void RTT::scripting::StateMachine::addChild ( StateMachinePtr  child)
inline

Definition at line 564 of file StateMachine.hpp.

Referenced by RTT::scripting::ParsedStateMachine::copy().

void RTT::StateMachine::addState ( StateInterface s)

Add a State.

If already present, changes nothing.

Definition at line 769 of file StateMachine.cpp.

References stateMap.

Referenced by StateMachine().

bool RTT::StateMachine::automatic ( )
void RTT::StateMachine::changeState ( StateInterface s,
ProgramInterface tprog,
bool  stepping = false 
)
protected
int RTT::StateMachine::checkConditions ( StateInterface state,
bool  stepping = false 
)
protected
bool RTT::StateMachine::createEventTransition ( ServicePtr  sp,
ExecutionEngine target_engine,
const std::string &  ename,
std::vector< base::DataSourceBase::shared_ptr args,
StateInterface from,
StateInterface to,
ConditionInterface guard,
boost::shared_ptr< ProgramInterface transprog,
StateInterface elseto = 0,
boost::shared_ptr< ProgramInterface elseprog = boost::shared_ptr<ProgramInterface>() 
)

Express a possible transition from one state to another when an Event is fired under a certain condition (guard).

Parameters
enameThe name of the Event under which a transition should be made
argsThe arguments which the event handler must set upon occurence.
fromThe state which should be left
toThe state which should be entered
guardThe Condition under which the transition may succeed
transprogThe program to be executed between exit of from and entry of to.
spThe Service in which ename can be found.
target_engineThe ExecutionEngine which will execute this StateMachine.

Definition at line 500 of file StateMachine.cpp.

References changeState(), checkConditions(), RTT::Debug, RTT::Logger::endl(), RTT::Logger::Error, RTT::Error, RTT::scripting::ConditionInterface::evaluate(), eventMap, RTT::base::RunnableInterface::getActivity(), RTT::base::ExecutableInterface::getEngine(), RTT::scripting::StateInterface::getName(), inTransition(), RTT::Logger::log(), stateMap, RTT::base::ActivityInterface::timeout(), and TRACE.

ProgramInterface * RTT::StateMachine::currentProgram ( ) const

Retrieve the current program in execution.

Returns null if the StateMachine is not active or no programs are being run.

Definition at line 922 of file StateMachine.cpp.

StateInterface * RTT::StateMachine::currentState ( ) const

Retrieve the current state of the state machine.

Returns null if the StateMachine is not active.

Definition at line 917 of file StateMachine.cpp.

Referenced by RTT::scripting::ParsedStateMachine::inState(), and unloading().

bool RTT::StateMachine::deactivate ( )
void RTT::StateMachine::disableEvents ( StateInterface s)
protected

Definition at line 484 of file StateMachine.cpp.

References eventMap.

Referenced by changeState(), deactivate(), and disableGlobalEvents().

void RTT::StateMachine::disableGlobalEvents ( )
protected

Definition at line 466 of file StateMachine.cpp.

References disableEvents().

Referenced by deactivate().

void RTT::StateMachine::enableEvents ( StateInterface s)
protected

Definition at line 470 of file StateMachine.cpp.

References eventMap.

Referenced by activate(), enableGlobalEvents(), and executePending().

void RTT::StateMachine::enableGlobalEvents ( )
protected

Definition at line 462 of file StateMachine.cpp.

References enableEvents().

Referenced by activate().

void RTT::StateMachine::enterState ( StateInterface s)
protected
bool RTT::StateMachine::execute ( )
virtual
bool RTT::StateMachine::executePending ( bool  stepping = false)

Execute any pending State (exit, entry, handle) programs.

You must executePending, before calling requestState() or requestNextState(). You should only call requestState() or requestNextState() if executePending returns true.

Due to the pending requests, the currentState() may have changed.

Parameters
steppingprovide true if the pending programs should be executed one step at a time.
Return values
trueif nothing was pending
falseif there was some program executing.

Definition at line 979 of file StateMachine.cpp.

References enableEvents(), enterState(), executeProgram(), RTT::scripting::StateInterface::getName(), inError(), stateMap, and TRACE.

Referenced by activate(), deactivate(), execute(), and requestStateChange().

bool RTT::StateMachine::executeProgram ( ProgramInterface *&  cp,
bool  stepping 
)
protected
const ChildList& RTT::scripting::StateMachine::getChildren ( ) const
inline

Get a list of all child state machines.

Definition at line 559 of file StateMachine.hpp.

Referenced by RTT::scripting::ParsedStateMachine::setName().

const std::string& RTT::scripting::StateMachine::getCurrentStateName ( ) const
inline

Return name of current state, empty string if not active.

Definition at line 164 of file StateMachine.hpp.

References RTT::scripting::StateInterface::getName().

ExecutionEngine* RTT::base::ExecutableInterface::getEngine ( )
inlineinherited

Returns the ExecutionEngine this object is loaded into or null otherwise.

Returns

Definition at line 117 of file ExecutableInterface.hpp.

Referenced by createEventTransition(), loading(), RTT::scripting::FunctionGraph::~FunctionGraph(), and ~StateMachine().

StateInterface* RTT::scripting::StateMachine::getFinalState ( ) const
inline

Retrieve the final state of the state machine.

Definition at line 522 of file StateMachine.hpp.

Referenced by unloading().

base::ActionInterface* RTT::scripting::StateMachine::getInitCommand ( ) const
inline

Definition at line 538 of file StateMachine.hpp.

StateInterface* RTT::scripting::StateMachine::getInitialState ( ) const
inline

Retrieve the initial state of the state machine.

Definition at line 515 of file StateMachine.hpp.

Referenced by activate().

int RTT::StateMachine::getLineNumber ( ) const

Returns the current program line in execution,.

Returns
1 if not active

Definition at line 861 of file StateMachine.cpp.

References RTT::scripting::StateInterface::getEntryPoint(), and RTT::scripting::ProgramInterface::getLineNumber().

Referenced by executeProgram(), and unloading().

const std::string& RTT::scripting::StateMachine::getName ( ) const
inline

This method must be overloaded to get a useful hierarchy.

Definition at line 572 of file StateMachine.hpp.

Referenced by RTT::scripting::StateGraphParser::storeOffset(), and unloading().

StateMachinePtr RTT::scripting::StateMachine::getParent ( ) const
inline

Get the parent, returns zero if no parent.

Definition at line 546 of file StateMachine.hpp.

StateInterface * RTT::StateMachine::getState ( const std::string &  name) const

Lookup a State by name.

Returns null if not found.

Definition at line 775 of file StateMachine.cpp.

References stateMap.

std::vector< std::string > RTT::StateMachine::getStateList ( ) const

Get a list of the names of all the present states.

Definition at line 759 of file StateMachine.cpp.

References RTT::scripting::StateInterface::getName(), and stateMap.

StateMachine::Status::StateMachineStatus RTT::StateMachine::getStatus ( ) const

Get the status of this state machine.

Definition at line 124 of file StateMachine.cpp.

References smStatus.

string RTT::StateMachine::getStatusStr ( ) const
string RTT::StateMachine::getText ( ) const
virtual

Return the text to which getLineNumber() refers.

Reimplemented in RTT::scripting::ParsedStateMachine.

Definition at line 878 of file StateMachine.cpp.

void RTT::StateMachine::handleState ( StateInterface s)
protected
bool RTT::scripting::StateMachine::inError ( ) const
inline

Get the error status of this StateMachine.

Definition at line 216 of file StateMachine.hpp.

Referenced by activate(), executePending(), and requestFinalState().

bool RTT::scripting::StateMachine::inFinalState ( ) const
inline

Inspect if we are in the final state.

Definition at line 188 of file StateMachine.hpp.

bool RTT::scripting::StateMachine::inInitialState ( ) const
inline

Inspect if we are in the initial state.

Definition at line 181 of file StateMachine.hpp.

bool RTT::scripting::StateMachine::inState ( const std::string &  state) const
inline

Check if the state machine is in a given state.

Definition at line 143 of file StateMachine.hpp.

References RTT::scripting::StateInterface::getName().

bool RTT::scripting::StateMachine::inStrictState ( const std::string &  state) const
inline

Check if the state machine is in a given state and not in the entry or exit program.

Definition at line 154 of file StateMachine.hpp.

References RTT::scripting::StateInterface::getName().

bool RTT::StateMachine::interruptible ( ) const

Inspect if the StateMachine is interruptible by events.

Only the run program may be interrupted, or if no program is currently executed.

Definition at line 1140 of file StateMachine.cpp.

Referenced by requestFinalState(), requestInitialState(), requestNextState(), and requestStateChange().

bool RTT::StateMachine::inTransition ( ) const

Inspect if the StateMachine is performing a state transition.

A transition is in progress if entry, transition or exit programs are executed.

Returns
true if it is executing a program (except run or handle program), false if it is not executing a program OR executing the run/handle program.

Definition at line 1135 of file StateMachine.cpp.

Referenced by createEventTransition(), and execute().

bool RTT::scripting::StateMachine::isActive ( ) const
inline

Returns true if the state machine is activated.

Definition at line 205 of file StateMachine.hpp.

Referenced by unloading().

bool RTT::scripting::StateMachine::isAutomatic ( ) const
inline

Query if the state machine is reacting to events and evaluating transition conditions.

Definition at line 227 of file StateMachine.hpp.

Referenced by unloading().

bool RTT::base::ExecutableInterface::isLoaded ( )
inlineinherited
bool RTT::scripting::StateMachine::isPaused ( ) const
inline

Query if the state machine is paused.

Definition at line 232 of file StateMachine.hpp.

bool RTT::scripting::StateMachine::isReactive ( ) const
inline

Query if the state machine is currently reacting only to events.

Definition at line 221 of file StateMachine.hpp.

Referenced by unloading().

bool RTT::scripting::StateMachine::isStopped ( ) const
inline

Returns true if the state machine is in the final state, after a stop() directive.

Definition at line 211 of file StateMachine.hpp.

bool RTT::scripting::StateMachine::isStrictlyActive ( ) const
inline

Strictly active, means active and not in a transition.

Definition at line 174 of file StateMachine.hpp.

void RTT::StateMachine::leaveState ( StateInterface s)
protected
void RTT::base::ExecutableInterface::loaded ( ExecutionEngine ee)
inlineinherited

Called by the ExecutionEngine ee or before synchronous execution to tell this object it is being loaded.

The engine pointer is set first and the user's loading() function is called next.

Parameters
eeThe pointer to the engine calling us.

Definition at line 73 of file ExecutableInterface.hpp.

Referenced by RTT::scripting::StateInterface::loaded(), and RTT::ExecutionEngine::runFunction().

void RTT::StateMachine::loading ( )
virtual

Informs this object that it got loaded in an ExecutionEngine.

Called by load() after the engine pointer is set.

Reimplemented from RTT::base::ExecutableInterface.

Definition at line 84 of file StateMachine.cpp.

References eventMap, RTT::base::ExecutableInterface::getEngine(), RTT::scripting::StateMachine::Status::inactive, smStatus, stateMap, and TRACE.

StateInterface * RTT::StateMachine::nextState ( )

Search from the current state a candidate next state.

If none is found, the current state is returned.

Note
The mere calling of this method, may influence future possible results. Multiple invocations of nextState() may return different results, so use with care.
See also
requestNextState()

Definition at line 732 of file StateMachine.cpp.

References checkConditions(), and stateMap.

bool RTT::StateMachine::pause ( )
void RTT::StateMachine::preconditionSet ( StateInterface state,
ConditionInterface cnd,
int  line 
)

Express a precondition for entering a state.

The precondition will be chained (Logical AND) with any transition to this state. This means that any transition to this state will only succeed if all preconditions hold. If state is the initial state, the preconditions must be true to make actiate() succeed. If state is the final state, they will not be checked upon requestFinalState, since requestFinalState always succeeds.

Parameters
stateThe state for which the preconditions must hold
cndThe Pre-Condition under which a transition to this state may succeed
lineThe line number where this precondition was introduced.

Definition at line 882 of file StateMachine.cpp.

References precondMap, and stateMap.

bool RTT::StateMachine::reactive ( )
bool RTT::StateMachine::requestFinalState ( )

Request going to the Final State.

This will always proceed.

Definition at line 391 of file StateMachine.cpp.

References inError(), interruptible(), requestStateChange(), and TRACE.

Referenced by execute(), and unloading().

bool RTT::StateMachine::requestInitialState ( )

Request going to the Initial State.

This function will only proceed if the current state is the Final State or the Initial State. If it fails, one can try to requestNextState() which may lead to the initial state anyway if the transition is set. This path is not tried by this function.

Returns
The true on success, false if not allowed.

Definition at line 376 of file StateMachine.cpp.

References interruptible(), requestStateChange(), and TRACE.

Referenced by execute().

StateInterface * RTT::StateMachine::requestNextState ( bool  stepping = false)

Search from the current state a candidate next state.

If none is found, the current state is taken. Next, handle the resulting state.

Note
This call is not equivalent to this->requestState( this->nextState() ), since multiple invocations of this->nextState() may result in different results, hence, this->requestState( this->nextState() ) may return false. Use this method instead to automatically go to the next state.
Parameters
steppingprovide true if the transition evaluations should be executed one at a time.
Returns
The current state.

Definition at line 616 of file StateMachine.cpp.

References changeState(), checkConditions(), interruptible(), and stateMap.

Referenced by execute().

StateInterface* RTT::scripting::StateMachine::requestNextStateStep ( )

Go stepwise through evaluations to find out next state.

See also
requestNextState()
bool RTT::scripting::StateMachine::requestState ( const std::string &  statename)
inline

Request a transition to a given state.

Definition at line 132 of file StateMachine.hpp.

bool RTT::StateMachine::requestStateChange ( StateInterface s_n)

Request a state transition to a new state.

If the transition is not set by transitionSet(), acquiering the state will fail.

Parameters
s_nThe state to change to
Return values
trueif the transition is successfull
falseif the transition is not allowed

Definition at line 786 of file StateMachine.cpp.

References changeState(), checkConditions(), executePending(), interruptible(), and stateMap.

Referenced by requestFinalState(), and requestInitialState().

bool RTT::StateMachine::reset ( )

Reset the state machine from the final state to the initial state and wait for events or requests.

Definition at line 246 of file StateMachine.cpp.

References smStatus, RTT::scripting::StateMachine::Status::stopped, and TRACE.

void RTT::StateMachine::runState ( StateInterface s)
protected
void RTT::StateMachine::setFinalState ( StateInterface s)

Set the final state of this StateMachine.

Definition at line 1150 of file StateMachine.cpp.

References stateMap.

void RTT::scripting::StateMachine::setInitCommand ( base::ActionInterface c)
inline

This was added for extra (non-user visible) initialisation when the StateMachine is activated.

Parameters
cThe command to execute upon each activate. c is aggregated by this state machine and deleted in the destructor.

Definition at line 533 of file StateMachine.hpp.

void RTT::StateMachine::setInitialState ( StateInterface s)

Set the initial state of this StateMachine.

Definition at line 1144 of file StateMachine.cpp.

References stateMap.

void RTT::scripting::StateMachine::setParent ( StateMachinePtr  parent)
inline

Definition at line 551 of file StateMachine.hpp.

bool RTT::StateMachine::start ( )

Enter automatic mode: evaluating the transition conditions continuously.

Definition at line 203 of file StateMachine.cpp.

References automatic().

bool RTT::StateMachine::step ( )

Execute a single action if the state machine is paused or evaluate the transition conditions if the state machine is reactive.

Definition at line 187 of file StateMachine.cpp.

References RTT::scripting::StateMachine::Status::active, RTT::scripting::StateMachine::Status::paused, RTT::scripting::StateMachine::Status::requesting, smStatus, and TRACE.

bool RTT::scripting::StateMachine::stepDone ( ) const
inline

When isPaused(), return true if no step is pending, when isReactive(), return isStrictlyActive()

Definition at line 196 of file StateMachine.hpp.

bool RTT::StateMachine::stop ( )

Bring the state machine to the safe final state and wait for events or requests.

Definition at line 235 of file StateMachine.cpp.

References RTT::scripting::StateMachine::Status::inactive, smStatus, TRACE, and RTT::scripting::StateMachine::Status::unloaded.

Referenced by unloading().

void RTT::StateMachine::trace ( bool  on_off)

Turn log(Debug) messages on or off to track state transitions.

Definition at line 1156 of file StateMachine.cpp.

void RTT::StateMachine::transitionSet ( StateInterface from,
StateInterface to,
ConditionInterface cnd,
int  priority,
int  line 
)

Express a possible transition from one state to another under a certain condition.

Parameters
fromThe state which should be left
toThe state which should be entered
cndThe Condition under which the transition may succeed
priorityThe priority of this transition; low number (like -1000) is low priority high number is high priority (like + 1000). Transitions of equal priority are traversed in an unspecified way.
lineThe line number where this transition was introduced.
Postcondition
All transitions from from to to will succeed under condition cnd

Definition at line 891 of file StateMachine.cpp.

void RTT::StateMachine::transitionSet ( StateInterface from,
StateInterface to,
ConditionInterface cnd,
boost::shared_ptr< ProgramInterface transprog,
int  priority,
int  line 
)

Express a possible transition from one state to another under a certain condition.

Parameters
fromThe state which should be left
toThe state which should be entered
cndThe Condition under which the transition may succeed
transprogThe program to be executed between exit of from and entry of to. May be null to indicate the empty program.
priorityThe priority of this transition; low number (like -1000) is low priority high number is high priority (like + 1000). Transitions of equal priority are traversed in an unspecified way.
lineThe line number where this transition was introduced.
Postcondition
All transitions from from to to will succeed under condition cnd

Definition at line 896 of file StateMachine.cpp.

References RTT::scripting::StateInterface::getName(), stateMap, and TRACE.

void RTT::base::ExecutableInterface::unloaded ( )
inlineinherited

Called by the ExecutionEngine ee or after synchronous execution to tell this object it is being unloaded.

The user's loading() function is called first and the engine pointer is cleared next.

Definition at line 88 of file ExecutableInterface.hpp.

Referenced by RTT::ExecutionEngine::processFunctions(), RTT::ExecutionEngine::removeFunction(), and RTT::ExecutionEngine::~ExecutionEngine().

void RTT::StateMachine::unloading ( )
virtual

Informs this object that it got unloaded from an ExecutionEngine.

Called by unload() before the engine pointer is cleared.

Reimplemented from RTT::base::ExecutableInterface.

Definition at line 107 of file StateMachine.cpp.

References RTT::Critical, currentState(), execute(), getFinalState(), getLineNumber(), RTT::scripting::StateInterface::getName(), getName(), isActive(), isAutomatic(), isReactive(), requestFinalState(), stop(), and TRACE.

Referenced by RTT::scripting::ParsedStateMachine::unloading().

Member Data Documentation

std::vector<StateMachinePtr> RTT::scripting::StateMachine::_children
protected

Definition at line 100 of file StateMachine.hpp.

std::string RTT::scripting::StateMachine::_name
protected

Definition at line 104 of file StateMachine.hpp.

Referenced by RTT::scripting::ParsedStateMachine::setName(), and ~StateMachine().

StateMachineParentPtr RTT::scripting::StateMachine::_parent
protected

Definition at line 102 of file StateMachine.hpp.

ExecutionEngine* RTT::base::ExecutableInterface::engine
protectedinherited

Definition at line 63 of file ExecutableInterface.hpp.

EventMap RTT::scripting::StateMachine::eventMap
protected

A map keeping track of all events of a state.

Not all states need to be present as a key in this map.

Definition at line 620 of file StateMachine.hpp.

Referenced by createEventTransition(), disableEvents(), enableEvents(), and loading().

PreConditionMap RTT::scripting::StateMachine::precondMap
protected

A map keeping track of all preconditions of a state.

Not all states need to be present as a key in this map.

Definition at line 614 of file StateMachine.hpp.

Referenced by checkConditions(), and preconditionSet().

Status::StateMachineStatus RTT::scripting::StateMachine::smStatus
protected
TransitionMap RTT::scripting::StateMachine::stateMap
protected

A map keeping track of all States and conditional transitions between two states.

Every state of this StateMachine must be] present as a key in this map.

Definition at line 608 of file StateMachine.hpp.

Referenced by activate(), addState(), changeState(), createEventTransition(), enterState(), executePending(), getState(), getStateList(), loading(), nextState(), preconditionSet(), requestNextState(), requestStateChange(), setFinalState(), setInitialState(), and transitionSet().


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