Class PIDCommand

  • All Implemented Interfaces:
    Sendable, AutoCloseable

    public abstract class PIDCommand
    extends Command
    This class defines a Command which interacts heavily with a PID loop.

    It provides some convenience methods to run an internal PIDController . It will also start and stop said PIDController when the PIDCommand is first initialized and ended/interrupted.

    • Constructor Detail

      • PIDCommand

        public PIDCommand​(String name,
                          double p,
                          double i,
                          double d)
        Instantiates a PIDCommand that will use the given p, i and d values.
        Parameters:
        name - the name of the command
        p - the proportional value
        i - the integral value
        d - the derivative value
      • PIDCommand

        public PIDCommand​(String name,
                          double p,
                          double i,
                          double d,
                          double period)
        Instantiates a PIDCommand that will use the given p, i and d values. It will also space the time between PID loop calculations to be equal to the given period.
        Parameters:
        name - the name
        p - the proportional value
        i - the integral value
        d - the derivative value
        period - the time (in seconds) between calculations
      • PIDCommand

        public PIDCommand​(double p,
                          double i,
                          double d)
        Instantiates a PIDCommand that will use the given p, i and d values. It will use the class name as its name.
        Parameters:
        p - the proportional value
        i - the integral value
        d - the derivative value
      • PIDCommand

        public PIDCommand​(double p,
                          double i,
                          double d,
                          double period)
        Instantiates a PIDCommand that will use the given p, i and d values. It will use the class name as its name. It will also space the time between PID loop calculations to be equal to the given period.
        Parameters:
        p - the proportional value
        i - the integral value
        d - the derivative value
        period - the time (in seconds) between calculations
      • PIDCommand

        public PIDCommand​(String name,
                          double p,
                          double i,
                          double d,
                          Subsystem subsystem)
        Instantiates a PIDCommand that will use the given p, i and d values.
        Parameters:
        name - the name of the command
        p - the proportional value
        i - the integral value
        d - the derivative value
        subsystem - the subsystem that this command requires
      • PIDCommand

        public PIDCommand​(String name,
                          double p,
                          double i,
                          double d,
                          double period,
                          Subsystem subsystem)
        Instantiates a PIDCommand that will use the given p, i and d values. It will also space the time between PID loop calculations to be equal to the given period.
        Parameters:
        name - the name
        p - the proportional value
        i - the integral value
        d - the derivative value
        period - the time (in seconds) between calculations
        subsystem - the subsystem that this command requires
      • PIDCommand

        public PIDCommand​(double p,
                          double i,
                          double d,
                          Subsystem subsystem)
        Instantiates a PIDCommand that will use the given p, i and d values. It will use the class name as its name.
        Parameters:
        p - the proportional value
        i - the integral value
        d - the derivative value
        subsystem - the subsystem that this command requires
      • PIDCommand

        public PIDCommand​(double p,
                          double i,
                          double d,
                          double period,
                          Subsystem subsystem)
        Instantiates a PIDCommand that will use the given p, i and d values. It will use the class name as its name. It will also space the time between PID loop calculations to be equal to the given period.
        Parameters:
        p - the proportional value
        i - the integral value
        d - the derivative value
        period - the time (in seconds) between calculations
        subsystem - the subsystem that this command requires
    • Method Detail

      • setSetpointRelative

        public void setSetpointRelative​(double deltaSetpoint)
        Adds the given value to the setpoint. If setInputRange(...) was used, then the bounds will still be honored by this method.
        Parameters:
        deltaSetpoint - the change in the setpoint
      • setSetpoint

        protected void setSetpoint​(double setpoint)
        Sets the setpoint to the given value. If setInputRange(...) was called, then the given setpoint will be trimmed to fit within the range.
        Parameters:
        setpoint - the new setpoint
      • getSetpoint

        protected double getSetpoint()
        Returns the setpoint.
        Returns:
        the setpoint
      • getPosition

        protected double getPosition()
        Returns the current position.
        Returns:
        the current position
      • setInputRange

        protected void setInputRange​(double minimumInput,
                                     double maximumInput)
        Sets the maximum and minimum values expected from the input and setpoint.
        Parameters:
        minimumInput - the minimum value expected from the input and setpoint
        maximumInput - the maximum value expected from the input and setpoint
      • returnPIDInput

        protected abstract double returnPIDInput()
        Returns the input for the pid loop.

        It returns the input for the pid loop, so if this command was based off of a gyro, then it should return the angle of the gyro.

        All subclasses of PIDCommand must override this method.

        This method will be called in a different thread then the Scheduler thread.

        Returns:
        the value the pid loop should use as input
      • usePIDOutput

        protected abstract void usePIDOutput​(double output)
        Uses the value that the pid loop calculated. The calculated value is the "output" parameter. This method is a good time to set motor values, maybe something along the lines of driveline.tankDrive(output, -output)

        All subclasses of PIDCommand must override this method.

        This method will be called in a different thread then the Scheduler thread.

        Parameters:
        output - the value the pid loop calculated