Last active
June 11, 2019 12:10
-
-
Save tanitanin/a4c6a7722bb31e91bf562a7d8a5ff4a6 to your computer and use it in GitHub Desktop.
Discrete-Time PID https://jp.mathworks.com/help/control/ug/discrete-time-proportional-integral-derivative-pid-controller.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <integrator.h> | |
template<typename T> | |
class PIDStd2 { | |
T Kp; | |
T Ti; | |
T Td; | |
T N; | |
T b; | |
T c; | |
T Ts; | |
DescreteTimeIntegrator<T> IF; | |
DescreteTimeIntegrator<T> DF; | |
public: | |
PIDStd2(T kp, T ti, T td, T n, T b, T c, T ts, T reference=T(), T initial=T()) : Kp(kp), Ti(ti), Td(td), N(n), b(b), c(c), IF(1, ts), DF(1, ts) { | |
IF.reset(reference - initial); | |
DF.reset(c * reference - initial); | |
} | |
T update(T reference, T input) { | |
auto u = Kp * ( (b * reference - input) + 1 / Ti * IF.update(reference - input) + Td / (Td / N + DF.update(c * reference - input)) ); | |
return u; | |
} | |
void reset(T reference=T(), T initial=T()) { | |
IF.reset(reference - initial); | |
DF.reset(c * reference - initial); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment