Class PIDCommand

  • All Implemented Interfaces:
    Sendable, Command

    public class PIDCommand
    extends CommandBase
    A command that controls an output with a PIDController. Runs forever by default - to add exit conditions and/or other behavior, subclass this class. The controller calculation and output are performed synchronously in the command's execute() method.
    • Constructor Detail

      • PIDCommand

        public PIDCommand​(PIDController controller,
                          DoubleSupplier measurementSource,
                          DoubleSupplier setpointSource,
                          DoubleConsumer useOutput,
                          Subsystem... requirements)
        Creates a new PIDCommand, which controls the given output with a PIDController.
        Parameters:
        controller - the controller that controls the output.
        measurementSource - the measurement of the process variable
        setpointSource - the controller's setpoint
        useOutput - the controller's output
        requirements - the subsystems required by this command
      • PIDCommand

        public PIDCommand​(PIDController controller,
                          DoubleSupplier measurementSource,
                          double setpoint,
                          DoubleConsumer useOutput,
                          Subsystem... requirements)
        Creates a new PIDCommand, which controls the given output with a PIDController.
        Parameters:
        controller - the controller that controls the output.
        measurementSource - the measurement of the process variable
        setpoint - the controller's setpoint
        useOutput - the controller's output
        requirements - the subsystems required by this command
    • Method Detail

      • initialize

        public void initialize()
        Description copied from interface: Command
        The initial subroutine of a command. Called once when the command is initially scheduled.
      • execute

        public void execute()
        Description copied from interface: Command
        The main body of a command. Called repeatedly while the command is scheduled.
      • end

        public void end​(boolean interrupted)
        Description copied from interface: Command
        The action to take when the command ends. Called when either the command finishes normally, or when it interrupted/canceled.

        Do not schedule commands here that share requirements with this command. Use Command.andThen(Command...) instead.

        Parameters:
        interrupted - whether the command was interrupted/canceled
      • getController

        public PIDController getController()
        Returns the PIDController used by the command.
        Returns:
        The PIDController