RoboJDETM v2.0

com.ridgesoft.robotics
Class BehaviorArbiter

java.lang.Object
  extended by java.lang.Thread
      extended by com.ridgesoft.robotics.BehaviorArbiter
All Implemented Interfaces:
Runnable

public class BehaviorArbiter
extends Thread

Implements a behavior arbitrator for behavior-based control of a robot.

A BehaviorArbiter arbitrates between a number of behaviors competing for control of the robot. The BehaviorArbiter maintains a priority ordered list of behavoir objects which must implent the Behavior interface. Using its own thread, the BehaviorArbiter periodically polls each Behavior by invoking each Behavior's poll method. Each Behavior indicates whether it desires to control the robot via the return argument of its poll method. During each polling iteration the BehaviorArbiter selects the active Behavior by choosing the highest priority Behavior that desires to control the robot. The BehaviorArbiter invokes each Behavior's poll method on each iteration, regardless of which Behavior it selects to be active.

Whenever the BehaviorArbiter's active Behavior selection changes, the BehaviorArbiter brings about a change in control by deactivating the currently active Behavior and activating the newly selected Behavior. It does this by invoking the setActive method of the affected Behaviors, using the argument to this method to activate or deactivate the Behavior, as appropriate.

The Behaviors operate in a "nice-guy" environment and, therefore, must operate according to the intentions of the BehaviorArbiter inorder for the behavior system to function correctly. When a Behavior is active, it is must take control of the robot. When a Behavior is inactive it must refrain from attempting to control the robot.

Active Behaviors may use their poll method as a means to periodically adjust their control of the robot. However, calls to a Behavior's poll method must return quickly to avoid interfering with the operation of the BehaviorArbiter and the other Behaviors. If a particular Behavior needs to update its control of the robot more frequently than the polling interval, that Behavior should use a separate thread or timer to carry out its control of the robot.

See Also:
Behavior, Behavior2, BehaviorEvent, BehaviorListener, com.ridgesoft.robotics.behaviors

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BehaviorArbiter(Behavior[] behaviors, int period)
          Constructs a BehaviorArbiter object and thread, but does not start the thread.
BehaviorArbiter(Behavior[] behaviors, int period, DigitalOutput heartBeat)
          Constructs a BehaviorArbiter object and thread, but does not start the thread.
BehaviorArbiter(Behavior[] behaviors, LED led, int period)
          Constructs a BehaviorArbiter object and thread, but does not start the thread.
 
Method Summary
 void run()
          The BehaviorArbiter thread's run method.
 
Methods inherited from class java.lang.Thread
activeCount, currentThread, dumpStack, getName, getPriority, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, setDaemon, setName, setPriority, sleep, start, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait
 

Constructor Detail

BehaviorArbiter

public BehaviorArbiter(Behavior[] behaviors,
                       int period)
Constructs a BehaviorArbiter object and thread, but does not start the thread.

Use the start method to start the BehaviorArbiter thread.

Parameters:
behaviors - an array of behaviors with the highest priority behavior at index 0 in the list
period - the period of execution of this BehaviorArbiter in milliseconds

BehaviorArbiter

public BehaviorArbiter(Behavior[] behaviors,
                       int period,
                       DigitalOutput heartBeat)
Constructs a BehaviorArbiter object and thread, but does not start the thread.

Use the start method to start the BehaviorArbiter thread.

Parameters:
behaviors - an array of behaviors with the highest priority behavior at index 0 in the list
period - the period of execution of this BehaviorArbiter in milliseconds
heartBeat - a DigitalOutput to toggle each behavior iteration - may be null

BehaviorArbiter

public BehaviorArbiter(Behavior[] behaviors,
                       LED led,
                       int period)
Constructs a BehaviorArbiter object and thread, but does not start the thread.

Use the start method to start the BehaviorArbiter thread.

Parameters:
behaviors - an array of behaviors with the highest priority behavior at index 0 in the list
led - an LED to toggle each behavior iteration - may be null
period - the period of execution of this BehaviorArbiter in milliseconds
Method Detail

run

public void run()
The BehaviorArbiter thread's run method.

Do not use this method directly. Instead, use the start method to start the BehaviorArbiter thread.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

RoboJDETM v2.0

Copyright (c) 2003-2009 RidgeSoft, LLC. All rights reserved.
www.ridgesoft.com