Class PIDController

java.lang.Object
com.stuypulse.stuylib.control.Controller
com.stuypulse.stuylib.control.feedback.PIDController

public class PIDController extends Controller
The PID algorithm is a feedback control algorithm meant for calculating an output based on an error between a measurement and a setpoint.

PID takes into account the error itself, the rate of change of error, and built-up error over time to create a stable controller.

Because it's a feedback algorithm, it will only react when the system is already behind (there must be error for there to be any output). *However, a feedback contrller can be easily combined with a feedforward model to reduce the delay.*

This PID controller is built by extending the Controller class. It has a dynamic rate, so it can detect how much time has passed between each update. It is made to be easy to use and simple to understand while still being accurate.

  • Constructor Details

    • PIDController

      public PIDController(Number p, Number i, Number d)
      Parameters:
      p - The Proportional Multiplier
      i - The Integral Multiplier
      d - The Derivative Multiplier
    • PIDController

      public PIDController()
      Creates a blank PIDController that doesn't move
  • Method Details

    • reset

      public void reset()
      Resets the integrator in the PIDController. This automatically gets called if the gap between update() commands is too large
    • calculate

      protected double calculate(double setpoint, double measurement)
      Description copied from class: Controller
      Calculates the output of the controller given a setpoint and measurement.
      Specified by:
      calculate in class Controller
      Parameters:
      setpoint - setpoint
      measurement - measurement
      Returns:
      calculated output
    • getP

      public double getP()
      Returns:
      the P value being used by the PID controller.
    • getI

      public double getI()
      Returns:
      the P value being used by the PID controller.
    • getD

      public double getD()
      Returns:
      the P value being used by the PID controller.
    • setP

      public PIDController setP(Number p)
      Parameters:
      p - new p value used by the PID controller.
      Returns:
      reference to PIDController (so you can chain the commands together)
    • setI

      public PIDController setI(Number i)
      Parameters:
      i - new i value used by the PID controller.
      Returns:
      reference to PIDController (so you can chain the commands together)
    • setD

      public PIDController setD(Number d)
      Parameters:
      d - new d value used by the PID controller.
      Returns:
      reference to PIDController (so you can chain the commands together)
    • setPID

      public PIDController setPID(Number p, Number i, Number d)
      Parameters:
      p - new p value used by the PID controller.
      i - new i value used by the PID controller.
      d - new d value used by the PID controller.
      Returns:
      reference to PIDController (so you can chain the commands together)
    • setPID

      public PIDController setPID(PIDController pidValues)
      Parameters:
      pidValues - PIDController that stores the PID values
      Returns:
      reference to PIDController (so you can chain the commands together)
    • setIntegratorFilter

      public PIDController setIntegratorFilter(Number range, Number limit)
      Add constraints to the integral of the PID Controller
      Parameters:
      range - the range of error in which the integral is allowed to accumulate (0 will disable)
      limit - the max / min the integral is allowed to accumulate to (0 will disables)
      Returns:
      reference to PIDController (so you can chain the commands together)
    • setDerivativeFilter

      public PIDController setDerivativeFilter(IFilter... derivativeFilter)
      Add a filter to the error velocity / derivative of the PID controller.
      Parameters:
      derivativeFilter - the filter to apply to derivative
      Returns:
      reference to PIDController (so you can chain the commands together)