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 ActionStack
The action call stack.protected Context
Context that is currently being executed by this ActionInterpreter. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ActionInterpreter
(Goal goal, Context rootContext) Only ActionInterpreter constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
call()
The main ActionInterpreter run method.void
cancel()
Sets the shouldCancel flag to true, which will cause the main AI loop to set the next step's ActionStatus to CANCEL.protected Context
createExecutionStack
(Context context) Create the execution stack from a context tree which may be partially executedstatic ActionInterpreter
createInterpreterFromContext
(Goal goal, Context step) Create new ActionInterpreter instance from an action context.static ActionInterpreter
createInterpreterFromEventSpec
(Goal goal, Context caller, EventSpec eventSpec) Create new ActionInterpreter instance from an event spec.static ActionInterpreter
createInterpreterFromExecutionTree
(Goal goal, Context goalRoot) Create a new ActionInterpreter instance from a context that may have been partially executedstatic ActionInterpreter
createInterpreterFromGoal
(Goal goal, Context caller, StateMachine stateMachine) Create a new ActionInterpreter instance to execute a goal.static ActionInterpreter
createInterpreterFromGoal
(Goal goal, Context caller, StateMachine stateMachine, ExecutionType executionType) Create a new ActionInterpreter instance to execute a goal (with specified executionType).double
Get the benefit of the step.double
Get the cost of the step.long
Get the maximum time allowed the step.double
Get the maximum urgency allowed the step.double
Get the minimum urgency allowed the step.double
Get the step's current priority.long
Get the start time for the step.getGoal()
getRoot()
Get the root context executed by this ActionIntepreter.protected boolean
isValid()
Whether this ActionInterpreter instance is valid (i.e.void
resume()
Resume the Action Interpreter's script.protected Context
runAsyncCycle
(Context step) Execute one cycle of the step interpreter.protected Context
Execute one cycle of the step interpreter.protected void
setActionPriority
(double newpri) Set the step's current priority.protected void
setCurrentStep
(Context step) void
suspend()
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 torunCycle
to execute the behavior for a single loop/cycle.- Specified by:
call
in interfaceCallable<ActionStatus>
-
setCurrentStep
-
suspend
public void suspend()Suspend the Action Interpreter's script. -
resume
public void resume()Resume the Action Interpreter's script. -
cancel
public 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
-