Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Encoder HIDScope mbed
Fork of Aansturing_knoppen by
PID.cpp
00001 #include "PID.h" 00002 00003 double PID( double err, const double Kp, const double Ki, const double Kd, const double Ts, const double N, double &v1, double &v2 ) { 00004 // These variables are only calculated once! 00005 const double a1 = -4/(N*Ts+2), 00006 a2 = -(N*Ts-2)/(N*Ts+2), 00007 b0 = (4*Kp + 4*Kd*N + 2*Ki*Ts + 2*Kp*N*Ts + Ki*N*pow(Ts,2))/(2*N*Ts + 4), 00008 b1 = (Ki*N*pow(Ts,2) - 4*Kp - 4*Kd*N)/(N*Ts + 2), 00009 b2 = (4*Kp + 4*Kd*N - 2*Ki*Ts - 2*Kp*N*Ts + Ki*N*pow(Ts,2))/(2*N*Ts + 4); 00010 00011 double v = err - a1*v1 - a2*v2; 00012 double u = b0*v + b1*v1 + b2*v2; 00013 v2 = v1; v1 = v; 00014 return u; 00015 }
Generated on Fri Jul 15 2022 02:36:49 by
1.7.2
