test

Fork of AutomationElements by TVZ Mechatronics Team

Files at this revision

API Documentation at this revision

Comitter:
tgw
Date:
Sat Nov 25 02:03:00 2017 +0000
Parent:
1:b9e11da0f2eb
Commit message:
test

Changed in this revision

AutomationElements.h Show annotated file Show diff for this revision Revisions of this file
PI.cpp Show diff for this revision Revisions of this file
PI.h Show diff for this revision Revisions of this file
PI1.cpp Show annotated file Show diff for this revision Revisions of this file
PI1.h Show annotated file Show diff for this revision Revisions of this file
diff -r b9e11da0f2eb -r a45cbb512c99 AutomationElements.h
--- a/AutomationElements.h	Thu Jan 22 12:44:37 2015 +0000
+++ b/AutomationElements.h	Sat Nov 25 02:03:00 2017 +0000
@@ -4,7 +4,7 @@
 #include "DT1.h"
 #include "I.h"
 #include "PDT1.h"
-#include "PI.h"
+#include "PI1.h"
 #include "PT1.h"
 #include "PT2.h"
 #include "PT2cc.h"
diff -r b9e11da0f2eb -r a45cbb512c99 PI.cpp
--- a/PI.cpp	Thu Jan 22 12:44:37 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-#include "PI.h"
-
-PI::PI() {
-    u = y = u_p1 = y_p1 = 0;
-    setParameters(1, 1, 0.1);
-    setOutputLimits(0, 1);
-    setOperationMode(automatic);
-}
-
-PI::PI(double K_R_, double T_I_, double T_d_) {
-    u = y = u_p1 = y_p1 = 0;
-    setParameters(K_R_, T_I_, T_d_);
-    setOutputLimits(0, 1);
-    setOperationMode(automatic);
-}
-
-void PI::setParameters(double K_R_, double T_I_, double T_d_) {
-    if (T_d_ > 0)
-        T_d = T_d_;
-    else
-        T_d = 0.1;
-    if (T_I_ > 0)
-        T_I = T_I_;
-    else
-        T_I = 1;
-    K_R = K_R_;
-}
-
-void PI::setOutputLimits(double lowerOutputLimit, double upperOutputLimit) {
-    if (upperOutputLimit > lowerOutputLimit) {
-        y_min = lowerOutputLimit;
-        y_max = upperOutputLimit;
-    }
-}
-
-void PI::setOperationMode(Mode newOperationMode) {
-    // Bumpless transfer from manual to automatic mode
-    if (operationMode == manual && newOperationMode == automatic) {
-        y = y_p1 = y_manual;
-        u = u_p1 = 0;
-    }
-    // Bumpless transfer from automatic to manual mode
-    else if (operationMode == automatic && newOperationMode == manual) {
-        y_manual = y;
-    }
-    operationMode = newOperationMode;
-}
-
-void PI::setOutputManually(double u_C) {
-    y_manual = u_C;
-}
-
-double PI::out() {
-    if (operationMode == automatic) {
-        y = y_p1 + K_R * u + K_R * (T_d / T_I - 1) * u_p1;
-    } else if (operationMode == manual) {
-        y = y_manual;
-    }
-    
-    if (y > y_max)
-        y = y_max;
-    else if (y < y_min)
-        y = y_min;
-    
-    y_p1 = y;    
-    u_p1 = u;
-    return y;
-}
-
-void PI::in(double u_) {
-    u = u_;
-}
\ No newline at end of file
diff -r b9e11da0f2eb -r a45cbb512c99 PI.h
--- a/PI.h	Thu Jan 22 12:44:37 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-#ifndef PI_H
-#define PI_H
-
-#include "mbed.h"
-
-/** Data type for choosing the operation mode of the controller ("automatic" or "manual"). */
-enum Mode {automatic, manual};
-
-/** Transfer function of a PI controller with output limitation, anti-windup and bumpless automatic and manual mode.
- * G_C(s) = U_C(s) / E(s) = K_C ( 1 + 1 / (T_I s) ) = K_C (1 + T_I s) / (T_I s)
- *
- * K_C is the controller gain, and T_I is the controller integral time constant in seconds.
- *
- * Author(s): TVZ Mechatronics Team
- *
- */
-class PI {
-    public:
-        /** Default constructor.
-         * K_C = 1, T_I = 1 s, sampleTime = 0.1 s.
-         */
-        PI();
-        /** PI controller gain, integral time constant in seconds and sample time in seconds. */
-        PI(double K_C, double T_I, double sampleTime);
-        /** Update PI controller gain, integral time constant and sample time. */
-        void setParameters(double K_C, double T_I, double sampleTime);
-        /** Set the controller lower and upper output limit. */
-        void setOutputLimits(double lowerOutputLimit, double upperOutputLimit);
-        /** Set the operation mode to "automatic" or "manual". */
-        void setOperationMode (Mode operationMode);
-        /** Set the controller output manually. */
-        void setOutputManually(double u_C);
-        /** Calculate the controller output u_C. */
-        double out();
-        /** Set the PI controller input e = SP - PV (setpoint - process value). */
-        void in(double e);
-    private:
-        double K_R, T_I, T_d, y, y_p1, u, u_p1, y_max, y_min, y_manual;
-        Mode operationMode;
-};
-
-#endif // PI_H
\ No newline at end of file
diff -r b9e11da0f2eb -r a45cbb512c99 PI1.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PI1.cpp	Sat Nov 25 02:03:00 2017 +0000
@@ -0,0 +1,72 @@
+#include "PI1.h"
+
+PI1::PI1() {
+    u = y = u_p1 = y_p1 = 0;
+    setParameters(1, 1, 0.1);
+    setOutputLimits(0, 1);
+    setOperationMode(automatic);
+}
+
+PI1::PI1(double K_R_, double T_I_, double T_d_) {
+    u = y = u_p1 = y_p1 = 0;
+    setParameters(K_R_, T_I_, T_d_);
+    setOutputLimits(0, 1);
+    setOperationMode(automatic);
+}
+
+void PI1::setParameters(double K_R_, double T_I_, double T_d_) {
+    if (T_d_ > 0)
+        T_d = T_d_;
+    else
+        T_d = 0.1;
+    if (T_I_ > 0)
+        T_I = T_I_;
+    else
+        T_I = 1;
+    K_R = K_R_;
+}
+
+void PI1::setOutputLimits(double lowerOutputLimit, double upperOutputLimit) {
+    if (upperOutputLimit > lowerOutputLimit) {
+        y_min = lowerOutputLimit;
+        y_max = upperOutputLimit;
+    }
+}
+
+void PI1::setOperationMode(Mode newOperationMode) {
+    // Bumpless transfer from manual to automatic mode
+    if (operationMode == manual && newOperationMode == automatic) {
+        y = y_p1 = y_manual;
+        u = u_p1 = 0;
+    }
+    // Bumpless transfer from automatic to manual mode
+    else if (operationMode == automatic && newOperationMode == manual) {
+        y_manual = y;
+    }
+    operationMode = newOperationMode;
+}
+
+void PI1::setOutputManually(double u_C) {
+    y_manual = u_C;
+}
+
+double PI1::out() {
+    if (operationMode == automatic) {
+        y = y_p1 + K_R * u + K_R * (T_d / T_I - 1) * u_p1;
+    } else if (operationMode == manual) {
+        y = y_manual;
+    }
+    
+    if (y > y_max)
+        y = y_max;
+    else if (y < y_min)
+        y = y_min;
+    
+    y_p1 = y;    
+    u_p1 = u;
+    return y;
+}
+
+void PI1::in(double u_) {
+    u = u_;
+}
\ No newline at end of file
diff -r b9e11da0f2eb -r a45cbb512c99 PI1.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PI1.h	Sat Nov 25 02:03:00 2017 +0000
@@ -0,0 +1,42 @@
+#ifndef PI1_H
+#define PI1_H
+
+#include "mbed.h"
+
+/** Data type for choosing the operation mode of the controller ("automatic" or "manual"). */
+enum Mode {automatic, manual};
+
+/** Transfer function of a PI controller with output limitation, anti-windup and bumpless automatic and manual mode.
+ * G_C(s) = U_C(s) / E(s) = K_C ( 1 + 1 / (T_I s) ) = K_C (1 + T_I s) / (T_I s)
+ *
+ * K_C is the controller gain, and T_I is the controller integral time constant in seconds.
+ *
+ * Author(s): TVZ Mechatronics Team
+ *
+ */
+class PI1 {
+    public:
+        /** Default constructor.
+         * K_C = 1, T_I = 1 s, sampleTime = 0.1 s.
+         */
+        PI1();
+        /** PI controller gain, integral time constant in seconds and sample time in seconds. */
+        PI1(double K_C, double T_I, double sampleTime);
+        /** Update PI controller gain, integral time constant and sample time. */
+        void setParameters(double K_C, double T_I, double sampleTime);
+        /** Set the controller lower and upper output limit. */
+        void setOutputLimits(double lowerOutputLimit, double upperOutputLimit);
+        /** Set the operation mode to "automatic" or "manual". */
+        void setOperationMode (Mode operationMode);
+        /** Set the controller output manually. */
+        void setOutputManually(double u_C);
+        /** Calculate the controller output u_C. */
+        double out();
+        /** Set the PI controller input e = SP - PV (setpoint - process value). */
+        void in(double e);
+    private:
+        double K_R, T_I, T_d, y, y_p1, u, u_p1, y_max, y_min, y_manual;
+        Mode operationMode;
+};
+
+#endif // PI1_H
\ No newline at end of file