|
|
|
=C=>
in shorthand notation) to move to the
next state in your state machine.
If you want to signal completion of a state node that you define, you
can call postStateCompletion() to post a completion event. This
method is inherited from the StateNode class. Writing
is equivalent to writingpostStateCompletion();
erouter->postEvent(EventBase::stateMachineEGID, (size_t)this, EventBase::statusETID);
=F=>
. For
example, you might write a state node that watches a ball and signals
completion when the ball is within reach of the robot. If the camera
loses sight of the ball, the state node might post a failure
event.
To complement the failure transition, there is a success transition,
abbreviated =S=>
. Sometimes you want to signal one of
two outcomes where neither is a "completion" or an abnormal condition;
they're just two possible alternatives, such as an answer to a
true/false question. You can use success and failure transitions for
this purpose.
=S=<T>(v)=>
as an abbreviation for SignalTrans, where T is the datatype of the signal
and v is the signal value to check for.
$nodeclass MyBehavior : VisualRoutinesStateNode { enum proceedInstruction { turnLeft, turnRight, straightAhead }; $nodeclass DecideNode : VisualRoutinesStateNode : { virtual void doStart() { ... if ( x < -10 ) { postStateSignal<proceedInstruction>(turnLeft); return; } else ... ... } } $setupmachine{
|
is equivalent to writingpostStateSignal<proceedInstruction>(turnLeft);
erouter->postEvent(DataEvent<proceedInstruction>(turnLeft, EventBase::stateMachineEGID, (size_t)this, EventBase::statusETID));
event
is set to the event that triggered
the transition. (This is also true when the node's doEvent method is
invoked.) In the case of a SignalTrans<T> transition invoking
the doStart method, event
is set to a DataEvent<T>.
User code can examine the DataEvent and retrieve the data it contains.
A method for doing this, called extractSignal<T>, is provided by
the StateNode class, allowing you to write:
If a node may be entered in one of several ways, you will want to check the event type before calling extractSignal. There is also a tryExtractSignal method that returns a pointer to the data in the DataEvent<T>, or a NULL pointer ifvirtual void doStart() { const proceedInstruction x = extractSignal(event); ... }
event
is NULL or
is not of type DataEvent<T>.
|
|
|