public abstract class Subsystem extends SendableBase implements Sendable
A good example of a subsystem is the driveline, or a claw if the robot has one.
All motors should be a part of a subsystem. For instance, all the wheel motors should be a part of some kind of "Driveline" subsystem.
Subsystems are used within the command system as requirements for Command
. Only one
command which requires a subsystem can run at a time. Also, subsystems can have default commands
which are started if there is no command running which requires this subsystem.
Command
Constructor and Description |
---|
Subsystem()
Creates a subsystem.
|
Subsystem(java.lang.String name)
Creates a subsystem with the given name.
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(Sendable child)
Associate a
Sendable with this Subsystem. |
void |
addChild(java.lang.String name,
Sendable child)
Associate a
Sendable with this Subsystem. |
Command |
getCurrentCommand()
Returns the command which currently claims this subsystem.
|
java.lang.String |
getCurrentCommandName()
Returns the current command name, or empty string if no current command.
|
Command |
getDefaultCommand()
Returns the default command (or null if there is none).
|
java.lang.String |
getDefaultCommandName()
Returns the default command name, or empty string is there is none.
|
protected abstract void |
initDefaultCommand()
Initialize the default command for a subsystem By default subsystems have no default command,
but if they do, the default command is set with this method.
|
void |
initSendable(SendableBuilder builder)
Initializes this
Sendable object. |
void |
periodic()
When the run method of the scheduler is called this method will be called.
|
void |
setDefaultCommand(Command command)
Sets the default command.
|
java.lang.String |
toString() |
addChild, free, getName, getSubsystem, setName, setName, setName, setSubsystem
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getName, getSubsystem, setName, setName, setSubsystem
public Subsystem(java.lang.String name)
name
- the name of the subsystempublic Subsystem()
protected abstract void initDefaultCommand()
public void periodic()
public void setDefaultCommand(Command command)
WARNING: This should NOT be called in a constructor if the subsystem is a singleton.
command
- the default command (or null if there should be none)IllegalUseOfCommandException
- if the command does not require the subsystempublic Command getDefaultCommand()
public java.lang.String getDefaultCommandName()
public Command getCurrentCommand()
public java.lang.String getCurrentCommandName()
public void addChild(java.lang.String name, Sendable child)
Sendable
with this Subsystem.
Also update the child's name.name
- name to give childchild
- sendablepublic void addChild(Sendable child)
Sendable
with this Subsystem.child
- sendablepublic java.lang.String toString()
toString
in class java.lang.Object
public void initSendable(SendableBuilder builder)
Sendable
Sendable
object.initSendable
in interface Sendable
builder
- sendable builder