2023-08-28 12:31:18 +02:00
|
|
|
/* A PID controller.
|
2019-04-12 09:45:12 +02:00
|
|
|
*
|
2023-08-31 11:17:07 +02:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-08-28 12:31:18 +02:00
|
|
|
*/
|
2019-04-12 09:45:12 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace dsp {
|
|
|
|
|
|
|
|
class PID {
|
|
|
|
|
|
|
|
protected:
|
2023-09-07 13:19:19 +02:00
|
|
|
double dt;
|
|
|
|
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-09-07 13:19:19 +02: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
|
|
|
|
PID(double _dt, double _max, double _min, double _Kp, double _Kd, double _Ki);
|
2019-04-12 09:45:12 +02:00
|
|
|
|
2023-09-07 13:19:19 +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
|
|
|
};
|
|
|
|
|
2022-12-02 17:16:44 +01:00
|
|
|
} // namespace dsp
|
|
|
|
} // namespace villas
|