edu.wpi.first.wpilibj.command

## Class Subsystem

- java.lang.Object
- - edu.wpi.first.wpilibj.command.Subsystem

- All Implemented Interfaces:
    NamedSendable, Sendable
  Direct Known Subclasses:
    PIDSubsystem

      public abstract class Subsystem
      extends java.lang.Object
      implements NamedSendable

  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

    Constructors
    Constructor and Description
    `Subsystem()` Creates a subsystem.
    `Subsystem(java.lang.String name)` Creates a subsystem with the given name.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Command` | `getCurrentCommand()` Returns the command which currently claims this subsystem.
    `protected Command` | `getDefaultCommand()` Returns the default command (or null if there is none).
    `java.lang.String` | `getName()` Returns the name of this subsystem, which is by default the class name.
    `java.lang.String` | `getSmartDashboardType()` The string representation of the named data type that will be used by the smart dashboard for this `Sendable`.
    `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` | `initTable(NetworkTable table)` Initializes a table for this `Sendable` object.
    `void` | `periodic()` When the run method of the scheduler is called this method will be called.
    `protected void` | `setDefaultCommand(Command command)` Sets the default command.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Subsystem

          public Subsystem(java.lang.String name)

      Creates a subsystem with the given name.
      Parameters:
        `name` - the name of the subsystem

    - #### Subsystem

          public Subsystem()

      Creates a subsystem. This will set the name to the name of the class.

  - ### Method Detail

    - #### initDefaultCommand

          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. It is called on all Subsystems by CommandBase in the users program after all the Subsystems are created.

    - #### periodic

          public void periodic()

      When the run method of the scheduler is called this method will be called.

    - #### setDefaultCommand

          protected void setDefaultCommand(Command command)

      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

          protected Command getDefaultCommand()

      Returns the default command (or null if there is none).
      Returns:
        the default command

    - #### getCurrentCommand

          public Command getCurrentCommand()

      Returns the command which currently claims this subsystem.
      Returns:
        the command which currently claims this subsystem

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### getName

          public java.lang.String getName()

      Returns the name of this subsystem, which is by default the class name.
      Specified by:
        `getName` in interface `NamedSendable`
      Returns:
        the name of this subsystem

    - #### getSmartDashboardType

          public java.lang.String getSmartDashboardType()

      Description copied from interface: `Sendable`
      The string representation of the named data type that will be used by the smart dashboard for this `Sendable`.
      Specified by:
        `getSmartDashboardType` in interface `Sendable`
      Returns:
        The type of this `Sendable`.

    - #### initTable

          public void initTable(NetworkTable table)

      Description copied from interface: `Sendable`
      Initializes a table for this `Sendable` object.
      Specified by:
        `initTable` in interface `Sendable`
      Parameters:
        `table` - The table to put the values in.