Implementing Primitive Actions

From ABL
Jump to: navigation, search

Concretely, several things must happen to implement and use an act.

  1. Implement a subclass of abl.compiler.runtime.PrimitiveAction. This involves implementing void execute(Object[] args) and possibly void abort().

    The body of execute(Object[] args) should execute the act "physically" in the virtual world of the agent. The body of abort() should terminate the execution of the physical act (if it is executing) and clean up any resources it holds.
  2. Optionally, override void decisionCycleCallback() if you need to do some processing every decision cycle.
  3. Register an act signature with a PrimitiveAction subclass.

For example, suppose in a baseball game world, the agent is able to throw a ball in a direction, with an angle, and a force. You might write:

register action throw(Ball, Direction, double, Force) with ThrowBall;

Let primAct(s) denote the run-time instance of PrimitiveAction which is the object of registration with signature s. For example,


primAct(throw(Ball, Direction, double, Force)) = a ThrowBall instance

Implementing execute()

execute(Object[] args) executes the primitive action. The execute() method defined on concrete PrimitiveSteps calls execute() on the PrimitiveAction. The ABL execution loop blocks on executing a primitive action. Thus primitive actions should return as quickly as possible. The executing action is also responsible for setting the completion status. Concrete physical actions may implement execute using one of the three following strategies:

  1. For actions which execute very quickly in the underlying execution system (e.g. setting a state flag), execute can directly make the appropriate RPC call and set completionStatus.
  2. For longer actions, may fork another method in a separate thread and immediately return the current thread of execution. The spawn thread is responsible for setting completionStatus.
  3. For longer actions, the execution system (e.g. world, robotic system) may be written so as to accept callbacks. The exeuction system then calls the callback when the action finishes executing. The current thread of execution initiates the action, registers the callback, and returns immediately. The default callback routine (defined above) appropriately updates the completion status.

Completion Callbacks

For actions which take significant time to execute, the action execution system (e.g. virtual world, robotic body, etc.), can be written to callback the PrimitiveAction when the activity completes (with success or failure). The completion callback accepts a single boolean argument: true for completion with success, false for completion with failure. The default completion callback updates the completion status of the action.

See the method PrimitiveAction.completionCallback(boolean).

Decision Cycle Callbacks

There are very good reasons why you might want to implement a decision cycle callback. I just don't know what they are.