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 SummaryFieldsModifier and TypeFieldDescriptionprotected ActionStackThe action call stack.protected ContextContext that is currently being executed by this ActionInterpreter.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedActionInterpreter(Goal goal, Context rootContext) Only ActionInterpreter constructor.
- 
Method SummaryModifier and TypeMethodDescriptionvoidcall()The main ActionInterpreter run method.voidcancel()Sets the shouldCancel flag to true, which will cause the main AI loop to set the next step's ActionStatus 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.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- 
currentStepContext that is currently being executed by this ActionInterpreter.
- 
callStackThe action call stack.
 
- 
- 
Constructor Details- 
ActionInterpreterOnly ActionInterpreter constructor. All AIs should be constructed through a factory method (e.g., createInterpreterFrom___(...)).- Parameters:
- goal-
- rootContext-
 
 
- 
- 
Method Details- 
createInterpreterFromGoalpublic static ActionInterpreter createInterpreterFromGoal(Goal goal, Context caller, StateMachine stateMachine) Create a new ActionInterpreter instance to execute a goal.- Parameters:
- goal- Goal
- caller- Caller context (e.g. root context)
- stateMachine- state machine to use for execution
 
- 
createInterpreterFromGoalpublic 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- Goal
- caller- Caller context (e.g. root context)
- stateMachine- state machine to use for execution
- executionType- action execution type
- Returns:
 
- 
createInterpreterFromEventSpecpublic static ActionInterpreter createInterpreterFromEventSpec(Goal goal, Context caller, EventSpec eventSpec) Create new ActionInterpreter instance from an event spec.- Parameters:
- goal- Goal
- caller- Caller context (e.g. root context)
- eventSpec- The EventSpec describing the initial action
 
- 
createInterpreterFromContextCreate new ActionInterpreter instance from an action context.- Parameters:
- step- context to be executed (e.g. root context)
 
- 
createInterpreterFromExecutionTreeCreate a new ActionInterpreter instance from a context that may have been partially executed- Parameters:
- goal- the goal which the context tree is working toward
- goalRoot- the root context for the goal
- Returns:
- the action new interpreter
 
- 
createExecutionStackCreate 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
 
- 
runCycleExecute 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).
- 
runAsyncCycleExecute 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).
- 
getRootGet the root context executed by this ActionIntepreter.- Returns:
- root context/step
 
- 
getActionCostpublic double getActionCost()Get the cost of the step.- Returns:
- the cost
 
- 
getActionBenefitpublic double getActionBenefit()Get the benefit of the step.- Returns:
- the benefit
 
- 
getActionMaxTimepublic long getActionMaxTime()Get the maximum time allowed the step.- Returns:
- the max time
 
- 
getActionStartTimepublic long getActionStartTime()Get the start time for the step.- Returns:
- the start time
 
- 
getActionMaxUrgpublic double getActionMaxUrg()Get the maximum urgency allowed the step.- Returns:
- the max urgency
 
- 
getActionMinUrgpublic double getActionMinUrg()Get the minimum urgency allowed the step.- Returns:
- the min urgency
 
- 
getActionPrioritypublic double getActionPriority()Get the step's current priority.- Returns:
- the priority
 
- 
setActionPriorityprotected void setActionPriority(double newpri) Set the step's current priority.- Parameters:
- newpri- the new priority
 
- 
getGoal
- 
isValidprotected 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.
 
- 
callThe 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 interface- Callable<ActionStatus>
 
- 
setCurrentStep
- 
suspendpublic void suspend()Suspend the Action Interpreter's script.
- 
resumepublic void resume()Resume the Action Interpreter's script.
- 
cancelpublic void cancel()Sets the shouldCancel flag to true, which will cause the main AI loop to set the next step's ActionStatus 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
 
-