Package edu.wpi.first.wpilibj.command
Class Subsystem
java.lang.Object
edu.wpi.first.wpilibj.command.Subsystem
- All Implemented Interfaces:
Sendable,AutoCloseable
- Direct Known Subclasses:
PIDSubsystem
public abstract class Subsystem extends Object implements Sendable, AutoCloseable
This class defines a major component of the robot.
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.
- See Also:
Command
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidaddChild(Sendable child)Associate aSendablewith this Subsystem.voidaddChild(String name, Sendable child)Associate aSendablewith this Subsystem.voidclose()CommandgetCurrentCommand()Returns the command which currently claims this subsystem.StringgetCurrentCommandName()Returns the current command name, or empty string if no current command.CommandgetDefaultCommand()Returns the default command (or null if there is none).StringgetDefaultCommandName()Returns the default command name, or empty string is there is none.StringgetName()Gets the name of this Subsystem.StringgetSubsystem()Gets the subsystem name of this Subsystem.protected abstract voidinitDefaultCommand()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.voidinitSendable(SendableBuilder builder)Initializes thisSendableobject.voidperiodic()When the run method of the scheduler is called this method will be called.voidsetDefaultCommand(Command command)Sets the default command.voidsetName(String name)Sets the name of this Subsystem.voidsetSubsystem(String subsystem)Sets the subsystem name of this Subsystem.StringtoString()
-
Constructor Details
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable
-
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. It is called on all Subsystems by CommandBase in the users program after all the Subsystems are created. -
periodic
When the run method of the scheduler is called this method will be called. -
setDefaultCommand
Sets the default command. If this is not called or is called with null, then there will be no default command for the subsystem.WARNING: This should NOT be called in a constructor if the subsystem is a singleton.
- Parameters:
command- the default command (or null if there should be none)- Throws:
IllegalUseOfCommandException- if the command does not require the subsystem
-
getDefaultCommand
Returns the default command (or null if there is none).- Returns:
- the default command
-
getDefaultCommandName
Returns the default command name, or empty string is there is none.- Returns:
- the default command name
-
getCurrentCommand
Returns the command which currently claims this subsystem.- Returns:
- the command which currently claims this subsystem
-
getCurrentCommandName
Returns the current command name, or empty string if no current command.- Returns:
- the current command name
-
addChild
Associate aSendablewith this Subsystem. Also update the child's name.- Parameters:
name- name to give childchild- sendable
-
addChild
Associate aSendablewith this Subsystem.- Parameters:
child- sendable
-
getName
Gets the name of this Subsystem.- Returns:
- Name
-
setName
Sets the name of this Subsystem.- Parameters:
name- name
-
getSubsystem
Gets the subsystem name of this Subsystem.- Returns:
- Subsystem name
-
setSubsystem
Sets the subsystem name of this Subsystem.- Parameters:
subsystem- subsystem name
-
toString
-
initSendable
Description copied from interface:SendableInitializes thisSendableobject.- Specified by:
initSendablein interfaceSendable- Parameters:
builder- sendable builder
-