WPILibC++
2018.4.1-1232-gce8c71b
|
Class implements a PID Control Loop. More...
#include <PIDBase.h>
Public Member Functions | |
PIDBase (double p, double i, double d, PIDSource &source, PIDOutput &output) | |
Allocate a PID object with the given constants for P, I, D. More... | |
PIDBase (double p, double i, double d, double f, PIDSource &source, PIDOutput &output) | |
Allocate a PID object with the given constants for P, I, D. More... | |
PIDBase (PIDBase &&)=default | |
PIDBase & | operator= (PIDBase &&)=default |
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... | |
void | SetP (double p) |
Set the Proportional coefficient of the PID controller gain. More... | |
void | SetI (double i) |
Set the Integral coefficient of the PID controller gain. More... | |
void | SetD (double d) |
Set the Differential coefficient of the PID controller gain. More... | |
void | SetF (double f) |
Get the Feed forward coefficient of the PID controller gain. 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 PIDBase. More... | |
double | GetSetpoint () const override |
Returns the current setpoint of the PIDBase. More... | |
double | GetDeltaSetpoint () const |
Returns the change in setpoint over time of the PIDBase. 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) |
Set the percentage error which is considered tolerable for use with OnTarget. More... | |
virtual void | SetAbsoluteTolerance (double absValue) |
Set the absolute error which is considered tolerable for use with OnTarget. More... | |
virtual void | SetPercentTolerance (double percentValue) |
Set the percentage error which is considered tolerable for use with OnTarget. More... | |
virtual void | SetToleranceBuffer (int buf=1) |
Set the number of previous error samples to average for tolerancing. More... | |
virtual bool | OnTarget () const |
Return true if the error is within the percentage of the total input range, determined by SetTolerance. More... | |
void | Reset () override |
Reset the previous error, the integral term, and disable the controller. | |
void | PIDWrite (double output) override |
Passes the output directly to SetSetpoint(). More... | |
void | InitSendable (SendableBuilder &builder) override |
Initializes this Sendable object. More... | |
![]() | |
SendableBase (bool addLiveWindow=true) | |
Creates an instance of the sensor base. More... | |
SendableBase (SendableBase &&rhs) | |
SendableBase & | operator= (SendableBase &&rhs) |
std::string | GetName () const final |
Gets the name of this Sendable object. More... | |
void | SetName (const wpi::Twine &name) final |
Sets the name of this Sendable object. More... | |
std::string | GetSubsystem () const final |
Gets the subsystem name of this Sendable object. More... | |
void | SetSubsystem (const wpi::Twine &subsystem) final |
Sets the subsystem name of this Sendable object. More... | |
![]() | |
Sendable (Sendable &&)=default | |
Sendable & | operator= (Sendable &&)=default |
void | SetName (const wpi::Twine &subsystem, const wpi::Twine &name) |
Sets both the subsystem name and device name of this Sendable object. More... | |
![]() | |
PIDInterface (PIDInterface &&)=default | |
PIDInterface & | operator= (PIDInterface &&)=default |
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... | |
![]() | |
void | AddChild (std::shared_ptr< Sendable > child) |
Add a child component. More... | |
void | AddChild (void *child) |
Add a child component. More... | |
void | SetName (const wpi::Twine &moduleType, int channel) |
Sets the name of the sensor with a channel number. More... | |
void | SetName (const wpi::Twine &moduleType, int moduleNumber, int channel) |
Sets the name of the sensor with a module and channel number. More... | |
Protected Attributes | |
bool | m_enabled = false |
wpi::mutex | m_thisMutex |
wpi::mutex | m_pidWriteMutex |
PIDSource * | m_pidInput |
PIDOutput * | m_pidOutput |
Timer | m_setpointTimer |
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.
|
protectedvirtual |
Read the input, calculate the output accordingly, and write to the output.
This should only be called by the Notifier.
Reimplemented in frc::SynchronousPID.
|
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 PIDBase 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 frc::PIDBase::GetDeltaSetpoint | ( | ) | const |
Returns the change in setpoint over time of the PIDBase.
|
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 PIDBase.
Implements frc::PIDInterface.
|
overridevirtual |
|
virtual |
Return true if the error is within the percentage of the total input range, determined by SetTolerance.
This asssumes that the maximum and minimum input were set using SetInput.
Currently this just reports on target as the actual value passes through the setpoint. Ideally it should be based on being within the tolerance for some period of time.
This will return false until at least one input value has been computed.
|
overridevirtual |
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().
Implements frc::PIDOutput.
|
virtual |
Set the absolute error which is considered tolerable for use with OnTarget.
percentage | error which is tolerable |
|
virtual |
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.
continuous | true turns on continuous, false turns off continuous |
void frc::PIDBase::SetD | ( | double | d | ) |
Set the Differential coefficient of the PID controller gain.
d | differential coefficient |
void frc::PIDBase::SetF | ( | double | f | ) |
Get the Feed forward coefficient of the PID controller gain.
f | Feed forward coefficient |
void frc::PIDBase::SetI | ( | double | i | ) |
Set the Integral coefficient of the PID controller gain.
i | integral coefficient |
|
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 |
void frc::PIDBase::SetP | ( | double | p | ) |
Set the Proportional coefficient of the PID controller gain.
p | proportional coefficient |
|
virtual |
Set the percentage error which is considered tolerable for use with OnTarget.
percentage | error which is tolerable |
|
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 PIDBase.
setpoint | the desired setpoint |
Implements frc::PIDInterface.
|
virtual |
Set the percentage error which is considered tolerable for use with OnTarget.
percentage | error which is tolerable |
|
virtual |
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.
bufLength | Number of previous cycles to average. Defaults to 1. |