Class PidController
- java.lang.Object
-
- org.wildstang.framework.pid.controller.PidController
-
- Direct Known Subclasses:
SpeedPidController
public class PidController extends java.lang.ObjectController for PID motor control.
-
-
Constructor Summary
Constructors Constructor Description PidController(IPidInput source, IPidOutput output, java.lang.String pidControllerName)Constructs and initialized controller values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected doublecalcDerivativeTerm()Calculates the derivative term D based off errors.voidcalcPid()Calculate PID.voiddisable()Resets and put the controller in the disabled state.voidenable()Puts the controller in the enabled state only if in the disabled state.doublegetCurrentOutput()Returns the current output value.doublegetD()Returns the D term.doublegetDifferentiatorBandLimit()Returns the differentiator band limit.doublegetEpsilon()Returns epsilon.doublegetError()Returns the current error value.doublegetI()Returns the I term.doublegetIntegralErrorThresh()Returns the integral error threshold.java.lang.StringgetName()Returns the name of the controller.doublegetP()Returns the P term.doublegetPreviousError()Returns the previous error value.doublegetSetPoint()Returns the set point value.PidStateTypegetState()Returns the current state of the controllerdoublegetStaticEpsilon()Returns static epsilon.booleanisEnabled()Returns true if the controller is in the enabled state.booleanisOnTarget()Returns true if the controller is in the target or stabilized state.booleanisStabilized()Returns true if the controller is in the stabilized state.voidnotifyConfigChange()Notifys the controller of a config change.voidreset()Resets all error values in controller.voidresetErrorSum()Resets the error sum to 0.voidsetConstants(double p, double i, double d)Set the 3 PID constants.voidsetDifferentiatorBandLimit(double band_limit)Sets the differentiator band limit.voidsetErrorEpsilon(double epsilon)Sets epsilon.voidsetErrorIncrementPercentage(double inc)Sets error increment percentage.voidsetIntegralErrorThresh(double thresh)Sets the integral error threshold.voidsetMaxIntegral(double max)Sets the max integral.voidsetMinMaxInput(double min, double max)Sets the min and max input.voidsetMinMaxOutput(double min, double max)Sets the min and max output.voidsetMinStabilizationTime(double time)Sets the min stabilization time.voidsetOutputEnabled(boolean outputEnabled)Set output to enabled or disabled.voidsetSetPoint(double set_point)Sets the set point.voidsetStaticEpsilon(double epsilon)Sets static epsilon.java.lang.StringtoString()Returns the name in combination with the PID state.
-
-
-
Constructor Detail
-
PidController
public PidController(IPidInput source, IPidOutput output, java.lang.String pidControllerName)
Constructs and initialized controller values.- Parameters:
source- IPidInput for PID control.output- IPidOutput for PID control.pidControllerName- Name of the controller.
-
-
Method Detail
-
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 java.lang.String getName()
Returns the name of the controller.- Returns:
- Controller name.
-
toString
public java.lang.String toString()
Returns the name in combination with the PID state.- Overrides:
toStringin classjava.lang.Object- Returns:
- Name and PID state.
-
-