3PID::PID(
const double *pv,
double *cv,
const double *sp,
double Kp,
double Ki,
double Kd,
double Kf, uint16_t dt,
4 double cvMin,
double cvMax,
double a)
5 : pv(*pv), cv(*cv), sp(*sp), a(a), cvMin(cvMin), cvMax(cvMax) {
27 double delta = (
lastE + e) / 2;
54 if (
inAuto && !this->inAuto)
59void PID::setGains(
double Kp,
double Ki,
double Kd,
double Kf, uint16_t dt) {
64 this->Ki =
Ki *
dt / 1000;
65 this->Kd =
Kd / (
static_cast<double>(
dt) / 1000);
double & cv
Control variable.
void setAuto(bool inAuto)
Set the mode of the controller.
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].
const double & sp
Setpoint.
double a
Smoothing factor for EWA filter for derivative.
double lastE
Last value of error.
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.
double integral
Integral of pv.
double lastPv
Last value of pv.
double lastDPV
Last value of derivative term.
double cvMax
Lower/upper limits for cv.
const double & pv
Process variable.
void setGains(double Kp, double Ki, double Kd, double Kf, uint16_t dt)
Set the gains and timestep.