Class PIDController

  • All Implemented Interfaces:
    Controller, PIDInterface, PIDOutput, Sendable, AutoCloseable

    public class PIDController
    extends PIDBase
    implements Controller
    Class implements a PID Control Loop.

    Creates a separate thread which reads the given PIDSource and takes care of the integral calculations, as well as writing the given PIDOutput.

    This feedback controller runs in discrete time, so time deltas are not used in the integral and derivative calculations. Therefore, the sample rate affects the controller's behavior for a given set of PID constants.

    • Constructor Detail

      • PIDController

        public PIDController​(double Kp,
                             double Ki,
                             double Kd,
                             double Kf,
                             PIDSource source,
                             PIDOutput output,
                             double period)
        Allocate a PID object with the given constants for P, I, D, and F.
        Parameters:
        Kp - the proportional coefficient
        Ki - the integral coefficient
        Kd - the derivative coefficient
        Kf - the feed forward term
        source - The PIDSource object that is used to get values
        output - The PIDOutput object that is set to the output percentage
        period - the loop time for doing calculations in seconds. This particularly affects calculations of the integral and differential terms. The default is 0.05 (50ms).
      • PIDController

        public PIDController​(double Kp,
                             double Ki,
                             double Kd,
                             PIDSource source,
                             PIDOutput output,
                             double period)
        Allocate a PID object with the given constants for P, I, D and period.
        Parameters:
        Kp - the proportional coefficient
        Ki - the integral coefficient
        Kd - the derivative coefficient
        source - the PIDSource object that is used to get values
        output - the PIDOutput object that is set to the output percentage
        period - the loop time for doing calculations in seconds. This particularly affects calculations of the integral and differential terms. The default is 0.05 (50ms).
      • PIDController

        public PIDController​(double Kp,
                             double Ki,
                             double Kd,
                             PIDSource source,
                             PIDOutput output)
        Allocate a PID object with the given constants for P, I, D, using a 50ms period.
        Parameters:
        Kp - the proportional coefficient
        Ki - the integral coefficient
        Kd - the derivative coefficient
        source - The PIDSource object that is used to get values
        output - The PIDOutput object that is set to the output percentage
      • PIDController

        public PIDController​(double Kp,
                             double Ki,
                             double Kd,
                             double Kf,
                             PIDSource source,
                             PIDOutput output)
        Allocate a PID object with the given constants for P, I, D, using a 50ms period.
        Parameters:
        Kp - the proportional coefficient
        Ki - the integral coefficient
        Kd - the derivative coefficient
        Kf - the feed forward term
        source - The PIDSource object that is used to get values
        output - The PIDOutput object that is set to the output percentage
    • Method Detail

      • enable

        public void enable()
        Begin running the PIDController.
        Specified by:
        enable in interface Controller
      • disable

        public void disable()
        Stop running the PIDController, this sets the output to zero before stopping.
        Specified by:
        disable in interface Controller
      • setEnabled

        public void setEnabled​(boolean enable)
        Set the enabled state of the PIDController.
      • isEnabled

        public boolean isEnabled()
        Return true if PIDController is enabled.
      • reset

        public void reset()
        Reset the previous error, the integral term, and disable the controller.
        Specified by:
        reset in interface PIDInterface
        Overrides:
        reset in class PIDBase