|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
org.team751.framework.RobotTask
public abstract class RobotTask
A thread that contains a robot task. Operations in this task can safely block
without freezing the robot.
Note that the methods in this class are called as frequently as possible. You
must add a call to Thread.sleep(long)
or Timer.delay(double)
to prevent this task from running continuously and causing 100% CPU usage.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
static float |
kMinTaskTime
The minimum time, in seconds, that a task ( disabled() ,
autonomous() , or teleop() ) is
expected to take. |
private CompetitionState |
state
The current phase of competition |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
RobotTask()
|
Method Summary | |
---|---|
protected void |
autonomous()
The robot task handler calls this method as frequently as possible while the robot is in autonomous mode. |
protected void |
checkInterrupt()
Check if the thread has been interrupted. |
protected void |
disabled()
The robot task handler calls this method as frequently as possible while the robot is disabled. |
void |
run()
|
(package private) void |
setState(CompetitionState state)
Change this task's competition state If the new state is different from the current state, this method will call interrupt() to ensure that it knows about the new state. |
protected void |
teleop()
The robot task handler calls this method as frequently as possible while the robot is in teleoperated mode. |
private void |
timingWarning(java.lang.String methodName)
Print a warning to System.err telling the user that a task
didn't take long enough to complete and probably lacks a call to
Thread.sleep(long) or Timer.delay(double) . |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, clone, 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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private volatile CompetitionState state
public static final float kMinTaskTime
disabled()
,
autonomous()
, or teleop()
) is
expected to take. If one of those method calls takes less than this time,
it is likely that the programmer didn't use Thread.sleep(long)
or
Timer.delay(double)
to prevent continous task operation and 100%
CPU usage. In this event, a warning will be printed to System.err
.
Constructor Detail |
---|
public RobotTask()
Method Detail |
---|
public final void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
final void setState(CompetitionState state)
state
- The new state to setprotected void disabled() throws java.lang.InterruptedException
java.lang.InterruptedException
- If the task has been interrupted. You don't need to worry
about this. The robot task handler will deal with it.protected void autonomous() throws java.lang.InterruptedException
java.lang.InterruptedException
- If the task has been interrupted. You don't need to worry
about this. The robot task handler will deal with it.protected void teleop() throws java.lang.InterruptedException
java.lang.InterruptedException
- If the task has been interrupted. You don't need to worry
about this. The robot task handler will deal with it.protected final void checkInterrupt() throws java.lang.InterruptedException
Thread.sleep()
or anything else that throws an
InterruptedException
) to ensure that it responds quickly to
state changes. RobotTask.run()
and the state
will be checked again. // Do some operation try { checkInterrupt(); } catch (InterruptedException e) { // Clean up throw e; // Always re-throw so that the state will be rechecked }
java.lang.InterruptedException
- If the task has been interrupted. You don't need to worry
about this. The robot task handler will deal with it.private void timingWarning(java.lang.String methodName)
System.err
telling the user that a task
didn't take long enough to complete and probably lacks a call to
Thread.sleep(long)
or Timer.delay(double)
.
methodName
- The name of the method that was called, not including
parenthesis. For example, "disabled", "autonomous", or "teleop".
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |