Class CommandBase

java.lang.Object
edu.wpi.first.wpilibj2.command.CommandBase
All Implemented Interfaces:
Sendable, Command
Direct Known Subclasses:
ConditionalCommand, FunctionalCommand, MecanumControllerCommand, NotifierCommand, ParallelCommandGroup, ParallelDeadlineGroup, ParallelRaceGroup, PIDCommand, ProfiledPIDCommand, ProxyCommand, RamseteCommand, RepeatCommand, ScheduleCommand, SelectCommand, SequentialCommandGroup, SwerveControllerCommand, TrapezoidProfileCommand, WaitCommand, WaitUntilCommand, WrapperCommand

public abstract class CommandBase
extends Object
implements Sendable, Command
A Sendable base class for Commands.

This class is provided by the NewCommands VendorDep

  • Field Details

  • Constructor Details

  • Method Details

    • addRequirements

      public final void addRequirements​(Subsystem... requirements)
      Adds the specified subsystems to the requirements of the command. The scheduler will prevent two commands that require the same subsystem from being scheduled simultaneously.

      Note that the scheduler determines the requirements of a command when it is scheduled, so this method should normally be called from the command's constructor.

      Parameters:
      requirements - the requirements to add
    • getRequirements

      Description copied from interface: Command
      Specifies the set of subsystems used by this command. Two commands cannot use the same subsystem at the same time. If another command is scheduled that shares a requirement, Command.getInterruptionBehavior() will be checked and followed. If no subsystems are required, return an empty set.

      Note: it is recommended that user implementations contain the requirements as a field, and return that field here, rather than allocating a new set every time this is called.

      Specified by:
      getRequirements in interface Command
      Returns:
      the set of subsystems that are required
      See Also:
      Command.InterruptionBehavior
    • getName

      public String getName()
      Description copied from interface: Command
      Gets the name of this Command. Defaults to the simple class name if not overridden.
      Specified by:
      getName in interface Command
      Returns:
      The display name of the Command
    • setName

      public void setName​(String name)
      Sets the name of this Command.
      Specified by:
      setName in interface Command
      Parameters:
      name - name
    • getSubsystem

      public String getSubsystem()
      Gets the subsystem name of this Command.
      Returns:
      Subsystem name
    • setSubsystem

      public void setSubsystem​(String subsystem)
      Sets the subsystem name of this Command.
      Parameters:
      subsystem - subsystem name
    • initSendable

      public void initSendable​(SendableBuilder builder)
      Initializes this sendable. Useful for allowing implementations to easily extend SendableBase.
      Specified by:
      initSendable in interface Sendable
      Parameters:
      builder - the builder used to construct this sendable