Package edu.wpi.first.wpilibj.command
Class Scheduler
java.lang.Object
edu.wpi.first.wpilibj.command.Scheduler
- All Implemented Interfaces:
NTSendable
,Sendable
,AutoCloseable
public final class Scheduler extends Object implements NTSendable, AutoCloseable
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.
- See Also:
Command
-
Method Summary
Modifier and Type Method Description void
add(Command command)
Adds the command to theScheduler
.void
addButton(Trigger.ButtonScheduler button)
Adds a button to theScheduler
.void
close()
void
disable()
Disable the command scheduler.void
enable()
Enable the command scheduler.static Scheduler
getInstance()
Returns theScheduler
, creating it if one does not exist.void
initSendable(NTSendableBuilder builder)
Initializes thisSendable
object.void
removeAll()
Removes all commands.void
run()
Runs a single iteration of the loop.
-
Method Details
-
getInstance
Returns theScheduler
, creating it if one does not exist.- Returns:
- the
Scheduler
-
close
- Specified by:
close
in interfaceAutoCloseable
-
add
Adds the command to theScheduler
. This will not add theCommand
immediately, but will instead wait for the proper time in therun()
loop before doing so. The command returns immediately and does nothing if given null.Adding a
Command
to theScheduler
involves theScheduler
removing anyCommand
which has shared requirements.- Parameters:
command
- the command to add
-
addButton
- Parameters:
button
- the button to add
-
run
Runs a single iteration of the loop. This method should be called often in order to have a functioningCommand
system. The loop has five stages:- Poll the Buttons
- Execute/Remove the Commands
- Send values to SmartDashboard
- Add Commands
- Add Defaults
-
removeAll
Removes all commands. -
disable
Disable the command scheduler. -
enable
Enable the command scheduler. -
initSendable
Description copied from interface:NTSendable
Initializes thisSendable
object.- Specified by:
initSendable
in interfaceNTSendable
- Parameters:
builder
- sendable builder
-