WPILibC++  2019.3.1
frc::PIDController Class Reference

Class implements a PID Control Loop. More...

#include <PIDController.h>

Inheritance diagram for frc::PIDController:

## 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 (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 (PIDController &&)=default

PIDControlleroperator= (PIDController &&)=default

void Enable () override
Begin running the PIDController.

void Disable () override
Stop running the PIDController, this sets the output to zero before stopping.

void SetEnabled (bool enable)
Set the enabled state of the PIDController.

bool IsEnabled () const
Return true if PIDController is enabled.

void Reset () override
Reset the previous error, the integral term, and disable the controller.

void InitSendable (SendableBuilder &builder) override
Initializes this Sendable object. More...

Public Member Functions inherited from frc::PIDBase
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

PIDBaseoperator= (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...

Public Member Functions inherited from frc::SendableBase
Creates an instance of the sensor base. More...

SendableBase (SendableBase &&rhs)

SendableBaseoperator= (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...

Public Member Functions inherited from frc::Sendable
Sendable (Sendable &&)=default

Sendableoperator= (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...

Public Member Functions inherited from frc::PIDInterface
PIDInterface (PIDInterface &&)=default

PIDInterfaceoperator= (PIDInterface &&)=default

Public Member Functions inherited from frc::Controller
Controller (Controller &&)=default

Controlleroperator= (Controller &&)=default

Protected Member Functions inherited from frc::PIDBase
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 Member Functions inherited from frc::SendableBase
void AddChild (std::shared_ptr< Sendable > child)

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 inherited from frc::PIDBase
bool m_enabled = false

wpi::mutex m_thisMutex

wpi::mutex m_pidWriteMutex

PIDSourcem_pidInput

PIDOutputm_pidOutput

Timer m_setpointTimer

## Detailed Description

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.

## Constructor & Destructor Documentation

 frc::PIDController::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.

Parameters
 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 in seconds. This particularly affects calculations of the integral and differental terms. The default is 0.05 (50ms).
 frc::PIDController::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.

Parameters
 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 in seconds. This particularly affects calculations of the integral and differental terms. The default is 0.05 (50ms).
 frc::PIDController::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.

Parameters
 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 in seconds. This particularly affects calculations of the integral and differental terms. The default is 0.05 (50ms).
 frc::PIDController::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.

Parameters
 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 in seconds. This particularly affects calculations of the integral and differental terms. The default is 0.05 (50ms).

## Member Function Documentation

 void frc::PIDController::InitSendable ( SendableBuilder & builder )
overridevirtual

Initializes this Sendable object.

Parameters
 builder sendable builder

Implements frc::Sendable.

The documentation for this class was generated from the following file:
• /var/lib/jenkins/workspace/WPILib/WPILib - Release/arm/wpilibc/src/main/native/include/frc/PIDController.h