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.
Fork of AutomationElements by
PT2.cpp
00001 #include "PT2.h" 00002 00003 PT2::PT2() { 00004 u = y = u_p1 = y_p1 = u_p2 = y_p2 = 0; 00005 setParameters(1, 1, 0.5, 0.1); 00006 } 00007 00008 PT2::PT2(double K_, double T_1_, double T_2_, double T_d_) { 00009 u = y = u_p1 = y_p1 = u_p2 = y_p2 = 0; 00010 setParameters(K_, T_1_, T_2_, T_d_); 00011 } 00012 00013 void PT2::setParameters(double K_, double T_1_, double T_2_, double T_d_) { 00014 if (T_d_ > 0) 00015 T_d = T_d_; 00016 else 00017 T_d = 0.1; 00018 K = K_; 00019 T_1 = T_1_; 00020 T_2 = T_2_; 00021 a = 1 / T_1; 00022 b = 1 / T_2; 00023 c = exp(-a * T_d); 00024 d = exp(-b * T_d); 00025 b_1 = -K * ( (a - b)*(c + d) + b*(1 + d) - a*(1 + c) ) / (a - b); 00026 b_2 = K * ( (a - b)*c*d + b*d - a*c ) / (a - b); 00027 a_1 = -(c + d); 00028 a_2 = c*d; 00029 } 00030 00031 double PT2::out() { 00032 y = -a_1 * y_p1 - a_2 * y_p2 + b_1 * u_p1 + b_2 * u_p2; 00033 y_p2 = y_p1; 00034 y_p1 = y; 00035 u_p2 = u_p1; 00036 u_p1 = u; 00037 return y; 00038 } 00039 00040 void PT2::in(double u_) { 00041 u = u_; 00042 }
Generated on Thu Jul 14 2022 20:25:49 by
1.7.2
