2019-04-12 09:45:12 +02:00
|
|
|
/** A PID controller.
|
|
|
|
*
|
|
|
|
* @file
|
2022-03-15 09:13:39 -04:00
|
|
|
* @author Steffen Vogel <svogel2@eonerc.rwth-aachen.de>
|
2022-03-15 09:05:42 -04:00
|
|
|
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
|
2019-04-12 09:45:12 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLAScommon
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#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:
|
2020-09-11 16:01:16 +02:00
|
|
|
/**
|
2019-04-12 09:45:12 +02:00
|
|
|
* Kp - proportional gain
|
2020-09-11 16:01:16 +02:00
|
|
|
* Ki - Integral gain
|
|
|
|
* Kd - derivative gain
|
|
|
|
* dt - loop interval time
|
|
|
|
* max - maximum value of manipulated variable
|
|
|
|
* min - minimum value of manipulated variable
|
2019-04-12 09:45:12 +02:00
|
|
|
*/
|
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
|
|
|
|
2020-09-11 16:01:16 +02:00
|
|
|
/** Returns the manipulated variable given a setpoint and current process value */
|
|
|
|
double calculate(double setpoint, double pv);
|
2019-04-12 09:45:12 +02:00
|
|
|
};
|
|
|
|
|
2019-05-28 10:50:50 +02:00
|
|
|
} /* namespace dsp */
|
|
|
|
} /* namespace villas */
|