Class CommandBuilder

java.lang.Object
edu.wpi.first.wpilibj2.command.Command
org.team1126.lib.util.command.CommandBuilder
All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable

public class CommandBuilder extends edu.wpi.first.wpilibj2.command.Command
A command builder. Very similar to FunctionalCommand. Stylistic alternative to using decorators.
  • Nested Class Summary

    Nested classes/interfaces inherited from class edu.wpi.first.wpilibj2.command.Command

    edu.wpi.first.wpilibj2.command.Command.InterruptionBehavior
  • Constructor Summary

    Constructors
    Constructor
    Description
    CommandBuilder(edu.wpi.first.wpilibj2.command.Subsystem... requirements)
    Create the command builder.
    CommandBuilder(String name, edu.wpi.first.wpilibj2.command.Subsystem... requirements)
    Create the command builder.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    end(boolean interrupted)
     
    void
     
    void
     
    boolean
     
    isFinished(boolean isFinished)
    Whether the command has finished.
    Whether the command has finished.
    onEnd(edu.wpi.first.util.function.BooleanConsumer onEnd)
    The action to take when the command ends.
    onEnd(Runnable onEnd)
    The action to take when the command ends.
    onExecute(Runnable onExecute)
    The main body of a command.
    onInitialize(Runnable onInitialize)
    The initial subroutine of a command.

    Methods inherited from class edu.wpi.first.wpilibj2.command.Command

    addRequirements, addRequirements, alongWith, andThen, andThen, asProxy, beforeStarting, beforeStarting, cancel, deadlineFor, deadlineWith, finallyDo, finallyDo, getInterruptionBehavior, getName, getRequirements, getSubsystem, handleInterrupt, hasRequirement, ignoringDisable, initSendable, isScheduled, onlyIf, onlyWhile, raceWith, repeatedly, runsWhenDisabled, schedule, setName, setSubsystem, unless, until, withDeadline, withInterruptBehavior, withName, withTimeout, withTimeout

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CommandBuilder

      public CommandBuilder(String name, edu.wpi.first.wpilibj2.command.Subsystem... requirements)
      Create the command builder.
      Parameters:
      name - The command's name.
      requirements - The subsystems required by the command.
    • CommandBuilder

      public CommandBuilder(edu.wpi.first.wpilibj2.command.Subsystem... requirements)
      Create the command builder.
      Parameters:
      requirements - The subsystems required by the command.
  • Method Details

    • onInitialize

      public CommandBuilder onInitialize(Runnable onInitialize)
      The initial subroutine of a command. Called once when the command is initially scheduled.
    • onExecute

      public CommandBuilder onExecute(Runnable onExecute)
      The main body of a command. Called repeatedly while the command is scheduled.
    • onEnd

      public CommandBuilder onEnd(Runnable onEnd)
      The action to take when the command ends. Called when either the command finishes normally, or when it interrupted/canceled.
    • onEnd

      public CommandBuilder onEnd(edu.wpi.first.util.function.BooleanConsumer onEnd)
      The action to take when the command ends. Called when either the command finishes normally, or when it interrupted/canceled. Supplied boolean is if the command was interrupted.
    • isFinished

      public CommandBuilder isFinished(boolean isFinished)
      Whether the command has finished. Once a command finishes, the scheduler will call its end() method and un-schedule it. By default, this returns false. If true, the command is effectively an InstantCommand. If false, the command will run continuously until it is canceled.
    • isFinished

      public CommandBuilder isFinished(BooleanSupplier isFinished)
      Whether the command has finished. Once a command finishes, the scheduler will call its end() method and un-schedule it. By default, this returns false.
    • initialize

      public void initialize()
      Overrides:
      initialize in class edu.wpi.first.wpilibj2.command.Command
    • execute

      public void execute()
      Overrides:
      execute in class edu.wpi.first.wpilibj2.command.Command
    • end

      public void end(boolean interrupted)
      Overrides:
      end in class edu.wpi.first.wpilibj2.command.Command
    • isFinished

      public boolean isFinished()
      Overrides:
      isFinished in class edu.wpi.first.wpilibj2.command.Command