WPILibC++
unspecified
|
Class implements a PID Control Loop. More...
#include <PIDController.h>
Public Member Functions | |
PIDController (double p, double i, double d, PIDSource *source, PIDOutput *output, double period=0.05) | |
Allocate a PID object with the given constants for P, I, D. More... | |
PIDController (double p, double i, double d, double f, PIDSource *source, PIDOutput *output, double period=0.05) | |
Allocate a PID object with the given constants for P, I, D. More... | |
PIDController (const PIDController &)=delete | |
PIDController & | operator= (const PIDController)=delete |
virtual double | Get () const |
Return the current PID result. More... | |
virtual void | SetContinuous (bool continuous=true) |
Set the PID controller to consider the input to be continuous,. More... | |
virtual void | SetInputRange (double minimumInput, double maximumInput) |
Sets the maximum and minimum values expected from the input. More... | |
virtual void | SetOutputRange (double minimumOutput, double maximumOutput) |
Sets the minimum and maximum values to write. More... | |
void | SetPID (double p, double i, double d) override |
Set the PID Controller gain parameters. More... | |
virtual void | SetPID (double p, double i, double d, double f) |
Set the PID Controller gain parameters. More... | |
double | GetP () const override |
Get the Proportional coefficient. More... | |
double | GetI () const override |
Get the Integral coefficient. More... | |
double | GetD () const override |
Get the Differential coefficient. More... | |
virtual double | GetF () const |
Get the Feed forward coefficient. More... | |
void | SetSetpoint (double setpoint) override |
Set the setpoint for the PIDController. More... | |
double | GetSetpoint () const override |
Returns the current setpoint of the PIDController. More... | |
double | GetDeltaSetpoint () const |
Returns the change in setpoint over time of the PIDController. More... | |
virtual double | GetError () const |
Returns the current difference of the input from the setpoint. More... | |
virtual double | GetAvgError () const |
Returns the current average of the error over the past few iterations. More... | |
virtual void | SetPIDSourceType (PIDSourceType pidSource) |
Sets what type of input the PID controller will use. | |
virtual PIDSourceType | GetPIDSourceType () const |
Returns the type of input the PID controller is using. More... | |
virtual void | SetTolerance (double percent) |
virtual void | SetAbsoluteTolerance (double absValue) |
virtual void | SetPercentTolerance (double percentValue) |
virtual void | SetToleranceBuffer (int buf=1) |
virtual bool | OnTarget () const |
void | Enable () override |
Begin running the PIDController. | |
void | Disable () override |
Stop running the PIDController, this sets the output to zero before stopping. | |
bool | IsEnabled () const override |
Return true if PIDController is enabled. | |
void | Reset () override |
Reset the previous error, the integral term, and disable the controller. | |
void | InitTable (std::shared_ptr< ITable > subtable) override |
Initializes a table for this sendable object. More... | |
![]() | |
virtual void | ValueChangedEx (ITable *source, llvm::StringRef key, std::shared_ptr< nt::Value > value, unsigned int flags) |
Extended version of ValueChanged. More... | |
Protected Member Functions | |
virtual void | Calculate () |
Read the input, calculate the output accordingly, and write to the output. More... | |
virtual double | CalculateFeedForward () |
Calculate the feed forward term. More... | |
double | GetContinuousError (double error) const |
Wraps error around for continuous inputs. More... | |
Protected Attributes | |
PIDSource * | m_pidInput |
PIDOutput * | m_pidOutput |
std::shared_ptr< ITable > | m_table |
Class implements a PID Control Loop.
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.
PIDController::PIDController | ( | double | Kp, |
double | Ki, | ||
double | Kd, | ||
PIDSource * | source, | ||
PIDOutput * | output, | ||
double | period = 0.05 |
||
) |
Allocate a PID object with the given constants for P, I, D.
Kp | the proportional coefficient |
Ki | the integral coefficient |
Kd | the derivative coefficient |
source | The PIDSource object that is used to get values |
output | The PIDOutput object that is set to the output value |
period | the loop time for doing calculations. This particularly effects calculations of the integral and differental terms. The default is 50ms. |
PIDController::PIDController | ( | double | Kp, |
double | Ki, | ||
double | Kd, | ||
double | Kf, | ||
PIDSource * | source, | ||
PIDOutput * | output, | ||
double | period = 0.05 |
||
) |
Allocate a PID object with the given constants for P, I, D.
Kp | the proportional coefficient |
Ki | the integral coefficient |
Kd | the derivative coefficient |
source | The PIDSource object that is used to get values |
output | The PIDOutput object that is set to the output value |
period | the loop time for doing calculations. This particularly effects calculations of the integral and differental terms. The default is 50ms. |
|
protectedvirtual |
Read the input, calculate the output accordingly, and write to the output.
This should only be called by the Notifier.
|
protectedvirtual |
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).
|
virtual |
Return the current PID result.
This is always centered on zero and constrained the the max and min outs.
|
virtual |
Returns the current average of the error over the past few iterations.
You can specify the number of iterations to average with SetToleranceBuffer() (defaults to 1). This is the same value that is used for OnTarget().
|
protected |
Wraps error around for continuous inputs.
The original error is returned if continuous mode is disabled. This is an unsynchronized function.
error | The current error of the PID controller. |
|
overridevirtual |
double PIDController::GetDeltaSetpoint | ( | ) | const |
Returns the change in setpoint over time of the PIDController.
|
virtual |
Returns the current difference of the input from the setpoint.
|
virtual |
Get the Feed forward coefficient.
|
overridevirtual |
|
overridevirtual |
|
virtual |
Returns the type of input the PID controller is using.
|
overridevirtual |
Returns the current setpoint of the PIDController.
Implements frc::PIDInterface.
|
overridevirtual |
Initializes a table for this sendable object.
subtable | The table to put the values in. |
Implements frc::Sendable.
|
virtual |
Set the PID controller to consider the input to be continuous,.
Rather then using the max and min in as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint.
continuous | true turns on continuous, false turns off continuous |
|
virtual |
Sets the maximum and minimum values expected from the input.
minimumInput | the minimum value expected from the input |
maximumInput | the maximum value expected from the output |
|
virtual |
Sets the minimum and maximum values to write.
minimumOutput | the minimum value to write to the output |
maximumOutput | the maximum value to write to the output |
|
overridevirtual |
Set the PID Controller gain parameters.
Set the proportional, integral, and differential coefficients.
p | Proportional coefficient |
i | Integral coefficient |
d | Differential coefficient |
Implements frc::PIDInterface.
|
virtual |
Set the PID Controller gain parameters.
Set the proportional, integral, and differential coefficients.
p | Proportional coefficient |
i | Integral coefficient |
d | Differential coefficient |
f | Feed forward coefficient |
|
overridevirtual |
Set the setpoint for the PIDController.
Clears the queue for GetAvgError().
setpoint | the desired setpoint |
Implements frc::PIDInterface.