interfaces
Class Controller

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--interfaces.Controller
All Implemented Interfaces:
java.lang.Runnable

public abstract class Controller
extends java.lang.Thread

Interface class for all controllers. All Controllers must extend this abstract class, and should obey the commands specified or system behaviour is undefined. e.g. a call to halt() *must* stop this controller's thread as quickly as possible and allow run() to return.

Author:
Graham Ritchie

Field Summary
static int SENSOR_TYPE_LIGHT
          Sensor type constants (see getSensors() for explanation)
static int SENSOR_TYPE_TOUCH
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Controller()
           
 
Method Summary
abstract  AbstractRobot getRobot()
          Returns the AbstractRobot associated with this controller
abstract  int[] getSensors()
          Returns an array of the sensors used by this controller, and the type of sensor required.
abstract  void halt()
          Stops this controller's thread running, i.e.
abstract  void initController(AbstractRobot r)
          Initialises controller.
abstract  void run()
          Starts this controller's thread running.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SENSOR_TYPE_LIGHT

public static int SENSOR_TYPE_LIGHT
Sensor type constants (see getSensors() for explanation)

SENSOR_TYPE_TOUCH

public static int SENSOR_TYPE_TOUCH
Constructor Detail

Controller

public Controller()
Method Detail

initController

public abstract void initController(AbstractRobot r)
Initialises controller. It should be noted that this method will only ever be called once, whereas run() can be called many times, so any variables or data structures etc. that are meant to persist in between stops and starts of the controller's thread, or that should only be initialised once should be set up from within this method, not in run().
Parameters:
r - the AbstractRobot associated with this controller

getSensors

public abstract int[] getSensors()
Returns an array of the sensors used by this controller, and the type of sensor required. This type must be one of the sensor type constants declared above. The index of the array is used to establish which sensor is being defined. e.g. if array[0] is SENSOR_TYPE_TOUCH then sensor 1 will be set to a touch sensor. The sensors array *must* be initialised with the correct values from the outset, and must not be set in initController(), or any other method. (see example Controllers for working examples)
Returns:
the sensor array

run

public abstract void run()
Starts this controller's thread running. The 'real' controller functionality should be started from here.
Overrides:
run in class java.lang.Thread

halt

public abstract void halt()
Stops this controller's thread running, i.e. must allow run() to return as quickly as possible. However it is acceptable for this method to do some housekeeping before stopping the controller, e.g. save some internal data strcuture to a file.

getRobot

public abstract AbstractRobot getRobot()
Returns the AbstractRobot associated with this controller
Returns:
the AbstractRobot