Class ActionInterpreter

java.lang.Object
edu.tufts.hrilab.action.ActionInterpreter
All Implemented Interfaces:
Callable<ActionStatus>
Direct Known Subclasses:
RolloutActionInterpreter

public class ActionInterpreter extends Object implements Callable<ActionStatus>
ActionInterpreter is the primary step execution module for the robot.
  • Field Details

    • currentStep

      protected Context currentStep
      Context that is currently being executed by this ActionInterpreter.
    • callStack

      protected ActionStack callStack
      The action call stack.
  • Constructor Details

    • ActionInterpreter

      protected ActionInterpreter(Goal goal, Context rootContext)
      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 - Goal
      caller - 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 - Goal
      caller - Caller context (e.g. root context)
      stateMachine - state machine to use for execution
      executionType - 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 - Goal
      caller - Caller context (e.g. root context)
      eventSpec - The EventSpec describing the initial action
    • createInterpreterFromContext

      public static ActionInterpreter createInterpreterFromContext(Goal goal, Context step)
      Create new ActionInterpreter instance from an action context.
      Parameters:
      step - context to be executed (e.g. root context)
    • createInterpreterFromExecutionTree

      public static ActionInterpreter createInterpreterFromExecutionTree(Goal goal, Context goalRoot)
      Create 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
    • createExecutionStack

      protected Context createExecutionStack(Context context)
      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

      protected Context runCycle(Context step)
      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

      protected Context runAsyncCycle(Context step)
      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

      public Context 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

      public Goal 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

      public ActionStatus call()
      The main ActionInterpreter run method. After running some checks (locks init and such), it will loop while shouldUpdate. Each loop makes a call to runCycle to execute the behavior for a single loop/cycle.
      Specified by:
      call in interface Callable<ActionStatus>
    • setCurrentStep

      protected void setCurrentStep(Context step)
    • 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

      public void updatePriority(PriorityCalculator calc)
    • addListener

      public void addListener(ActionListener al)
    • getCurrentStep

      public Context getCurrentStep()