Class PID

java.lang.Object
xbot.common.math.PID

public class PID extends Object
This PID was extracted from WPILib. It has all the same functionality, but does not run on its own separate thread.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PID()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    calculate(double goal, double current, double p, double i, double d)
    Calculates the output value given P,I,D, a process variable and a goal
    double
    calculate(double goal, double current, double p, double i, double d, double f)
    Calculates the output value given P,I,D, a process variable and a goal
    double
    calculate(double goal, double current, double p, double i, double d, double f, double iZone)
    Calculates the output value given P,I,D, a process variable and a goal
    Returns an enum explaining the reason the PID is not on target.
    boolean
     
    void
    Resets the PID controller.
    void
    setShouldCheckTolerances(boolean checkError, boolean checkDerivative, boolean checkTime)
    Controls whether or not the tolerances are checked as part of isOnTarget().
    void
    setTolerances(double errorTolerance, double derivativeTolerance, double timeToleranceInSeconds)
    Set tolerances for the PID system.

    Methods inherited from class java.lang.Object

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

    • PID

      public PID()
  • Method Details

    • reset

      public void reset()
      Resets the PID controller.
    • setTolerances

      public void setTolerances(double errorTolerance, double derivativeTolerance, double timeToleranceInSeconds)
      Set tolerances for the PID system.
      Parameters:
      errorTolerance - How close the error can be before it is considered "on-target." Negative values will cause that constraint to skipped when checking isOnTarget(). This is in the same units as your current and goal values.
      derivativeTolerance - Set how small the derivative of the error can be before it is considered "on-target." This is roughly in the same units as your current and goal values, but per 1/20th of a second. e.g. if you wanted a minimum rotation speed of 5 degrees per second, this tolerance would need to be 0.25.
    • setShouldCheckTolerances

      public void setShouldCheckTolerances(boolean checkError, boolean checkDerivative, boolean checkTime)
      Controls whether or not the tolerances are checked as part of isOnTarget().
    • calculate

      public double calculate(double goal, double current, double p, double i, double d, double f, double iZone)
      Calculates the output value given P,I,D, a process variable and a goal
      Parameters:
      goal - What value you are trying to achieve
      current - What the value under observation currently is
      p - Proportionate response
      i - Integral response.
      d - Derivative response.
      f - Feed-forward response
      Returns:
      The output value to achieve goal
    • calculate

      public double calculate(double goal, double current, double p, double i, double d, double f)
      Calculates the output value given P,I,D, a process variable and a goal
      Parameters:
      goal - What value you are trying to achieve
      current - What the value under observation currently is
      p - Proportionate response
      i - Integral response.
      d - Derivative response.
      f - Feed-forward response.
      Returns:
      The output value to achieve goal
    • calculate

      public double calculate(double goal, double current, double p, double i, double d)
      Calculates the output value given P,I,D, a process variable and a goal
      Parameters:
      goal - What value you are trying to achieve
      current - What the value under observation currently is
      p - Proportionate response
      i - Integral response.
      d - Derivative response.
      Returns:
      The output value to achieve goal
    • isOnTarget

      public boolean isOnTarget()
    • getOffTargetReason

      public PID.OffTargetReason getOffTargetReason()
      Returns an enum explaining the reason the PID is not on target. It has the following priority list if there are multiple reasons (higher ones overrule lower ones): - Too much error - Too much derivative - Waiting for time stability - On Target
      Returns:
      The reason the PID is not on target.