Skip to content

Instantly share code, notes, and snippets.

@tanitanin
Last active June 10, 2019 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanitanin/b4e0bae6d18f2133bbd7dabba5590431 to your computer and use it in GitHub Desktop.
Save tanitanin/b4e0bae6d18f2133bbd7dabba5590431 to your computer and use it in GitHub Desktop.
#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