public class FiniteStateMachineBehavior extends Object implements Behavior
A finite-state machine behavior is a composite behavior that schedules its children serially like the sequential behavior. The children of the finite-state machine behavior, called states, can have results which determine which their successor state.
The behavior is finished if a state is reached that is finished and that has no successors.
Alternatively, the states may be arranged in a cyclic way. Then, one run of the finite-state machine executes each of its child at most once. The execution continues with the next call of the run method.
Constructor and Description |
---|
FiniteStateMachineBehavior(BehaviorController controller)
Instantiate the behavior with the specified controller.
|
Modifier and Type | Method and Description |
---|---|
State |
currentState()
Returns the current state.
|
void |
deregisterState(State state)
Deregister a state.
|
void |
deregisterTransition(State origin)
Deregister a default transition.
|
void |
deregisterTransition(State origin,
Result input)
Deregister a conditional transition.
|
boolean |
isFinished()
Indicates whether the behavior is finished or requires re-scheduling.
|
void |
registerStartState(State start,
Behavior behavior)
Register a start state and the respective behavior.
|
void |
registerState(State state,
Behavior behavior)
Register a state.
|
void |
registerTransition(State origin,
State destination)
Register a default transition from one state to another.
|
void |
registerTransition(State origin,
State destination,
Result input)
Register a conditional transition from one state to another that depends
on the outcome of the origin state.
|
Result |
result()
Returns the result of the behavior.
|
void |
run()
The implementation of the actual behavior.
|
EventPattern |
waitingFor()
Defines the event pattern for re-scheduling.
|
public FiniteStateMachineBehavior(BehaviorController controller)
controller
- the controller of this behaviorpublic void registerStartState(State start, Behavior behavior)
start
- the identifier of the state to be registeredbehavior
- the behavior to be executed in this statepublic void registerState(State state, Behavior behavior)
state
- the identifier of the state to be registeredbehavior
- the behavior to be executed in this statepublic void deregisterState(State state)
state
- the state to be deregisteredpublic void registerTransition(State origin, State destination)
origin
- the origin state of the transitiondestination
- the destination state of the transitionpublic void registerTransition(State origin, State destination, Result input)
origin
- the origin state of the transitiondestination
- the destination state of the transitioninput
- the outcome of the origin state specifying this transitionpublic void deregisterTransition(State origin)
origin
- the origin state of the default transition to be deregisteredpublic void deregisterTransition(State origin, Result input)
origin
- the origin state of the conditional transition to be
deregisteredinput
- the outcome of the origin state specifying the conditional
transition to be deregisteredpublic void run()
Behavior
public EventPattern waitingFor()
Defines the event pattern for re-scheduling. The behavior controller will re-schedule the behavior if an event occurs that is covered by the pattern.
The return value is the event pattern of the currently active state.
waitingFor
in interface Behavior
null
if the behavior is finishedpublic boolean isFinished()
Behavior
isFinished
in interface Behavior
true
if the behavior is finished,
false
otherwisepublic Result result()
Behavior
Returns the result of the behavior.
Note that the result is only available if the behavior is finished. Otherwise, an illegal-state exception may be thrown.
public State currentState()
Copyright © Aimpulse Intelligent Systems GmbH
All rights reserved.