2019-04-12 09:45:12 +02:00
|
|
|
/** A PID controller.
|
|
|
|
*
|
|
|
|
* @file
|
2022-12-14 17:39:07 +01:00
|
|
|
* @author Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:05:42 -04:00
|
|
|
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
|
2022-05-19 17:40:10 +02:00
|
|
|
* @license Apache License 2.0
|
2019-04-12 09:45:12 +02:00
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace dsp {
|
|
|
|
|
|
|
|
class PID {
|
|
|
|
|
|
|
|
protected:
|
|
|
|
double dt;
|
2020-09-11 16:01:16 +02:00
|
|
|
double max;
|
|
|
|
double min;
|
|
|
|
double Kp;
|
|
|
|
double Kd;
|
|
|
|
double Ki;
|
|
|
|
double pre_error;
|
|
|
|
double integral;
|
2019-04-12 09:45:12 +02:00
|
|
|
|
|
|
|
public:
|
2023-04-03 10:00:02 +00:00
|
|
|
// Kp - proportional gain
|
|
|
|
// Ki - Integral gain
|
|
|
|
// Kd - derivative gain
|
|
|
|
// dt - loop interval time
|
|
|
|
// max - maximum value of manipulated variable
|
|
|
|
// min - minimum value of manipulated variable
|
2020-09-11 16:01:16 +02:00
|
|
|
PID(double _dt, double _max, double _min, double _Kp, double _Kd, double _Ki);
|
2019-04-12 09:45:12 +02:00
|
|
|
|
2023-04-03 10:00:02 +00:00
|
|
|
// Returns the manipulated variable given a setpoint and current process value
|
2020-09-11 16:01:16 +02:00
|
|
|
double calculate(double setpoint, double pv);
|
2019-04-12 09:45:12 +02:00
|
|
|
};
|
|
|
|
|
2022-12-02 17:16:44 +01:00
|
|
|
} // namespace dsp
|
|
|
|
} // namespace villas
|