Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

StateNode Class Reference

#include <StateNode.h>

Inheritance diagram for StateNode:

Inheritance graph
[legend]
List of all members.

Detailed Description

Recursive data structure - both a state machine controller as well as a node within a state machine itself.

Override setup() to setup your own Transition and StateNode network. There are two StateNode templates in project/templates/: statenode.h and statemachine.h. statenode.h is meant for leaf nodes, which directly implement the execution of a task. statemachine.h is meant for nodes which contain a network of transitions and subnodes, which together solve the task.

Definition at line 16 of file StateNode.h.

Public Member Functions

 StateNode (const std::string &name)
 constructor, pass a name to use
virtual ~StateNode ()
 destructor, removes references to its outgoing transitions (be careful of incoming ones - they're still around!), and calls RemoveReference() on subnodes
virtual TransitionaddTransition (Transition *trans)
 Adds the specified StateTransition to the transition table.
std::vector< Transition * > & getTransitions ()
 Returns the std::vector of transitions so you can modify them yourself if need be.
const std::vector< Transition * > & getTransitions () const
 Returns the const std::vector of transitions so you can read through them if need be.
virtual StateNodeaddNode (StateNode *node)
 Adds a StateNode to nodes so it can be automatically dereferenced later, returns what it's passed (for convenience), calls AddReference() on node. Also sets the node's parent to this if it is null.
std::vector< StateNode * > & getNodes ()
 Returns the std::vector of sub-nodes so you can modify them yourself if need be.
const std::vector< StateNode * > & getNodes () const
 Returns the const std::vector of sub-nodes so you can read through them if need be.
void setRetain (bool f)
 Sets the retain flag - if not retained, will RemoveReference() subnodes upon DoStop() and recreate them on DoStart (by calling setup()) - may be too expensive to be worth saving memory...
virtual void DoStart ()
 Transitions should call this when you are entering the state, so it can enable its transitions.
virtual void setup ()
 This is called by DoStart() when you should setup the network of subnodes (if any).
virtual void DoStop ()
 Transitions should call this when you are leaving the state, so it can disable its transitions.
virtual void teardown ()
 This is called by DoStop() when you should destruct subnodes.
virtual StateNodegetParent () const
 returns parent

Protected Member Functions

 StateNode (const std::string &classname, const std::string &name)
 constructor, pass the class name and instance name to use
virtual void postStartEvent ()
 will throw an activation event through stateMachineEGID, used when DoStart() is called
virtual void postCompletionEvent (float magnitude=0)
 will throw a status event through stateMachineEGID to signal "completion" of the node
virtual void postStopEvent ()
 will throw an deactivation event through stateMachineEGID, used when DoStop() is called

Protected Attributes

StateNodeparent
 pointer to the machine that contains this node
std::vector< Transition * > transitions
 a vector of outgoing transitions
bool issetup
 this is set to true if the network has been setup but not destroyed (i.e. don't need to call setupSubNodes again)
bool retain
 this is set to true if the network should be retained between activations. Otherwise it's dereferenced upon DoStop(). (or at least RemoveReference() is called on subnodes)
unsigned int startedTime
 the timestamp of last call to DoStart()
std::vector< StateNode * > nodes
 vector of StateNodes, just so they can be dereferenced again on DoStop() (unless retained) or ~StateNode()

Private Member Functions

 StateNode (const StateNode &node)
 don't call this
StateNode operator= (const StateNode &node)
 don't call this


Constructor & Destructor Documentation

StateNode::StateNode const std::string &  name  )  [inline]
 

constructor, pass a name to use

Definition at line 19 of file StateNode.h.

StateNode::~StateNode  )  [virtual]
 

destructor, removes references to its outgoing transitions (be careful of incoming ones - they're still around!), and calls RemoveReference() on subnodes

Definition at line 5 of file StateNode.cc.

StateNode::StateNode const std::string &  classname,
const std::string &  name
[inline, protected]
 

constructor, pass the class name and instance name to use

Definition at line 66 of file StateNode.h.

StateNode::StateNode const StateNode node  )  [private]
 

don't call this


Member Function Documentation

StateNode * StateNode::addNode StateNode node  )  [virtual]
 

Adds a StateNode to nodes so it can be automatically dereferenced later, returns what it's passed (for convenience), calls AddReference() on node. Also sets the node's parent to this if it is null.

Definition at line 27 of file StateNode.cc.

Referenced by PaceTargetsMachine::setup(), ExploreMachine::setup(), and BanditMachine::setup().

Transition * StateNode::addTransition Transition trans  )  [virtual]
 

Adds the specified StateTransition to the transition table.

Definition at line 20 of file StateNode.cc.

Referenced by PaceTargetsMachine::setup(), ExploreMachine::setup(), and BanditMachine::setup().

void StateNode::DoStart  )  [virtual]
 

Transitions should call this when you are entering the state, so it can enable its transitions.

Reimplemented from BehaviorBase.

Reimplemented in BanditMachine, BanditMachine::PressNode, BanditMachine::DecideNode, BanditMachine::WaitNode, ExploreMachine, PaceTargetsMachine, GroupNode, HeadPointerNode, LedNode, MotionSequenceNode< SIZE >, OutputNode, SoundNode, TailWagNode, WalkNode, and WalkToTargetNode.

Definition at line 35 of file StateNode.cc.

Referenced by WalkToTargetNode::DoStart(), WalkNode::DoStart(), TailWagNode::DoStart(), SoundNode::DoStart(), PaceTargetsMachine::DoStart(), OutputNode::DoStart(), MotionSequenceNode< SIZE >::DoStart(), LedNode::DoStart(), HeadPointerNode::DoStart(), GroupNode::DoStart(), ExploreMachine::DoStart(), BanditMachine::WaitNode::DoStart(), BanditMachine::DecideNode::DoStart(), BanditMachine::PressNode::DoStart(), and BanditMachine::DoStart().

void StateNode::DoStop  )  [virtual]
 

Transitions should call this when you are leaving the state, so it can disable its transitions.

Reimplemented from BehaviorBase.

Reimplemented in BanditMachine, BanditMachine::PressNode, BanditMachine::WaitNode, ExploreMachine, HeadPointerNode, LedNode, MotionSequenceNode< SIZE >, SoundNode, TailWagNode, WalkNode, and WalkToTargetNode.

Definition at line 52 of file StateNode.cc.

Referenced by OutputNode::DoStart(), BanditMachine::DecideNode::DoStart(), WalkToTargetNode::DoStop(), WalkNode::DoStop(), TailWagNode::DoStop(), SoundNode::DoStop(), MotionSequenceNode< SIZE >::DoStop(), LedNode::DoStop(), HeadPointerNode::DoStop(), ExploreMachine::DoStop(), BanditMachine::WaitNode::DoStop(), BanditMachine::PressNode::DoStop(), and BanditMachine::DoStop().

const std::vector<StateNode*>& StateNode::getNodes  )  const [inline]
 

Returns the const std::vector of sub-nodes so you can read through them if need be.

Definition at line 40 of file StateNode.h.

std::vector<StateNode*>& StateNode::getNodes  )  [inline]
 

Returns the std::vector of sub-nodes so you can modify them yourself if need be.

Definition at line 37 of file StateNode.h.

Referenced by SpiderMachineBehavior::spider().

virtual StateNode* StateNode::getParent  )  const [inline, virtual]
 

returns parent

Definition at line 62 of file StateNode.h.

Referenced by SpiderMachineBehavior::isListening().

const std::vector<Transition*>& StateNode::getTransitions  )  const [inline]
 

Returns the const std::vector of transitions so you can read through them if need be.

Definition at line 31 of file StateNode.h.

std::vector<Transition*>& StateNode::getTransitions  )  [inline]
 

Returns the std::vector of transitions so you can modify them yourself if need be.

Definition at line 28 of file StateNode.h.

StateNode StateNode::operator= const StateNode node  )  [private]
 

don't call this

void StateNode::postCompletionEvent float  magnitude = 0  )  [protected, virtual]
 

will throw a status event through stateMachineEGID to signal "completion" of the node

"completion" is defined by your subclass - will mean different things to different nodes depending on the actions they are performing. So call this yourself if there is a natural ending point for your state.

Parameters:
magnitude the value to use for EventBase::magnitude -- generally is 1 for status events, but since this is to signal completion, 0 (the default) may be more appropriate; if your node is doing something repetitive however, 1 (or the loop count) may be better

Definition at line 85 of file StateNode.cc.

Referenced by WalkNode::processEvent(), TailWagNode::processEvent(), SoundNode::processEvent(), MotionSequenceNode< SIZE >::processEvent(), LedNode::processEvent(), and HeadPointerNode::processEvent().

void StateNode::postStartEvent  )  [protected, virtual]
 

will throw an activation event through stateMachineEGID, used when DoStart() is called

Definition at line 81 of file StateNode.cc.

Referenced by DoStart().

void StateNode::postStopEvent  )  [protected, virtual]
 

will throw an deactivation event through stateMachineEGID, used when DoStop() is called

Definition at line 89 of file StateNode.cc.

Referenced by DoStop().

void StateNode::setRetain bool  f  )  [inline]
 

Sets the retain flag - if not retained, will RemoveReference() subnodes upon DoStop() and recreate them on DoStart (by calling setup()) - may be too expensive to be worth saving memory...

Definition at line 43 of file StateNode.h.

virtual void StateNode::setup  )  [inline, virtual]
 

This is called by DoStart() when you should setup the network of subnodes (if any).

Reimplemented in BanditMachine, ExploreMachine, and PaceTargetsMachine.

Definition at line 49 of file StateNode.h.

Referenced by DoStart(), PaceTargetsMachine::setup(), ExploreMachine::setup(), and BanditMachine::setup().

void StateNode::teardown  )  [virtual]
 

This is called by DoStop() when you should destruct subnodes.

Default implementation will take care of the subnodes and their transitions, you only need to worry about any *other* memory which may have been allocated. If none, you may not need implement this function at all.

Reimplemented in ExploreMachine, PaceTargetsMachine, MotionSequenceNode< SIZE >, and WalkNode.

Definition at line 73 of file StateNode.cc.

Referenced by DoStop(), WalkNode::teardown(), PaceTargetsMachine::teardown(), MotionSequenceNode< SIZE >::teardown(), ExploreMachine::teardown(), and ~StateNode().


Member Data Documentation

bool StateNode::issetup [protected]
 

this is set to true if the network has been setup but not destroyed (i.e. don't need to call setupSubNodes again)

Definition at line 90 of file StateNode.h.

Referenced by DoStart(), DoStop(), setup(), teardown(), ExploreMachine::~ExploreMachine(), MotionSequenceNode< SIZE >::~MotionSequenceNode(), PaceTargetsMachine::~PaceTargetsMachine(), ~StateNode(), and WalkNode::~WalkNode().

std::vector<StateNode*> StateNode::nodes [protected]
 

vector of StateNodes, just so they can be dereferenced again on DoStop() (unless retained) or ~StateNode()

Definition at line 96 of file StateNode.h.

Referenced by addNode(), GroupNode::DoStart(), DoStop(), getNodes(), teardown(), and ~StateNode().

StateNode* StateNode::parent [protected]
 

pointer to the machine that contains this node

Definition at line 84 of file StateNode.h.

Referenced by addNode(), DoStart(), and getParent().

bool StateNode::retain [protected]
 

this is set to true if the network should be retained between activations. Otherwise it's dereferenced upon DoStop(). (or at least RemoveReference() is called on subnodes)

Definition at line 92 of file StateNode.h.

Referenced by DoStop(), and setRetain().

unsigned int StateNode::startedTime [protected]
 

the timestamp of last call to DoStart()

Definition at line 94 of file StateNode.h.

Referenced by postCompletionEvent(), and postStopEvent().

std::vector<Transition*> StateNode::transitions [protected]
 

a vector of outgoing transitions

Definition at line 86 of file StateNode.h.

Referenced by addTransition(), DoStart(), DoStop(), getTransitions(), and ~StateNode().


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

Tekkotsu v2.4.1
Generated Tue Aug 16 16:35:10 2005 by Doxygen 1.4.4