ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
PID Class Reference

Implements a proportional-integral-derivative (PID) controller. More...

#include <PID.h>

Public Member Functions

 PID ()
 Default constructor for PID, initializes gains to zero.
 
 PID (float kp, float ki, float kd)
 Constructs a PID controller with specified gains.
 
 ~PID ()
 Destructor for PID.
 
float Calculate (float setpoint, float processVariable, unsigned long currentMillis)
 Calculates the control output based on the setpoint and process variable.
 
float Calculate (float setpoint, float processVariable, float dT)
 Calculates the control output based on the setpoint and process variable.
 

Private Attributes

float integral
 Integral term accumulator.
 
float error
 Current error value.
 
float previousError
 Previous error value for derivative calculation.
 
float output
 Calculated output value.
 
float kp
 Proportional gain.
 
float ki
 Integral gain.
 
float kd
 Derivative gain.
 
float previousSeconds
 Time of the previous calculation in seconds.
 

Detailed Description

Implements a proportional-integral-derivative (PID) controller.

This class calculates control outputs based on the error between a setpoint and a process variable, using configurable proportional, integral, and derivative gains.

Definition at line 22 of file PID.h.

Constructor & Destructor Documentation

◆ PID() [1/2]

PID ( )

Default constructor for PID, initializes gains to zero.

Definition at line 3 of file PID.cpp.

◆ PID() [2/2]

PID ( float  kp,
float  ki,
float  kd 
)

Constructs a PID controller with specified gains.

Parameters
kpProportional gain.
kiIntegral gain.
kdDerivative gain.

Definition at line 13 of file PID.cpp.

◆ ~PID()

~PID ( )

Destructor for PID.

Definition at line 23 of file PID.cpp.

Member Function Documentation

◆ Calculate() [1/2]

float Calculate ( float  setpoint,
float  processVariable,
float  dT 
)

Calculates the control output based on the setpoint and process variable.

This method requires the caller to provide the time delta in seconds since the last calculation.

Parameters
setpointDesired target value.
processVariableCurrent value of the process variable.
dTTime delta in seconds since the last calculation.
Returns
Calculated control output.

Definition at line 46 of file PID.cpp.

References error, integral, kd, ki, kp, output, and previousError.

◆ Calculate() [2/2]

float Calculate ( float  setpoint,
float  processVariable,
unsigned long  currentMillis 
)

Calculates the control output based on the setpoint and process variable.

This method uses the elapsed time in milliseconds since the last call to calculate the derivative term.

Parameters
setpointDesired target value.
processVariableCurrent value of the process variable.
currentMillisCurrent time in milliseconds.
Returns
Calculated control output.

Definition at line 25 of file PID.cpp.

References error, integral, kd, ki, kp, output, previousError, and previousSeconds.

Member Data Documentation

◆ error

float error
private

Current error value.

Definition at line 25 of file PID.h.

Referenced by Calculate(), and Calculate().

◆ integral

float integral
private

Integral term accumulator.

Definition at line 24 of file PID.h.

Referenced by Calculate(), and Calculate().

◆ kd

float kd
private

Derivative gain.

Definition at line 30 of file PID.h.

Referenced by Calculate(), and Calculate().

◆ ki

float ki
private

Integral gain.

Definition at line 29 of file PID.h.

Referenced by Calculate(), and Calculate().

◆ kp

float kp
private

Proportional gain.

Definition at line 28 of file PID.h.

Referenced by Calculate(), and Calculate().

◆ output

float output
private

Calculated output value.

Definition at line 27 of file PID.h.

Referenced by Calculate(), and Calculate().

◆ previousError

float previousError
private

Previous error value for derivative calculation.

Definition at line 26 of file PID.h.

Referenced by Calculate(), and Calculate().

◆ previousSeconds

float previousSeconds
private

Time of the previous calculation in seconds.

Definition at line 31 of file PID.h.

Referenced by Calculate().


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