Humidistat
Arduino firmware for a humidistat (humidity controller)
Loading...
Searching...
No Matches
PID.h
Go to the documentation of this file.
1#ifndef HUMIDISTAT_PID_H
2#define HUMIDISTAT_PID_H
3
4#include <stdint.h>
5
8class PID {
9private:
10 const double &pv;
11 double &cv;
12 const double &sp;
13
14 double Kp, Ki, Kd, Kf;
15 double a;
16 uint16_t dt;
17
18 bool inAuto = false;
19 double lastPv;
20 double lastE;
21 double lastDPV;
22 double integral;
23
25 void init();
26
30 double clip(double value) const;
31
32public:
33 double pTerm = 0, iTerm = 0, dTerm = 0, fTerm = 0;
34 double cvMin, cvMax;
35
48 PID(const double *pv, double *cv, const double *sp, double Kp, double Ki, double Kd, double Kf, uint16_t dt,
49 double cvMin, double cvMax, double a);
50
53 bool compute();
54
57 void setAuto(bool inAuto);
58
65 void setGains(double Kp, double Ki, double Kd, double Kf, uint16_t dt);
66};
67
68#endif //HUMIDISTAT_PID_H
PID controller in parallel form implemented in floating-point arithmetic. Features Derivative-on-Meas...
Definition PID.h:8
double & cv
Control variable.
Definition PID.h:11
void setAuto(bool inAuto)
Set the mode of the controller.
Definition PID.cpp:52
void init()
Method to be called when the controller goes from manual to auto mode for proper bumpless transfer.
Definition PID.cpp:9
double clip(double value) const
Clip value to [cvMin, cvMax].
Definition PID.cpp:44
double Kf
Gains.
Definition PID.h:14
const double & sp
Setpoint.
Definition PID.h:12
double a
Smoothing factor for EWA filter for derivative.
Definition PID.h:15
double Kp
Definition PID.h:14
double lastE
Last value of error.
Definition PID.h:20
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.
Definition PID.cpp:3
double iTerm
Definition PID.h:33
bool compute()
Run a cycle of the PID loop.
Definition PID.cpp:17
double integral
Integral of pv.
Definition PID.h:22
double Ki
Definition PID.h:14
double dTerm
Definition PID.h:33
double lastPv
Last value of pv.
Definition PID.h:19
double lastDPV
Last value of derivative term.
Definition PID.h:21
double cvMax
Lower/upper limits for cv.
Definition PID.h:34
uint16_t dt
Timestep.
Definition PID.h:16
bool inAuto
Mode.
Definition PID.h:18
double cvMin
Definition PID.h:34
const double & pv
Process variable.
Definition PID.h:10
void setGains(double Kp, double Ki, double Kd, double Kf, uint16_t dt)
Set the gains and timestep.
Definition PID.cpp:59
double Kd
Definition PID.h:14
double fTerm
PID terms.
Definition PID.h:33
double pTerm
Definition PID.h:33