ADBLib  0.5
A simple library for rapid robot code development
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
ADBLib::SimplePID Class Reference

#include <SimplePID.h>

Public Member Functions

 SimplePID (double p, double i, double d, bool continuous, double period=0.05)
 
 ~SimplePID ()
 
double getOutput ()
 
void setInputRange (double minimumInput, double maximumInput)
 
void setOutputRange (double mimimumOutput, double maximumOutput)
 
void setPID (double p, double i, double d)
 
void setMV (double mv)
 
void setSetpoint (double setpoint)
 
double setSetpoint ()
 
double setError ()
 
void setTolerance (double percent)
 
bool onTarget ()
 
void enable ()
 
void disable ()
 
void reset ()
 

Protected Member Functions

void calculate ()
 

Static Protected Member Functions

static void callCalculate (void *controller)
 

Protected Attributes

double m_P
 
double m_I
 
double m_D
 
double m_maximumOutput
 
double m_minimumOutput
 
double m_maximumInput
 
double m_minimumInput
 
bool m_continuous
 
bool m_enabled
 
double m_prevError
 
double m_totalError
 
double m_tolerance
 
double m_setpoint
 
double m_error
 
double m_result
 
double m_period
 
double m_measuredValue
 
Notifier * m_controlLoop
 

Detailed Description

Class for doing PID calculations without slaving an output into a PIDController object. Class originally by Parker Stebbins, adapted for use in ADBLib in 2016.

To use this class, first give it your PID values, select whether input is continuous, and select a control period (default is 50 ms). To provide sensor input, call setMV() and provide your sensor input. To set a setpoint, use setSetpoint(). To get the calculated value that your output should be set to, call getOutput().

Note
You MUST call enable(), all SimplePID objects start as DISABLED!

Constructor & Destructor Documentation

ADBLib::SimplePID::SimplePID ( double  Kp,
double  Ki,
double  Kd,
bool  continuous,
double  period = 0.05 
)

Create a PID object with the given constants for P, I, D. Default values for min/max IO are -1 and 1 respectively, continuous input is disabled, tolerance is set to 5%, and the SimplePID starts as disabled (zero output).

Parameters
KpThe proportional coefficient
KiThe integral coefficient
KdThe derivative coefficient
periodThe loop time for doing calculations in seconds. This particularly affects calculations of the integral and differential terms. The default is 50 ms.

Here is the call graph for this function:

ADBLib::SimplePID::~SimplePID ( )

Destroys this object.

Member Function Documentation

void ADBLib::SimplePID::calculate ( )
protected

Internal function. Performs necessary PID calculations.

Here is the caller graph for this function:

void ADBLib::SimplePID::callCalculate ( void *  controller)
staticprotected

Internal function. Calls the calculate function... for some reason.

Parameters
controllerA pointer to a SimplePID object.

Here is the call graph for this function:

Here is the caller graph for this function:

void ADBLib::SimplePID::disable ( )

Disables the SimplePID, zeroing output from getOutput().

Here is the caller graph for this function:

void ADBLib::SimplePID::enable ( )

Enables the SimplePID, starting output from getOutput().

double ADBLib::SimplePID::getOutput ( )

Gets the output as calculated using input and setpoint.

Returns
The output from the PID calculation. Give this to the object you want work with (eg. a motor).
bool ADBLib::SimplePID::onTarget ( )

Returns the status of whether this PID controller is on target or not to within tolerance set by the SetTolerance function. Tolerance is set at 5% by default. Calculation is done by getting the absolute value of error and checking whether it's less than the tolerance times the input range.

Returns
True for on-target, false otherwise.
void ADBLib::SimplePID::reset ( )

Resets the SimplePID, disabling it and resetting all error and calculated output.

Here is the call graph for this function:

double ADBLib::SimplePID::setError ( )
void ADBLib::SimplePID::setInputRange ( double  minimumInput,
double  maximumInput 
)

Sets the input range this object expects. For example. a gyro could output from -180 to 180, so you would call this function with Set

Parameters
minimumInputThe minimum input expected. Can be negative.
maximumInputThe maximum input expected.
Todo:
Investigate "SetSetpoint(m_setpoint)"

Here is the call graph for this function:

void ADBLib::SimplePID::setMV ( double  mv)

Sets the measured value, presumably from sensors.

Parameters
mvThe measured value as a double.
void ADBLib::SimplePID::setOutputRange ( double  minimumOutput,
double  maximumOutput 
)

Sets the output range delivered. For example, if you have a drivebase expecting values between -512 and 512, call this function with -512 and 512, respectively.

Parameters
minimumOutputThe minimum output delivered. Can be negative.
maximumOutputThe maximum output delivered.
void ADBLib::SimplePID::setPID ( double  p,
double  i,
double  d 
)

Sets PID constants.

Parameters
pThe proportional constant. Multiplied by the error.
iThe integral constant. Multiplied by the sum of error.
dThe derivative constant. Multiplied by the rate at which error is changing.
void ADBLib::SimplePID::setSetpoint ( double  setpoint)

Sets the point that PID calculations will try to work towards. This value should be somewhere within the output range, which by default is from -1 to 1. This function can and should be used similarly to motor set functions.

Parameters
setpointThe desired setpoint.
double ADBLib::SimplePID::setSetpoint ( )

Here is the caller graph for this function:

void ADBLib::SimplePID::setTolerance ( double  tolerance)

Sets the tolerance to error.

Parameters
toleranceTolerance as a percent (eg. 0.02)

Member Data Documentation

bool ADBLib::SimplePID::m_continuous
protected
Notifier* ADBLib::SimplePID::m_controlLoop
protected
double ADBLib::SimplePID::m_D
protected
bool ADBLib::SimplePID::m_enabled
protected
double ADBLib::SimplePID::m_error
protected
double ADBLib::SimplePID::m_I
protected
double ADBLib::SimplePID::m_maximumInput
protected
double ADBLib::SimplePID::m_maximumOutput
protected
double ADBLib::SimplePID::m_measuredValue
protected
double ADBLib::SimplePID::m_minimumInput
protected
double ADBLib::SimplePID::m_minimumOutput
protected
double ADBLib::SimplePID::m_P
protected
double ADBLib::SimplePID::m_period
protected
double ADBLib::SimplePID::m_prevError
protected
double ADBLib::SimplePID::m_result
protected
double ADBLib::SimplePID::m_setpoint
protected
double ADBLib::SimplePID::m_tolerance
protected
double ADBLib::SimplePID::m_totalError
protected

The documentation for this class was generated from the following files: