public class StateWorkExecutor extends Object implements IWorkExecutor
IWorkExecutor, that considers actions to be have state,
in this executor, primitive is working in phases INIT, RUN*, DONE.
Thanks to state nature of primitive, primitive is far easier to program
in discrete time-slice (time slice = primitive can be called multiple times consequentially)
nature of Pogamut. If primitive wasn't notified that it is about to end,
things like switching from primitive "walk" to "shoot" could be troublesome.
Imagine it, "walk" primitive will compute path to destination and suddently
new primitive "shoot" is now called. What about path the bot is following? It
will still follow it, although it is supposed to stop and start shooting.
To handle this correctlty is troublesome for few states, for many states, it is madness.
StateWorkExecutor would do this: ..., walk.INIT, walk.RUN*, walk.DONE, shoot.INIT, shoot.RUN*, shoot.DONE....,
primitive walk would have DONE called before shoot.INIT would be called,
allowing it to stop walking. Same thing is valid for state shoot too.
Since we have phase DONE to cleanup some stuff before we switch to another,
where another can be nearly anything, what state bot should be in when DONE
phase is DONE. In neutral bot state (precise neutral state is defined by programmer,
in unreal, that would probably be standing, not shooting.).
What if we don't want to switch to neutral bot state after primitive is DONE?
Don't, there is no explicit need, and in many situation it is meaningless (such as
primtive "enter_ducts" where bot would entering INIT in standing state, but left
DONE crouching).IAction| Modifier and Type | Field and Description |
|---|---|
protected HashMap<String,IAction> |
actions
Map that maps primtive name to
IAction. |
protected String |
currentActionName
Primitive that is currently being executed.
|
protected Logger |
log
Log where we put
|
protected HashMap<String,ISense> |
senses
Map that maps primitive name to its respective
ISense. |
| Constructor and Description |
|---|
StateWorkExecutor() |
StateWorkExecutor(Logger log) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAction(IAction action)
Add primitive, use name from annotations.
|
void |
addAction(String name,
IAction action)
Add new
IAction with primitive name. |
void |
addSense(ISense sense)
Add primitive, use name from annotations.
|
void |
addSense(String name,
ISense sense)
Add new
ISense with primtive name. |
ActionResult |
executeAction(String actionToExecuteName,
VariableContext ctx)
Execute action and get the result.
|
Object |
executeSense(String primitive,
VariableContext ctx)
Execute sense and get the result.
|
Logger |
getLogger()
Get logger of this
IWorkExecutor. |
protected boolean |
isAction(String name)
Is there an action with the name.
|
boolean |
isNameUsed(String name)
Is name used in some primtive in this the work executor.
|
protected boolean |
isSense(String name)
Is there a sense with the name.
|
protected final HashMap<String,ISense> senses
ISense.protected String currentActionName
protected Logger log
public StateWorkExecutor()
public StateWorkExecutor(Logger log)
public Logger getLogger()
IWorkExecutor.public boolean isNameUsed(String name)
name - queried nameStateWorkExecutor.protected boolean isAction(String name)
name - queries nameprotected boolean isSense(String name)
name - queries namepublic void addAction(String name, IAction action)
IAction with primitive name.name - name that will be used for this IAction in posh plan.action - primitive that will be executed when executor will be asked to execute primtive with name.IllegalArgumentException - if primitive with name already exists in StateWorkExecutor.public void addSense(String name, ISense sense)
ISense with primtive name.name - name of primtive to be associated with passed sense objectsense - sense object to be used, when sense with name is supposed to execute.public void addAction(IAction action)
action - primitive that will be addedpublic void addSense(ISense sense)
sense - primitive that will be addedpublic Object executeSense(String primitive, VariableContext ctx)
IWorkExecutorexecuteSense in interface IWorkExecutorprimitive - name of primitivectx - variable context for sense containing possible parameterspublic ActionResult executeAction(String actionToExecuteName, VariableContext ctx)
IWorkExecutorexecuteAction in interface IWorkExecutoractionToExecuteName - name of primitivectx - variable context for action containing possible parametersCopyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.