Class PIDBase
- All Implemented Interfaces:
Sendable
,PIDInterface
,PIDOutput
,AutoCloseable
- Direct Known Subclasses:
PIDController
@Deprecated(since="2020", forRemoval=true) public class PIDBase extends Object implements PIDInterface, PIDOutput, Sendable, AutoCloseable
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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
PIDBase.AbsoluteTolerance
Deprecated, for removal: This API element is subject to removal in a future version.static class
PIDBase.NullTolerance
Deprecated, for removal: This API element is subject to removal in a future version.Used internally for when Tolerance hasn't been set.class
PIDBase.PercentageTolerance
Deprecated, for removal: This API element is subject to removal in a future version.static interface
PIDBase.Tolerance
Deprecated, for removal: This API element is subject to removal in a future version.Tolerance is the type of tolerance used to specify if the PID controller is on target. -
Field Summary
Fields Modifier and Type Field Description static double
kDefaultPeriod
Deprecated, for removal: This API element is subject to removal in a future version.protected boolean
m_enabled
Deprecated, for removal: This API element is subject to removal in a future version.protected PIDSource
m_pidInput
Deprecated, for removal: This API element is subject to removal in a future version.protected PIDOutput
m_pidOutput
Deprecated, for removal: This API element is subject to removal in a future version.protected ReentrantLock
m_pidWriteMutex
Deprecated, for removal: This API element is subject to removal in a future version.protected Timer
m_setpointTimer
Deprecated, for removal: This API element is subject to removal in a future version.protected ReentrantLock
m_thisMutex
Deprecated, for removal: This API element is subject to removal in a future version. -
Constructor Summary
Constructors Constructor Description PIDBase(double Kp, double Ki, double Kd, double Kf, PIDSource source, PIDOutput output)
Deprecated, for removal: This API element is subject to removal in a future version.Allocate a PID object with the given constants for P, I, D, and F.PIDBase(double Kp, double Ki, double Kd, PIDSource source, PIDOutput output)
Deprecated, for removal: This API element is subject to removal in a future version.Allocate a PID object with the given constants for P, I, and D. -
Method Summary
Modifier and Type Method Description protected void
calculate()
Deprecated, for removal: This API element is subject to removal in a future version.Read the input, calculate the output accordingly, and write to the output.protected double
calculateFeedForward()
Deprecated, for removal: This API element is subject to removal in a future version.Calculate the feed forward term.void
close()
Deprecated, for removal: This API element is subject to removal in a future version.double
get()
Deprecated, for removal: This API element is subject to removal in a future version.Return the current PID result This is always centered on zero and constrained the the max and min outs.double
getAvgError()
Deprecated.Use getError(), which is now already filtered.protected double
getContinuousError(double error)
Deprecated, for removal: This API element is subject to removal in a future version.Wraps error around for continuous inputs.double
getD()
Deprecated, for removal: This API element is subject to removal in a future version.Get the Differential coefficient.double
getDeltaSetpoint()
Deprecated, for removal: This API element is subject to removal in a future version.Returns the change in setpoint over time of the PIDController.double
getError()
Deprecated, for removal: This API element is subject to removal in a future version.Returns the current difference of the input from the setpoint.double
getF()
Deprecated, for removal: This API element is subject to removal in a future version.Get the Feed forward coefficient.double
getI()
Deprecated, for removal: This API element is subject to removal in a future version.Get the Integral coefficient.double
getP()
Deprecated, for removal: This API element is subject to removal in a future version.Get the Proportional coefficient.PIDSourceType
getPIDSourceType()
Deprecated, for removal: This API element is subject to removal in a future version.Returns the type of input the PID controller is using.double
getSetpoint()
Deprecated, for removal: This API element is subject to removal in a future version.Returns the current setpoint of the PIDController.void
initSendable(SendableBuilder builder)
Deprecated, for removal: This API element is subject to removal in a future version.Initializes thisSendable
object.boolean
onTarget()
Deprecated, for removal: This API element is subject to removal in a future version.Return true if the error is within the percentage of the total input range, determined by setTolerance.void
pidWrite(double output)
Deprecated, for removal: This API element is subject to removal in a future version.Passes the output directly to setSetpoint().void
reset()
Deprecated, for removal: This API element is subject to removal in a future version.Reset the previous error, the integral term, and disable the controller.void
setAbsoluteTolerance(double absvalue)
Deprecated, for removal: This API element is subject to removal in a future version.Set the absolute error which is considered tolerable for use with OnTarget.void
setContinuous()
Deprecated, for removal: This API element is subject to removal in a future version.Set the PID controller to consider the input to be continuous, Rather then using the max and min input range as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint.void
setContinuous(boolean continuous)
Deprecated, for removal: This API element is subject to removal in a future version.Set the PID controller to consider the input to be continuous, Rather then using the max and min input range as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint.void
setD(double d)
Deprecated, for removal: This API element is subject to removal in a future version.Set the Differential coefficient of the PID controller gain.void
setF(double f)
Deprecated, for removal: This API element is subject to removal in a future version.Set the Feed forward coefficient of the PID controller gain.void
setI(double i)
Deprecated, for removal: This API element is subject to removal in a future version.Set the Integral coefficient of the PID controller gain.void
setInputRange(double minimumInput, double maximumInput)
Deprecated, for removal: This API element is subject to removal in a future version.Sets the maximum and minimum values expected from the input and setpoint.void
setOutputRange(double minimumOutput, double maximumOutput)
Deprecated, for removal: This API element is subject to removal in a future version.Sets the minimum and maximum values to write.void
setP(double p)
Deprecated, for removal: This API element is subject to removal in a future version.Set the Proportional coefficient of the PID controller gain.void
setPercentTolerance(double percentage)
Deprecated, for removal: This API element is subject to removal in a future version.Set the percentage error which is considered tolerable for use with OnTarget.void
setPID(double p, double i, double d)
Deprecated, for removal: This API element is subject to removal in a future version.Set the PID Controller gain parameters.void
setPID(double p, double i, double d, double f)
Deprecated, for removal: This API element is subject to removal in a future version.Set the PID Controller gain parameters.void
setPIDSourceType(PIDSourceType pidSource)
Deprecated, for removal: This API element is subject to removal in a future version.Sets what type of input the PID controller will use.void
setSetpoint(double setpoint)
Deprecated, for removal: This API element is subject to removal in a future version.Set the setpoint for the PIDController.void
setTolerance(PIDBase.Tolerance tolerance)
Deprecated.Use setPercentTolerance() instead.void
setToleranceBuffer(int bufLength)
Deprecated.Use a LinearFilter as the input.
-
Field Details
-
kDefaultPeriod
Deprecated, for removal: This API element is subject to removal in a future version.- See Also:
- Constant Field Values
-
m_enabled
Deprecated, for removal: This API element is subject to removal in a future version. -
m_thisMutex
Deprecated, for removal: This API element is subject to removal in a future version. -
m_pidWriteMutex
Deprecated, for removal: This API element is subject to removal in a future version. -
m_pidInput
Deprecated, for removal: This API element is subject to removal in a future version. -
m_pidOutput
Deprecated, for removal: This API element is subject to removal in a future version. -
m_setpointTimer
Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Constructor Details
-
PIDBase
Deprecated, for removal: This API element is subject to removal in a future version.Allocate a PID object with the given constants for P, I, D, and F.- Parameters:
Kp
- the proportional coefficientKi
- the integral coefficientKd
- the derivative coefficientKf
- the feed forward termsource
- The PIDSource object that is used to get valuesoutput
- The PIDOutput object that is set to the output percentage
-
PIDBase
Deprecated, for removal: This API element is subject to removal in a future version.Allocate a PID object with the given constants for P, I, and D.- Parameters:
Kp
- the proportional coefficientKi
- the integral coefficientKd
- the derivative coefficientsource
- the PIDSource object that is used to get valuesoutput
- the PIDOutput object that is set to the output percentage
-
-
Method Details
-
close
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
close
in interfaceAutoCloseable
-
calculate
Deprecated, for removal: This API element is subject to removal in a future version.Read the input, calculate the output accordingly, and write to the output. This should only be called by the PIDTask and is created during initialization. -
calculateFeedForward
Deprecated, for removal: This API element is subject to removal in a future version.Calculate the feed forward term.Both of the provided feed forward calculations are velocity feed forwards. If a different feed forward calculation is desired, the user can override this function and provide his or her own. This function does no synchronization because the PIDController class only calls it in synchronized code, so be careful if calling it oneself.
If a velocity PID controller is being used, the F term should be set to 1 over the maximum setpoint for the output. If a position PID controller is being used, the F term should be set to 1 over the maximum speed for the output measured in setpoint units per this controller's update period (see the default period in this class's constructor).
- Returns:
- The feedforward value.
-
setPID
Deprecated, for removal: This API element is subject to removal in a future version.Set the PID Controller gain parameters. Set the proportional, integral, and differential coefficients.- Specified by:
setPID
in interfacePIDInterface
- Parameters:
p
- Proportional coefficienti
- Integral coefficientd
- Differential coefficient
-
setPID
Deprecated, for removal: This API element is subject to removal in a future version.Set the PID Controller gain parameters. Set the proportional, integral, and differential coefficients.- Parameters:
p
- Proportional coefficienti
- Integral coefficientd
- Differential coefficientf
- Feed forward coefficient
-
setP
Deprecated, for removal: This API element is subject to removal in a future version.Set the Proportional coefficient of the PID controller gain.- Parameters:
p
- Proportional coefficient
-
setI
Deprecated, for removal: This API element is subject to removal in a future version.Set the Integral coefficient of the PID controller gain.- Parameters:
i
- Integral coefficient
-
setD
Deprecated, for removal: This API element is subject to removal in a future version.Set the Differential coefficient of the PID controller gain.- Parameters:
d
- differential coefficient
-
setF
Deprecated, for removal: This API element is subject to removal in a future version.Set the Feed forward coefficient of the PID controller gain.- Parameters:
f
- feed forward coefficient
-
getP
Deprecated, for removal: This API element is subject to removal in a future version.Get the Proportional coefficient.- Specified by:
getP
in interfacePIDInterface
- Returns:
- proportional coefficient
-
getI
Deprecated, for removal: This API element is subject to removal in a future version.Get the Integral coefficient.- Specified by:
getI
in interfacePIDInterface
- Returns:
- integral coefficient
-
getD
Deprecated, for removal: This API element is subject to removal in a future version.Get the Differential coefficient.- Specified by:
getD
in interfacePIDInterface
- Returns:
- differential coefficient
-
getF
Deprecated, for removal: This API element is subject to removal in a future version.Get the Feed forward coefficient.- Returns:
- feed forward coefficient
-
get
Deprecated, for removal: This API element is subject to removal in a future version.Return the current PID result This is always centered on zero and constrained the the max and min outs.- Returns:
- the latest calculated output
-
setContinuous
Deprecated, for removal: This API element is subject to removal in a future version.Set the PID controller to consider the input to be continuous, Rather then using the max and min input range as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint.- Parameters:
continuous
- Set to true turns on continuous, false turns off continuous
-
setContinuous
Deprecated, for removal: This API element is subject to removal in a future version.Set the PID controller to consider the input to be continuous, Rather then using the max and min input range as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint. -
setInputRange
Deprecated, for removal: This API element is subject to removal in a future version.Sets the maximum and minimum values expected from the input and setpoint.- Parameters:
minimumInput
- the minimum value expected from the inputmaximumInput
- the maximum value expected from the input
-
setOutputRange
Deprecated, for removal: This API element is subject to removal in a future version.Sets the minimum and maximum values to write.- Parameters:
minimumOutput
- the minimum percentage to write to the outputmaximumOutput
- the maximum percentage to write to the output
-
setSetpoint
Deprecated, for removal: This API element is subject to removal in a future version.Set the setpoint for the PIDController.- Specified by:
setSetpoint
in interfacePIDInterface
- Parameters:
setpoint
- the desired setpoint
-
getSetpoint
Deprecated, for removal: This API element is subject to removal in a future version.Returns the current setpoint of the PIDController.- Specified by:
getSetpoint
in interfacePIDInterface
- Returns:
- the current setpoint
-
getDeltaSetpoint
Deprecated, for removal: This API element is subject to removal in a future version.Returns the change in setpoint over time of the PIDController.- Returns:
- the change in setpoint over time
-
getError
Deprecated, for removal: This API element is subject to removal in a future version.Returns the current difference of the input from the setpoint.- Specified by:
getError
in interfacePIDInterface
- Returns:
- the current error
-
getAvgError
Deprecated.Use getError(), which is now already filtered.Returns the current difference of the error over the past few iterations. You can specify the number of iterations to average with setToleranceBuffer() (defaults to 1). getAvgError() is used for the onTarget() function.- Returns:
- the current average of the error
-
setPIDSourceType
Deprecated, for removal: This API element is subject to removal in a future version.Sets what type of input the PID controller will use.- Parameters:
pidSource
- the type of input
-
getPIDSourceType
Deprecated, for removal: This API element is subject to removal in a future version.Returns the type of input the PID controller is using.- Returns:
- the PID controller input type
-
setTolerance
Deprecated.Use setPercentTolerance() instead.Set the PID tolerance using a Tolerance object. Tolerance can be specified as a percentage of the range or as an absolute value. The Tolerance object encapsulates those options in an object. Use it by creating the type of tolerance that you want to use: setTolerance(new PIDController.AbsoluteTolerance(0.1))- Parameters:
tolerance
- A tolerance object of the right type, e.g. PercentTolerance or AbsoluteTolerance
-
setAbsoluteTolerance
Deprecated, for removal: This API element is subject to removal in a future version.Set the absolute error which is considered tolerable for use with OnTarget.- Parameters:
absvalue
- absolute error which is tolerable in the units of the input object
-
setPercentTolerance
Deprecated, for removal: This API element is subject to removal in a future version.Set the percentage error which is considered tolerable for use with OnTarget. (Input of 15.0 = 15 percent)- Parameters:
percentage
- percent error which is tolerable
-
setToleranceBuffer
Deprecated.Use a LinearFilter as the input.Set the number of previous error samples to average for tolerancing. When determining whether a mechanism is on target, the user may want to use a rolling average of previous measurements instead of a precise position or velocity. This is useful for noisy sensors which return a few erroneous measurements when the mechanism is on target. However, the mechanism will not register as on target for at least the specified bufLength cycles.- Parameters:
bufLength
- Number of previous cycles to average.
-
onTarget
Deprecated, for removal: This API element is subject to removal in a future version.Return true if the error is within the percentage of the total input range, determined by setTolerance. This assumes that the maximum and minimum input were set using setInput.- Returns:
- true if the error is less than the tolerance
-
reset
Deprecated, for removal: This API element is subject to removal in a future version.Reset the previous error, the integral term, and disable the controller.- Specified by:
reset
in interfacePIDInterface
-
pidWrite
Deprecated, for removal: This API element is subject to removal in a future version.Passes the output directly to setSetpoint().PIDControllers can be nested by passing a PIDController as another PIDController's output. In that case, the output of the parent controller becomes the input (i.e., the reference) of the child.
It is the caller's responsibility to put the data into a valid form for setSetpoint().
-
initSendable
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:Sendable
Initializes thisSendable
object.- Specified by:
initSendable
in interfaceSendable
- Parameters:
builder
- sendable builder
-
getContinuousError
Deprecated, for removal: This API element is subject to removal in a future version.Wraps error around for continuous inputs. The original error is returned if continuous mode is disabled. This is an unsynchronized function.- Parameters:
error
- The current error of the PID controller.- Returns:
- Error for continuous inputs.
-