pr7

Dependencies:   mbed

Revision:
2:1ded9d10f322
Parent:
1:92f175969d90
--- a/main.cpp	Fri May 10 14:25:24 2019 +0000
+++ b/main.cpp	Tue May 14 15:29:24 2019 +0000
@@ -36,8 +36,9 @@
 float Ts = 0.0005f;                     // sample time of main loop
 uint16_t k = 0;
 // initiate PIDT1 controller objects
-// ???
-// ???
+PID_Cntrl dt1( 0.0f, 0.0f, 0.0186f, 0.000667f, Ts, -3.0f, 3.0f); 
+PID_Cntrl pi( 8.13f, 15.0f, 0.0f, 0.0f, Ts, -3.0f, 3.0f); // Ki 38.8
+float w = 0.5f;
 //******************************************************************************
 //---------- main loop -------------
 //******************************************************************************
@@ -61,13 +62,13 @@
     float i_des = 0.0f;         // default: set motor current to zero (will be overwritten)
     if(controller_active) {
         // controller update
-        // ???
+        i_des = pi(w - x) - dt1(x);
     }
-    out.write(i2u(i_des));
+    out.write(i2u(i_des)); 
     if(++k>1000) {
         pc.printf("x: %1.3f, i: %1.4f\r\n",x,i_des);
         k = 0;
-
+        w = -w;
     }
 } // END OF updateLoop(void)
 
@@ -91,7 +92,8 @@
         if(controller_active) {
             pc.printf("Controller actived\r\n");
             // reset controller here!!!
-            // ???
+            dt1.reset(0.0f);
+            pi.reset(0.0f);
         } else
             pc.printf("Controller disabled\r\n");
     }