fusion-zauberstab/firmware/include/pt1.h
Thomas Schmid 830703589d pt1: implement as template class
Signed-off-by: Thomas Schmid <tom@lfence.de>
2022-06-19 12:54:17 +02:00

18 lines
319 B
C++

#pragma once
template<class T>
struct Pt1 {
T y_n1;
T K;
T T1;
/* PT1: y = y_(n-1) + (Ku - y_(n-1)) * dt/T1 */
Pt1(T K, T T1) : T1(T1), K(K) {};
T update(T u, T dt)
{
T y = this->y_n1 + (this->K * u - this->y_n1) * dt / this->T1;
this->y_n1 = y;
return y;
}
};