edu.wpi.first.wpilibj.command
Class Scheduler

java.lang.Object
  extended by edu.wpi.first.wpilibj.command.Scheduler
All Implemented Interfaces:
SmartDashboardData, SmartDashboardNamedData

public class Scheduler
extends java.lang.Object
implements SmartDashboardNamedData

The Scheduler is a singleton which holds the top-level running commands. It is in charge of both calling the command's run() method and to make sure that there are no two commands with conflicting requirements running.

It is fine if teams wish to take control of the Scheduler themselves, all that needs to be done is to call Scheduler.getInstance().run() often to have Commands function correctly. However, this is already done for you if you use the CommandBased Robot template.

Author:
Joe Grinstead
See Also:
Command

Method Summary
 void add(Command command)
          Adds the command to the Scheduler.
 void addButton(Button.ButtonScheduler button)
          Adds a button to the Scheduler.
static Scheduler getInstance()
          Returns the Scheduler, creating it if one does not exist.
 java.lang.String getName()
          Returns the name of this object.
 NetworkTable getTable()
          Returns the NetworkTable associated with the data.
 java.lang.String getType()
          Returns the type of the data.
 void run()
          Runs a single iteration of the loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Scheduler getInstance()
Returns the Scheduler, creating it if one does not exist.

Returns:
the Scheduler

add

public void add(Command command)
Adds the command to the Scheduler. This will not add the Command immediately, but will instead wait for the proper time in the run() loop before doing so. The command returns immediately and does nothing if given null.

Adding a Command to the Scheduler involves the Scheduler removing any Command which has shared requirements.

Parameters:
command - the command to add

addButton

public void addButton(Button.ButtonScheduler button)
Adds a button to the Scheduler. The Scheduler will poll the button during its run().

Parameters:
button - the button to add

run

public void run()
Runs a single iteration of the loop. This method should be called often in order to have a functioning Command system. The loop has five stages:
  1. Poll the Buttons
  2. Execute/Remove the Commands
  3. Send values to SmartDashboard
  4. Add Commands
  5. Add Defaults


getName

public java.lang.String getName()
Description copied from interface: SmartDashboardNamedData
Returns the name of this object.

Specified by:
getName in interface SmartDashboardNamedData
Returns:
the name of this object

getType

public java.lang.String getType()
Description copied from interface: SmartDashboardData
Returns the type of the data. This is used by the SmartDashboard on the desktop to determine what to do with the table returned by getTable().

For instance, if the type was "Button", then the SmartDashboard would show the data as a button on the desktop and would know to look at and modify the "pressed" field in the NetworkTable returned by getTable().

Specified by:
getType in interface SmartDashboardData
Returns:
the type of the data

getTable

public NetworkTable getTable()
Description copied from interface: SmartDashboardData
Returns the NetworkTable associated with the data. The table should contain all the information the desktop version of SmartDashboard needs to interact with the object. The data should both keep the table up-to-date and also react to changes that the SmartDashboard might make.

For instance, the SendablePIDController will put its p, i and d values into its table and will change them if the table receives new values.

This method should return the same table between calls

Specified by:
getTable in interface SmartDashboardData
Returns:
the table that represents this data