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
PI1.cpp
00001 #include "PI1.h" 00002 00003 PI1::PI1() { 00004 u = y = u_p1 = y_p1 = 0; 00005 setParameters(1, 1, 0.1); 00006 setOutputLimits(0, 1); 00007 setOperationMode(automatic); 00008 } 00009 00010 PI1::PI1(double K_R_, double T_I_, double T_d_) { 00011 u = y = u_p1 = y_p1 = 0; 00012 setParameters(K_R_, T_I_, T_d_); 00013 setOutputLimits(0, 1); 00014 setOperationMode(automatic); 00015 } 00016 00017 void PI1::setParameters(double K_R_, double T_I_, double T_d_) { 00018 if (T_d_ > 0) 00019 T_d = T_d_; 00020 else 00021 T_d = 0.1; 00022 if (T_I_ > 0) 00023 T_I = T_I_; 00024 else 00025 T_I = 1; 00026 K_R = K_R_; 00027 } 00028 00029 void PI1::setOutputLimits(double lowerOutputLimit, double upperOutputLimit) { 00030 if (upperOutputLimit > lowerOutputLimit) { 00031 y_min = lowerOutputLimit; 00032 y_max = upperOutputLimit; 00033 } 00034 } 00035 00036 void PI1::setOperationMode(Mode newOperationMode) { 00037 // Bumpless transfer from manual to automatic mode 00038 if (operationMode == manual && newOperationMode == automatic) { 00039 y = y_p1 = y_manual; 00040 u = u_p1 = 0; 00041 } 00042 // Bumpless transfer from automatic to manual mode 00043 else if (operationMode == automatic && newOperationMode == manual) { 00044 y_manual = y; 00045 } 00046 operationMode = newOperationMode; 00047 } 00048 00049 void PI1::setOutputManually(double u_C) { 00050 y_manual = u_C; 00051 } 00052 00053 double PI1::out() { 00054 if (operationMode == automatic) { 00055 y = y_p1 + K_R * u + K_R * (T_d / T_I - 1) * u_p1; 00056 } else if (operationMode == manual) { 00057 y = y_manual; 00058 } 00059 00060 if (y > y_max) 00061 y = y_max; 00062 else if (y < y_min) 00063 y = y_min; 00064 00065 y_p1 = y; 00066 u_p1 = u; 00067 return y; 00068 } 00069 00070 void PI1::in(double u_) { 00071 u = u_; 00072 }
Generated on Thu Jul 14 2022 20:25:49 by
1.7.2
