PIController.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 //
6 // Created by reza on 04-01-21.
7 //
8 
9 #ifndef MERCURYDPM_PICONTROLLER_H
10 #define MERCURYDPM_PICONTROLLER_H
11 #include "Math/ExtendedMath.h"
12 
13 /*
14  * Applies a PI-controller,
15  * control = pGain * error + iGain * intError,
16  * with
17  * error = processVariable - setPoint
18  * and integrated error
19  * intError += error * timeStep.
20  *
21  * See https://en.wikipedia.org/wiki/Proportional%E2%80%93integral%E2%80%93derivative_controller
22  */
24  // the gain factor applied to the error
25  Mdouble pGain_ = 0.0;
26  // the gain factor applied the integrated error
27  Mdouble iGain_ = 0.0;
28  // the integrated error
30 
31 public:
32  // default constructor
33  PIControllerBasic () = default;
34  // constructor
35  PIControllerBasic(Mdouble pGain, Mdouble iGain) : pGain_(pGain), iGain_(iGain) {}
36  // sets pGain and iGain
37  void set(Mdouble pGain, Mdouble iGain);
38  // resets iError to zero
39  void reset ();
40  // returns the value of the control variable
41  Mdouble apply (Mdouble error, Mdouble timeStep);
42  // returns iError
43  double getIError() const { return iError_; }
44 };
45 
46 /*
47  * PI controller with error estimate
48  */
50  // the integrated error
52  unsigned nApplied_ = 0;
53 
54 public:
55  // default constructor
56  PIController () = default;
57  // constructor
58  PIController(Mdouble pGain, Mdouble iGain) : PIControllerBasic(pGain, iGain) {}
59  // resets iError to zero
60  void reset ();
61  // returns the value of the control variable
62  Mdouble apply (Mdouble error, Mdouble timeStep);
63  // returns variance of error
64  double getErrorVariance() const;
65  // returns variance of error
66  unsigned getNApplied() const;
67 };
68 
69 #endif //MERCURYDPM_PICONTROLLER_H
double Mdouble
Definition: GeneralDefine.h:13
Definition: PIController.h:23
Mdouble iError_
Definition: PIController.h:29
PIControllerBasic()=default
Mdouble iGain_
Definition: PIController.h:27
Mdouble apply(Mdouble error, Mdouble timeStep)
Definition: PIController.cc:25
PIControllerBasic(Mdouble pGain, Mdouble iGain)
Definition: PIController.h:35
Mdouble pGain_
Definition: PIController.h:25
void set(Mdouble pGain, Mdouble iGain)
Definition: PIController.cc:11
double getIError() const
Definition: PIController.h:43
void reset()
Definition: PIController.cc:36
Definition: PIController.h:49
Mdouble apply(Mdouble error, Mdouble timeStep)
Definition: PIController.cc:40
unsigned nApplied_
Definition: PIController.h:52
void reset()
Definition: PIController.cc:46
Mdouble sumErrorSquared_
Definition: PIController.h:51
unsigned getNApplied() const
Definition: PIController.cc:56
double getErrorVariance() const
Definition: PIController.cc:52
PIController()=default
PIController(Mdouble pGain, Mdouble iGain)
Definition: PIController.h:58
int error
Definition: calibrate.py:297