Class PidController

java.lang.Object
org.wildstang.framework.pid.controller.PidController
Direct Known Subclasses:
SpeedPidController

public class PidController extends Object
Controller for PID motor control.
  • Constructor Details

    • PidController

      public PidController(IPidInput source, IPidOutput output, String pidControllerName)
      Constructs and initialized controller values.
      Parameters:
      source - IPidInput for PID control.
      output - IPidOutput for PID control.
      pidControllerName - Name of the controller.
  • Method Details

    • getP

      public double getP()
      Returns the P term.
      Returns:
      The P (proportional) term.
    • getI

      public double getI()
      Returns the I term.
      Returns:
      The I (integral) term.
    • getD

      public double getD()
      Returns the D term.
      Returns:
      The D (derivative) term.
    • getEpsilon

      public double getEpsilon()
      Returns epsilon.
      Returns:
      Epsilon, the allowable error in completion.
    • getStaticEpsilon

      public double getStaticEpsilon()
      Returns static epsilon.
      Returns:
      Static epsilon, the allowable error in steady-state.
    • setConstants

      public void setConstants(double p, double i, double d)
      Set the 3 PID constants.
      Parameters:
      p - Proportional - Proportional to the current value of the error.
      i - Integral - Accounts for past values of the error.
      d - Derivative - Best estimate of the future trend of the error.
    • setStaticEpsilon

      public void setStaticEpsilon(double epsilon)
      Sets static epsilon.
      Parameters:
      epsilon - Static epsilon, the allowable error in steady-state.
    • setErrorEpsilon

      public void setErrorEpsilon(double epsilon)
      Sets epsilon.
      Parameters:
      epsilon - Epsilon, the allowable error in completion.
    • setErrorIncrementPercentage

      public void setErrorIncrementPercentage(double inc)
      Sets error increment percentage.
      Parameters:
      inc - Error increment percentage, the max error increment per call.
    • setMinMaxOutput

      public void setMinMaxOutput(double min, double max)
      Sets the min and max output.
      Parameters:
      min - Minimum output, floor on PID output.
      max - Maximum output, ceiling on PID output.
    • setMinMaxInput

      public void setMinMaxInput(double min, double max)
      Sets the min and max input.
      Parameters:
      min - Minimum input, floor on PID input.
      max - Maximum input, ceiling on PID input.
    • setMaxIntegral

      public void setMaxIntegral(double max)
      Sets the max integral.
      Parameters:
      max - Max integral.
    • setIntegralErrorThresh

      public void setIntegralErrorThresh(double thresh)
      Sets the integral error threshold.
      Parameters:
      thresh - Intergral error threshold.
    • getIntegralErrorThresh

      public double getIntegralErrorThresh()
      Returns the integral error threshold.
      Returns:
      Intergral error threshold.
    • setMinStabilizationTime

      public void setMinStabilizationTime(double time)
      Sets the min stabilization time.
      Parameters:
      time - New min stabilization time.
    • setSetPoint

      public void setSetPoint(double set_point)
      Sets the set point.
      Parameters:
      set_point - The new set point.
    • getSetPoint

      public double getSetPoint()
      Returns the set point value.
      Returns:
      The current set point value.
    • setDifferentiatorBandLimit

      public void setDifferentiatorBandLimit(double band_limit)
      Sets the differentiator band limit.
      Parameters:
      band_limit - The new differentiator band limit.
    • getDifferentiatorBandLimit

      public double getDifferentiatorBandLimit()
      Returns the differentiator band limit.
      Returns:
      The current differentiator band limit.
    • resetErrorSum

      public void resetErrorSum()
      Resets the error sum to 0.
    • getCurrentOutput

      public double getCurrentOutput()
      Returns the current output value.
      Returns:
      The current output.
    • setOutputEnabled

      public void setOutputEnabled(boolean outputEnabled)
      Set output to enabled or disabled.
      Parameters:
      outputEnabled - True if set to enabled.
    • calcPid

      public void calcPid()
      Calculate PID.
    • isOnTarget

      public boolean isOnTarget()
      Returns true if the controller is in the target or stabilized state.
      Returns:
      True if the controller is target or stabilized.
    • isStabilized

      public boolean isStabilized()
      Returns true if the controller is in the stabilized state.
      Returns:
      True if the controller is stabilized.
    • isEnabled

      public boolean isEnabled()
      Returns true if the controller is in the enabled state.
      Returns:
      True if the controller is enabled.
    • enable

      public void enable()
      Puts the controller in the enabled state only if in the disabled state.
    • disable

      public void disable()
      Resets and put the controller in the disabled state.
    • reset

      public void reset()
      Resets all error values in controller.
    • getError

      public double getError()
      Returns the current error value.
      Returns:
      The current error value.
    • getPreviousError

      public double getPreviousError()
      Returns the previous error value.
      Returns:
      The previous error value.
    • calcDerivativeTerm

      protected double calcDerivativeTerm()
      Calculates the derivative term D based off errors.
      Returns:
      Estimated derivative term D.
    • getState

      public PidStateType getState()
      Returns the current state of the controller
      Returns:
      Current state.
    • notifyConfigChange

      public void notifyConfigChange()
      Notifys the controller of a config change. Controller then set values to config values.
    • getName

      public String getName()
      Returns the name of the controller.
      Returns:
      Controller name.
    • toString

      public String toString()
      Returns the name in combination with the PID state.
      Overrides:
      toString in class Object
      Returns:
      Name and PID state.