Skip to content

Instantly share code, notes, and snippets.

@tanitanin
Last active June 10, 2019 16:27
Show Gist options
  • Save tanitanin/3ee5a8beb60dda7f55f3bcb98d5abc44 to your computer and use it in GitHub Desktop.
Save tanitanin/3ee5a8beb60dda7f55f3bcb98d5abc44 to your computer and use it in GitHub Desktop.
Discrete-Time Integrator with Forward Eular Method
#pragma once
template<typename T>
class DescreteTimeIntegrator {
T x;
T y;
T Ts;
T K;
public:
DescreteTimeIntegrator(T k, T ts,T initial = T()) : K(k), Ts(ts) {
y = initial;
}
T update(T input) {
// forward eular
x = y + K * Ts * input;
y = x;
return y;
}
void reset(T initial) { y = initial; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment