Implementing Primitive Actions
Concretely, several things must happen to implement and use an act.
- Implement a subclass of
abl.compiler.runtime.PrimitiveAction. This involves implementing
void execute(Object args)and possibly
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.
- Optionally, override
void decisionCycleCallback()if you need to do some processing every decision cycle.
- Register an act signature with a
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;
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
execute(Object args) executes the primitive action. The
execute() method defined on concrete
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:
- 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.
- 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.
- 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.
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
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.