|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
rcx.josx.robotics.ActivityBase
rcx.josx.robotics.Activity
public abstract class Activity
An activity that operates in coordination with other activities. Only one activity can run at a time. When an activity of a higher priority wants to run any activities of a lower priority will be suppressed. Furthermore, if there is already an activity of the same or lower priority running, that activity will be stopped.
This is essentially an alternative way of implementing a Behavior or Subsumption architecture. It is totally distinct from the Behavior and Arbitrator classes and does not use either.
It works like this:
Example:
/** * When sensor one is pressed, run the motors in some pattern. */ class ControlMotors extends Activity implements SensorListener { public ControlMotors() { Sensor.S1.addSensorListener(this); } /** * Called when the sensor state changes (in some thread other than this one). */ public void stateChanged(Sensor s, int old, int nu) { if (old > nu) return; iWantToRun(); } /** * Encapsulates the actual activity we want to perform. * * @exception StopException if we are forcibly stopped. */ protected void action() throws StopException { boolean finished = false; // Sit here until we are finished or we are forcibly halted. while (!finished) { try { // spin Motor.C.forward(); Motor.A.backward(); // Wait for 0.25 secs, may throw InterruptedException pause(250); // Forward Motor.A.forward(); // We are finished finished = true; } catch (InterruptedException ie) { // pause() was interrupted. Re-start from the beginning } } } }
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary |
---|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
Activity()
|
Method Summary | |
---|---|
void |
run()
Thread entry point. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Activity()
Method Detail |
---|
public final void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |