TR-mbed 1.0
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
PID Class Reference

#include <PID.h>

Public Member Functions

 PID ()
 
 PID (float kP, float kI, float kD, float integralCap=0, float outputCap=0)
 
void setPID (float p, float i, float d, float integralCap=0, float outputCap=0)
 
void resetPID (float kP, float kI, float kD, float integralCap=0, float outputCap=0)
 
void resetErrorIntegral ()
 
int calculate (int desired, int current, double dt)
 
int calculatePeriodic (float error, double dt)
 
void limitOutput (double &PIDCalc) const
 
double limitErrorDerivative (double dTerm)
 
void limitErrorIntegral ()
 
void setDerivativeCap (float derivativeCap)
 
void setIntegralCap (float integralCap)
 
void setOutputCap (float outCap)
 

Public Attributes

float feedForward = 0
 
float pC
 
float iC
 
float dC = 0
 
lastfew dBuffer
 

Detailed Description

The PID class is used to implement PID (proportional, integral, derivative) control of a motor. It is used by almost every motor on the robot, and supports both position and velocity control.

Constructor & Destructor Documentation

◆ PID() [1/2]

PID::PID ( )

Creates a new PID object with the default control parameters

◆ PID() [2/2]

PID::PID ( float  kP,
float  kI,
float  kD,
float  integralCap = 0,
float  outputCap = 0 
)

Creates a new PID object with the given control parameters

Parameters
kPThe P (proportional) parameter
kIThe I (integral) parameter
kDThe D (derivative) parameter
integralCApThe maximum integral that can be achieved, above which the integral will be capped
outputCapThe maximum output of the PID, above which the output will be capped

Member Function Documentation

◆ calculate()

int PID::calculate ( int  desired,
int  current,
double  dt 
)

Calculates an output power based on the current and desired measurement (speed/position)

Parameters
desiredThe desired speed/position
currentThe current speed/position
dtThe time that has passed since the last calculation, in milliseconds
Returns
The output control power

◆ calculatePeriodic()

int PID::calculatePeriodic ( float  error,
double  dt 
)

◆ limitErrorDerivative()

double PID::limitErrorDerivative ( double  dTerm)

◆ limitErrorIntegral()

void PID::limitErrorIntegral ( )

◆ limitOutput()

void PID::limitOutput ( double &  PIDCalc) const

◆ resetErrorIntegral()

void PID::resetErrorIntegral ( )

◆ resetPID()

void PID::resetPID ( float  kP,
float  kI,
float  kD,
float  integralCap = 0,
float  outputCap = 0 
)

◆ setDerivativeCap()

void PID::setDerivativeCap ( float  derivativeCap)

Sets the integral cap

Parameters
derivativeCapThe new integral cap

◆ setIntegralCap()

void PID::setIntegralCap ( float  integralCap)

Sets the integral cap

Parameters
integralCapThe new integral cap

◆ setOutputCap()

void PID::setOutputCap ( float  outCap)

Sets the output cap

Parameters
outCapThe new output cap

◆ setPID()

void PID::setPID ( float  p,
float  i,
float  d,
float  integralCap = 0,
float  outputCap = 0 
)

Sets the P, I, and D control parameters

Parameters
pThe new P (proportional) parameter
iThe new I (integral) parameter
dThe new D (derivative) parameter

Member Data Documentation

◆ dBuffer

lastfew PID::dBuffer

◆ dC

float PID::dC = 0

◆ feedForward

float PID::feedForward = 0

◆ iC

float PID::iC

◆ pC

float PID::pC

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