Humidistat
Arduino firmware for a humidistat (humidity controller)
Loading...
Searching...
No Matches
PID Class Reference

PID controller in parallel form implemented in floating-point arithmetic. Features Derivative-on-Measurement, anti-windup through conditional integration, bumpless transfer, and feed-forward. More...

#include <PID.h>

Public Member Functions

 PID (const double *pv, double *cv, const double *sp, double Kp, double Ki, double Kd, double Kf, uint16_t dt, double cvMin, double cvMax, double a)
 Constructor.
 
bool compute ()
 Run a cycle of the PID loop.
 
void setAuto (bool inAuto)
 Set the mode of the controller.
 
void setGains (double Kp, double Ki, double Kd, double Kf, uint16_t dt)
 Set the gains and timestep.
 

Public Attributes

double pTerm = 0
 
double iTerm = 0
 
double dTerm = 0
 
double fTerm = 0
 PID terms.
 
double cvMin
 
double cvMax
 Lower/upper limits for cv.
 

Private Member Functions

void init ()
 Method to be called when the controller goes from manual to auto mode for proper bumpless transfer.
 
double clip (double value) const
 Clip value to [cvMin, cvMax].
 

Private Attributes

const double & pv
 Process variable.
 
double & cv
 Control variable.
 
const double & sp
 Setpoint.
 
double Kp
 
double Ki
 
double Kd
 
double Kf
 Gains.
 
double a
 Smoothing factor for EWA filter for derivative.
 
uint16_t dt
 Timestep.
 
bool inAuto = false
 Mode.
 
double lastPv
 Last value of pv.
 
double lastE
 Last value of error.
 
double lastDPV
 Last value of derivative term.
 
double integral
 Integral of pv.
 

Detailed Description

PID controller in parallel form implemented in floating-point arithmetic. Features Derivative-on-Measurement, anti-windup through conditional integration, bumpless transfer, and feed-forward.

Definition at line 8 of file PID.h.

Constructor & Destructor Documentation

◆ PID()

PID::PID ( const double * pv,
double * cv,
const double * sp,
double Kp,
double Ki,
double Kd,
double Kf,
uint16_t dt,
double cvMin,
double cvMax,
double a )

Constructor.

Parameters
pvPointer to process variable
cvPointer to control value
spPointer to setpoint
KpProportional gain
KiIntegral gain (in 1/s)
KdDerivative gain (in s)
KfFeed-forward gain
dtTimestep (in ms)
cvMinLower limit for control value
cvMaxUpper limit for control value
aSmoothing factor for EWA filter for derivative

Definition at line 3 of file PID.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ clip()

double PID::clip ( double value) const
private

Clip value to [cvMin, cvMax].

Parameters
valueValue to clip
Returns
Clipped value

Definition at line 44 of file PID.cpp.

Here is the caller graph for this function:

◆ compute()

bool PID::compute ( )

Run a cycle of the PID loop.

Returns
True if a PID step was run, and false if not.

Definition at line 17 of file PID.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void PID::init ( )
private

Method to be called when the controller goes from manual to auto mode for proper bumpless transfer.

Definition at line 9 of file PID.cpp.

Here is the caller graph for this function:

◆ setAuto()

void PID::setAuto ( bool inAuto)

Set the mode of the controller.

Parameters
inAutoSet to true for automatic, false for manual.

Definition at line 52 of file PID.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setGains()

void PID::setGains ( double Kp,
double Ki,
double Kd,
double Kf,
uint16_t dt )

Set the gains and timestep.

Parameters
KpProportional gain
KiIntegral gain (in 1/s)
KdDerivative gain (in s)
KfFeed-forward gain
dtTimestep (in ms)

Definition at line 59 of file PID.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ a

double PID::a
private

Smoothing factor for EWA filter for derivative.

Definition at line 15 of file PID.h.

◆ cv

double& PID::cv
private

Control variable.

Definition at line 11 of file PID.h.

◆ cvMax

double PID::cvMax

Lower/upper limits for cv.

Definition at line 34 of file PID.h.

◆ cvMin

double PID::cvMin

Definition at line 34 of file PID.h.

◆ dt

uint16_t PID::dt
private

Timestep.

Definition at line 16 of file PID.h.

◆ dTerm

double PID::dTerm = 0

Definition at line 33 of file PID.h.

◆ fTerm

double PID::fTerm = 0

PID terms.

Definition at line 33 of file PID.h.

◆ inAuto

bool PID::inAuto = false
private

Mode.

Definition at line 18 of file PID.h.

◆ integral

double PID::integral
private

Integral of pv.

Definition at line 22 of file PID.h.

◆ iTerm

double PID::iTerm = 0

Definition at line 33 of file PID.h.

◆ Kd

double PID::Kd
private

Definition at line 14 of file PID.h.

◆ Kf

double PID::Kf
private

Gains.

Definition at line 14 of file PID.h.

◆ Ki

double PID::Ki
private

Definition at line 14 of file PID.h.

◆ Kp

double PID::Kp
private

Definition at line 14 of file PID.h.

◆ lastDPV

double PID::lastDPV
private

Last value of derivative term.

Definition at line 21 of file PID.h.

◆ lastE

double PID::lastE
private

Last value of error.

Definition at line 20 of file PID.h.

◆ lastPv

double PID::lastPv
private

Last value of pv.

Definition at line 19 of file PID.h.

◆ pTerm

double PID::pTerm = 0

Definition at line 33 of file PID.h.

◆ pv

const double& PID::pv
private

Process variable.

Definition at line 10 of file PID.h.

◆ sp

const double& PID::sp
private

Setpoint.

Definition at line 12 of file PID.h.


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