Class Subsystem

  • All Implemented Interfaces:
    Sendable, AutoCloseable
    Direct Known Subclasses:

    public abstract class Subsystem
    extends SendableBase
    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:
    • Constructor Detail

      • Subsystem

        public Subsystem​(String name)
        Creates a subsystem with the given name.
        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

        public 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.

        command - the default command (or null if there should be none)
        IllegalUseOfCommandException - if the command does not require the subsystem
      • getDefaultCommand

        public Command getDefaultCommand()
        Returns the default command (or null if there is none).
        the default command
      • getDefaultCommandName

        public String getDefaultCommandName()
        Returns the default command name, or empty string is there is none.
        the default command name
      • getCurrentCommand

        public Command getCurrentCommand()
        Returns the command which currently claims this subsystem.
        the command which currently claims this subsystem
      • getCurrentCommandName

        public String getCurrentCommandName()
        Returns the current command name, or empty string if no current command.
        the current command name
      • addChild

        public void addChild​(String name,
                             Sendable child)
        Associate a Sendable with this Subsystem. Also update the child's name.
        name - name to give child
        child - sendable
      • addChild

        public void addChild​(Sendable child)
        Associate a Sendable with this Subsystem.
        child - sendable
      • initSendable

        public void initSendable​(SendableBuilder builder)
        Description copied from interface: Sendable
        Initializes this Sendable object.
        builder - sendable builder