Public Member Functions | Protected Attributes

CxUtils::PIDController Class Reference

A generic PID controller. This can be used for any application that needs to handle oscillations using a PID controller. Specific examples using a PID controller are maintain velocity, heading, or position. More...

#include <pidcontroller.h>

List of all members.

Public Member Functions

 PIDController ()
 Constructor.
 ~PIDController ()
 Destructor.
void SetRate (const double dt=1.0)
 Set the update interval for PID constants.
double UpdatePID (const double error)
 Uses error feedback to provide new input to the system.
void SetOffset (const double offset)
 Sets any desired offset for calculating solution from the PID.
void SetBounds (const double min, const double max)
 Sets boundaries for the solutions the PID can calculate.
void SetGains (const double p, const double i, const double d)
 Sets the PID gain values of your controller.
void ClearError ()
 Clears out any summed error.
void Reset ()
 Sets all values back to defaults.
void Reset (const double lower, const double upper, const double offset, const double p, const double i, const double d)
 Resets the sum of errors, and configures the controller based on the inputs.
double GetProportionalGain () const
double GetIntegralGrain () const
double GetDifferentialGain () const
double GetSumOfError () const
double GetOffset () const
double GetLowerBound () const
double GetUpperBound () const

Protected Attributes

double mPreviousError
 Previous error of system.
double mPreviousSolution
 Previous feedback result (used with upper and lower bounds to prevent winding)
double mP
 Proportional Gain.
double mI
 Integral Gain.
double mD
 Differential Gain.
double mSumOfError
 Sum of error.
double mOffset
 Offset to add onto solution (default 0)
double mUpperBound
 Upper bound on solution (prevents winding/large sum of errors) default is INFINITE.
double mLowerBound
 Lower bound on solution (prevents winding/large sum of erros) default is -INFINITE.
double mDT
 DT term.

Detailed Description

A generic PID controller. This can be used for any application that needs to handle oscillations using a PID controller. Specific examples using a PID controller are maintain velocity, heading, or position.

This controller does not calculate the error for your specific application, instead it takes the error as an argument to the UpdatePID function, which returns the new solution to use in your closed loop process.

Definition at line 62 of file pidcontroller.h.


Constructor & Destructor Documentation

PIDController::PIDController (  )

Constructor.

Definition at line 52 of file pidcontroller.cpp.

PIDController::~PIDController (  )

Destructor.

Definition at line 65 of file pidcontroller.cpp.


Member Function Documentation

void PIDController::ClearError (  )

Clears out any summed error.

Definition at line 200 of file pidcontroller.cpp.

double CxUtils::PIDController::GetDifferentialGain (  ) const [inline]

Definition at line 94 of file pidcontroller.h.

double CxUtils::PIDController::GetIntegralGrain (  ) const [inline]

Definition at line 93 of file pidcontroller.h.

double CxUtils::PIDController::GetLowerBound (  ) const [inline]

Definition at line 97 of file pidcontroller.h.

double CxUtils::PIDController::GetOffset (  ) const [inline]

Definition at line 96 of file pidcontroller.h.

double CxUtils::PIDController::GetProportionalGain (  ) const [inline]

Definition at line 92 of file pidcontroller.h.

double CxUtils::PIDController::GetSumOfError (  ) const [inline]

Definition at line 95 of file pidcontroller.h.

double CxUtils::PIDController::GetUpperBound (  ) const [inline]

Definition at line 98 of file pidcontroller.h.

void PIDController::Reset ( const double  lower,
const double  upper,
const double  offset,
const double  p,
const double  i,
const double  d 
)

Resets the sum of errors, and configures the controller based on the inputs.

Parameters:
lowerLower bound of system inputs
upperUpper bound of system inputs
offsetOffset to add to system input solutions
pThe proportional gain
iThe integral gain
dThe derivative gain

Definition at line 239 of file pidcontroller.cpp.

void PIDController::Reset (  )

Sets all values back to defaults.

Definition at line 211 of file pidcontroller.cpp.

void PIDController::SetBounds ( const double  min,
const double  max 
)

Sets boundaries for the solutions the PID can calculate.

For example, if the inputs you want to provide your system are between [-100,100], then your offset would be 0, and you would have upper and lower bounds of [-100,100]. If your system was [50, 150], you would have an offset of 50, with upper and lower bounds of [50,150].

Parameters:
minThe lower bound of your system inputs
maxThe upper bound of your system inputs

Definition at line 164 of file pidcontroller.cpp.

void PIDController::SetGains ( const double  p,
const double  i,
const double  d 
)

Sets the PID gain values of your controller.

By adjusting these values you can increase or decrease the performance of the PID controller. You should have a limited understanding of how to adjust these values before doing so.

Parameters:
pThe proportional gain
iThe integral gain
dThe derivative gain

Definition at line 187 of file pidcontroller.cpp.

void PIDController::SetOffset ( const double  offset )

Sets any desired offset for calculating solution from the PID.

For example, if the inputs you want to provide your system are between [-100,100], then your offset would be 0, and you would have upper and lower bounds of [-100,100]. If your system was [50, 150], you would have an offset of 50, with upper and lower bounds of [50,150].

Parameters:
offsetThe offset to add to the PID solutions.

Definition at line 145 of file pidcontroller.cpp.

void PIDController::SetRate ( const double  dt = 1.0 )

Set the update interval for PID constants.

Parameters:
[in]dtDelta Time variable for PID calculations, default is 1.

Definition at line 77 of file pidcontroller.cpp.

double PIDController::UpdatePID ( const double  error )

Uses error feedback to provide new input to the system.

This function performs the calculations of the PID controller. It checks to make sure the returned value is within the bounds of the maximum and minimum values your system can take. The upper and lower bounds can be set using the setBounds function.

The error provided should be the error of your system between desired and actual. This controller does not calculate error so that it can be kept generic. The results of this function are only as good as the PID gain values that model your system.

Parameters:
errorThe feedback error of the system.
Returns:
The output to provide your system from the PID controller.

Definition at line 102 of file pidcontroller.cpp.


Member Data Documentation

double CxUtils::PIDController::mD [protected]

Differential Gain.

Definition at line 104 of file pidcontroller.h.

double CxUtils::PIDController::mDT [protected]

DT term.

Definition at line 109 of file pidcontroller.h.

double CxUtils::PIDController::mI [protected]

Integral Gain.

Definition at line 103 of file pidcontroller.h.

Lower bound on solution (prevents winding/large sum of erros) default is -INFINITE.

Definition at line 108 of file pidcontroller.h.

double CxUtils::PIDController::mOffset [protected]

Offset to add onto solution (default 0)

Definition at line 106 of file pidcontroller.h.

double CxUtils::PIDController::mP [protected]

Proportional Gain.

Definition at line 102 of file pidcontroller.h.

Previous error of system.

Definition at line 100 of file pidcontroller.h.

Previous feedback result (used with upper and lower bounds to prevent winding)

Definition at line 101 of file pidcontroller.h.

Sum of error.

Definition at line 105 of file pidcontroller.h.

Upper bound on solution (prevents winding/large sum of errors) default is INFINITE.

Definition at line 107 of file pidcontroller.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines