Ruprecht Altenburger
/
mirror_actuator_stud
template for students for mirror actuator
Lib_Cntrl/PID_Cntrl.cpp
- Committer:
- altb2
- Date:
- 2021-05-17
- Revision:
- 1:a7fc1afe0575
- Parent:
- 0:d2e117716219
- Child:
- 2:c4c4cc1bff45
File content as of revision 1:a7fc1afe0575:
/* */ #include "PID_Cntrl.h" // Matlab // Tn = .005; // Gpi= tf([Tn 1],[Tn 0]); // Kp = 0.0158; // pid(Kp*Gpi); PID_Cntrl::PID_Cntrl(float P, float I, float D, float tau_f, float Ts, float uMin, float uMax) { // ------------------ this->P = P; this->I = I; this->Ts = Ts; this->uMin = uMin; this->uMax = uMax; reset(0); } PID_Cntrl::~PID_Cntrl() {} void PID_Cntrl::reset(float initValue) { // ----------------------- Ipart = initValue; } float PID_Cntrl::update(float e) { // the main update Ipart += I * Ts * e; Ipart = saturate(Ipart); return saturate(P * e + Ipart); } float PID_Cntrl::saturate(float x) { if(x > uMax) return uMax; else if(x < uMin) return uMin; return x; }