Last active
June 10, 2019 16:36
-
-
Save tanitanin/b4e0bae6d18f2133bbd7dabba5590431 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 PIDStd { | |
T Kp; | |
T Ti; | |
T Td; | |
T N; | |
T Ts; | |
T x; | |
T y; | |
DescreteTimeIntegrator<T> IF; | |
DescreteTimeIntegrator<T> DF; | |
public: | |
PIDStd(T kp, T ti, T td, T n, T ts, T initial=T()) : Kp(kp), Ti(ti), Td(td), N(n), IF(1, ts), DF(1, ts) { | |
y = initial; | |
IF.reset(y); | |
DF.reset(0); | |
} | |
T update(T input) { | |
x = y; | |
y = Kp * ( x + 1 / Ti * IF.update(x) + Td / (Td / N + DF.update(x)) ); | |
return y; | |
} | |
void reset(T initial=T()) { | |
y = initial; | |
IF.reset(initial); | |
DF.reset(0); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment