till

Dependencies:   mbed

Fork of RT2_P3_students_G4 by RT2_P3_students

Revision:
12:e18fdd404660
Parent:
11:67af6d24c588
--- a/PI_Cntrl.cpp	Fri Apr 27 06:54:18 2018 +0000
+++ b/PI_Cntrl.cpp	Tue May 15 19:01:38 2018 +0000
@@ -11,3 +11,47 @@
 #include "PI_Cntrl.h"
 
 using namespace std;
+
+
+    PI_Cntrl::PI_Cntrl(float Kp, float Tn, float Ts) {
+        this->Kp = Kp;
+        this->Tn = Tn;
+        this->Ts = Ts;   
+        
+        this->iMin = -0.4f;
+        this->iMax = 0.4f;
+        this->iPartOld = 0;
+        
+    }
+    
+    PI_Cntrl::PI_Cntrl(float Kp, float Tn, float Ts, float iMin, float iMax) {
+        this->Kp = Kp;
+        this->Tn = Tn;
+        this->Ts = Ts;  
+        this->iMin = iMin;
+        this->iMax = iMax;
+        this->iPartOld = 0;
+        
+    }
+    
+    PI_Cntrl::~PI_Cntrl() {}
+    
+    float PI_Cntrl::eval(float val) {
+        
+        float pPart = Kp*val;
+        float iPart = iPartOld+(Ts*Kp/Tn)*val;
+        
+        
+        // Begrenze I
+        if(iPart > iMax) {
+            iPart = iMax;   
+        } else if(iPart < iMin) {
+            iPart = iMin;   
+        }
+        
+        iPartOld = iPart;
+        
+        return pPart+iPart;   
+    }
+    
+