wpi-32u4-library
Public Member Functions | Protected Attributes
PIDController Class Reference

A generic PID controller. More...

#include <PIDcontroller.h>

Public Member Functions

 PIDController (float p, float i=0, float d=0, float bound=0)
 Constructor defaults to proportional only. More...
 
float calcEffort (float error)
 Used to calculate the effort from the error. More...
 
float setKp (float k)
 
float setKi (float k)
 
float setKd (float k)
 
float setCap (float cap)
 
void resetSum (void)
 

Protected Attributes

float Kp
 
float Ki
 
float Kd
 
float currError = 0
 
float prevError = 0
 
float sumError = 0
 
float errorBound = 0
 
float deltaT = 0
 
float currEffort = 0
 

Detailed Description

A generic PID controller.

If errorBound is non-zero, the integral will be capped at that value.

Definition at line 9 of file PIDcontroller.h.

Constructor & Destructor Documentation

◆ PIDController()

PIDController::PIDController ( float  p,
float  i = 0,
float  d = 0,
float  bound = 0 
)
inline

Constructor defaults to proportional only.

Definition at line 25 of file PIDcontroller.h.

Member Function Documentation

◆ calcEffort()

float PIDController::calcEffort ( float  error)

Used to calculate the effort from the error.

Parameters
errorThe current error (which is calculated in the calling code).

Definition at line 8 of file PIDcontroller.cpp.

References currEffort, currError, errorBound, Kd, Ki, Kp, prevError, and sumError.

Referenced by Romi32U4Motor::update().

◆ resetSum()

void PIDController::resetSum ( void  )
inline

Definition at line 34 of file PIDcontroller.h.

References sumError.

Referenced by Romi32U4Motor::setTargetSpeed().

◆ setCap()

float PIDController::setCap ( float  cap)
inline

Definition at line 33 of file PIDcontroller.h.

References errorBound.

◆ setKd()

float PIDController::setKd ( float  k)
inline

Definition at line 32 of file PIDcontroller.h.

References Kd.

◆ setKi()

float PIDController::setKi ( float  k)
inline

Definition at line 31 of file PIDcontroller.h.

References Ki, and sumError.

Referenced by Romi32U4Motor::setPIDCoeffients().

◆ setKp()

float PIDController::setKp ( float  k)
inline

Definition at line 30 of file PIDcontroller.h.

References Kp.

Referenced by Romi32U4Motor::setPIDCoeffients().

Field Documentation

◆ currEffort

float PIDController::currEffort = 0
protected

Definition at line 21 of file PIDcontroller.h.

Referenced by calcEffort().

◆ currError

float PIDController::currError = 0
protected

Definition at line 13 of file PIDcontroller.h.

Referenced by calcEffort().

◆ deltaT

float PIDController::deltaT = 0
protected

Definition at line 19 of file PIDcontroller.h.

◆ errorBound

float PIDController::errorBound = 0
protected

Definition at line 17 of file PIDcontroller.h.

Referenced by calcEffort(), and setCap().

◆ Kd

float PIDController::Kd
protected

Definition at line 12 of file PIDcontroller.h.

Referenced by calcEffort(), and setKd().

◆ Ki

float PIDController::Ki
protected

Definition at line 12 of file PIDcontroller.h.

Referenced by calcEffort(), and setKi().

◆ Kp

float PIDController::Kp
protected

Definition at line 12 of file PIDcontroller.h.

Referenced by calcEffort(), and setKp().

◆ prevError

float PIDController::prevError = 0
protected

Definition at line 14 of file PIDcontroller.h.

Referenced by calcEffort().

◆ sumError

float PIDController::sumError = 0
protected

Definition at line 16 of file PIDcontroller.h.

Referenced by calcEffort(), resetSum(), and setKi().


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