Package edu.tufts.hrilab.action
Class ActionInterpreter
java.lang.Object
edu.tufts.hrilab.action.ActionInterpreter
- All Implemented Interfaces:
Callable<ActionStatus>
- Direct Known Subclasses:
RolloutActionInterpreter
ActionInterpreter is the primary step execution module for the
robot.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ActionStackThe action call stack.protected ContextContext that is currently being executed by this ActionInterpreter. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedActionInterpreter(Goal goal, Context rootContext) Only ActionInterpreter constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidcall()The main ActionInterpreter run method.voidcancel()Sets the canceled flag to true, and sets the current context to CANCEL.protected ContextcreateExecutionStack(Context context) Create the execution stack from a context tree which may be partially executedstatic ActionInterpretercreateInterpreterFromContext(Goal goal, Context step) Create new ActionInterpreter instance from an action context.static ActionInterpretercreateInterpreterFromEventSpec(Goal goal, Context caller, EventSpec eventSpec) Create new ActionInterpreter instance from an event spec.static ActionInterpretercreateInterpreterFromExecutionTree(Goal goal, Context goalRoot) Create a new ActionInterpreter instance from a context that may have been partially executedstatic ActionInterpretercreateInterpreterFromGoal(Goal goal, Context caller, StateMachine stateMachine) Create a new ActionInterpreter instance to execute a goal.static ActionInterpretercreateInterpreterFromGoal(Goal goal, Context caller, StateMachine stateMachine, ExecutionType executionType) Create a new ActionInterpreter instance to execute a goal (with specified executionType).doubleGet the benefit of the step.doubleGet the cost of the step.longGet the maximum time allowed the step.doubleGet the maximum urgency allowed the step.doubleGet the minimum urgency allowed the step.doubleGet the step's current priority.longGet the start time for the step.getGoal()getRoot()Get the root context executed by this ActionIntepreter.protected booleanisValid()Whether this ActionInterpreter instance is valid (i.e.voidresume()Resume the Action Interpreter's script after suspending.protected ContextrunAsyncCycle(Context step) Execute one cycle of the step interpreter.protected ContextExecute one cycle of the step interpreter.protected voidsetActionPriority(double newpri) Set the step's current priority.protected voidsetCurrentStep(Context step) voidsuspend()Suspend the Action Interpreter's script.void
-
Field Details
-
currentStep
Context that is currently being executed by this ActionInterpreter. -
callStack
The action call stack.
-
-
Constructor Details
-
ActionInterpreter
Only ActionInterpreter constructor. All AIs should be constructed through a factory method (e.g., createInterpreterFrom___(...)).- Parameters:
goal-rootContext-
-
-
Method Details
-
createInterpreterFromGoal
public static ActionInterpreter createInterpreterFromGoal(Goal goal, Context caller, StateMachine stateMachine) Create a new ActionInterpreter instance to execute a goal.- Parameters:
goal- Goalcaller- Caller context (e.g. root context)stateMachine- state machine to use for execution
-
createInterpreterFromGoal
public static ActionInterpreter createInterpreterFromGoal(Goal goal, Context caller, StateMachine stateMachine, ExecutionType executionType) Create a new ActionInterpreter instance to execute a goal (with specified executionType).- Parameters:
goal- Goalcaller- Caller context (e.g. root context)stateMachine- state machine to use for executionexecutionType- action execution type- Returns:
-
createInterpreterFromEventSpec
public static ActionInterpreter createInterpreterFromEventSpec(Goal goal, Context caller, EventSpec eventSpec) Create new ActionInterpreter instance from an event spec.- Parameters:
goal- Goalcaller- Caller context (e.g. root context)eventSpec- The EventSpec describing the initial action
-
createInterpreterFromContext
Create new ActionInterpreter instance from an action context.- Parameters:
step- context to be executed (e.g. root context)
-
createInterpreterFromExecutionTree
Create a new ActionInterpreter instance from a context that may have been partially executed- Parameters:
goal- the goal which the context tree is working towardgoalRoot- the root context for the goal- Returns:
- the action new interpreter
-
createExecutionStack
Create the execution stack from a context tree which may be partially executed- Parameters:
context- a partially executed context tree used to create execution stack- Returns:
- the starting context step
-
runCycle
Execute one cycle of the step interpreter. This is currently equivalent to executing one primitive (i.e., progressing through the script until a primitive is found). -
runAsyncCycle
Execute one cycle of the step interpreter. This is currently equivalent to executing one primitive (i.e., progressing through the script until a primitive is found). -
getRoot
Get the root context executed by this ActionIntepreter.- Returns:
- root context/step
-
getActionCost
public double getActionCost()Get the cost of the step.- Returns:
- the cost
-
getActionBenefit
public double getActionBenefit()Get the benefit of the step.- Returns:
- the benefit
-
getActionMaxTime
public long getActionMaxTime()Get the maximum time allowed the step.- Returns:
- the max time
-
getActionStartTime
public long getActionStartTime()Get the start time for the step.- Returns:
- the start time
-
getActionMaxUrg
public double getActionMaxUrg()Get the maximum urgency allowed the step.- Returns:
- the max urgency
-
getActionMinUrg
public double getActionMinUrg()Get the minimum urgency allowed the step.- Returns:
- the min urgency
-
getActionPriority
public double getActionPriority()Get the step's current priority.- Returns:
- the priority
-
setActionPriority
protected void setActionPriority(double newpri) Set the step's current priority.- Parameters:
newpri- the new priority
-
getGoal
-
isValid
protected boolean isValid()Whether this ActionInterpreter instance is valid (i.e. can run) or not. It all comes down the the status of the current step.- Returns:
- true if ActionInterpreter is valid and can execute the action.
-
call
The main ActionInterpreter run method. After running some checks (locks init and such), it will loop whileshouldUpdate. Each loop makes a call torunCycleto execute the behavior for a single loop/cycle.- Specified by:
callin interfaceCallable<ActionStatus>
-
setCurrentStep
-
suspend
public void suspend()Suspend the Action Interpreter's script. -
resume
public void resume()Resume the Action Interpreter's script after suspending. -
cancel
public void cancel()Sets the canceled flag to true, and sets the current context to CANCEL. This does not explicitly halt the ActionInterpreter, but instead relies on the handling of the CANCEL status by the currently running action. This allows for graceful handling of canceled actions (e.g., via try/catch/finally). This is the only option for external classes. -
updatePriority
-
addListener
-
getCurrentStep
-