control algo applied for mnm

Dependencies:   mbed-rtos mbed

Fork of BAE_hw_test1_1 by sakthi priya amirtharaj

Revision:
9:8b74ed33be76
Parent:
6:1cdbda747f99
--- a/ACS.cpp	Sun Mar 01 05:30:12 2015 +0000
+++ b/ACS.cpp	Sun Mar 01 07:41:51 2015 +0000
@@ -274,7 +274,7 @@
 /*------------------------------------------------------------------------------------------------------------------------------------------------------
 -------------------------------------------CONTROL ALGORITHM------------------------------------------------------------------------------------------*/
 
-float * FUNC_ACS_CNTRLALGO(float b[3],float omega[3])
+void FUNC_ACS_CNTRLALGO(float b[3],float omega[3],float tauc[3])
 {
     float db[3]; /// inputs
 //initialization
@@ -284,10 +284,12 @@
     float den = 0; 
     float den2;
     int i, j; //temporary variables
-    float Mu[2], z[2], dv[2], v[2], u[2], tauc[3] = {0, 0, 0}; //outputs
+    float Mu[2], z[2], dv[2], v[2], u[2]; //outputs
+    //float tauc[3];
+    float *tauc1;
     float invJm[3][3];
     float kmu2 = 0.07, gamma2 = 1.9e4, kz2 = 0.4e-2, kmu = 0.003, gamma = 5.6e4, kz = 0.1e-4;
-    printf("Entered cntrl algo\n\r");
+    printf("\n\r Entered cntrl algo\n\r");
     //structure parameters
 
     void inverse (float mat[3][3], float inv[3][3]); 
@@ -295,8 +297,8 @@
     //functions
  
 ////////// Input from Matlab //////////////
-    while(1) 
-    {
+  //  while(1)                          //removed assumin while is used coz of matlab
+    //{
        
  /*getInput(inputs);
 //while(1)
@@ -311,6 +313,10 @@
  omega[2] = inputs[8];*/
 /////////// Control Algorithm //////////////////////
 // calculate norm b, norm db
+        tauc[0]=0;
+        tauc[1]=0;
+        tauc[2]=0;
+        
         den = sqrt((b[0]*b[0]) + (b[1]*b[1]) + (b[2]*b[2]));
         den2 = (b[0]*db[0]) + (b[1]*db[1]) + (b[2]*db[2]);
        
@@ -324,8 +330,8 @@
         {
             printf("\n\rreached here\n\r");
             if(den!=0)
-                //b[i]=b[i]/den;                                      //there is a problem here. The code gets stuck here.  Maf value is required 
-                ;
+                b[i]=b[i]/den;                                      //there is a problem here. The code gets stuck here.  Maf value is required 
+                
         }
         
 // select kz, kmu, gamma
@@ -375,14 +381,20 @@
 // calculate inv(N) store in Jm
         inverse(invJm, Jm);
 // calculate tauc
+         printf("\n \r calculatin tauc");
         for(i=0;i<3;i++)
         {
+           
             for(j=0;j<3;j++)
                 tauc[i] += Jm[i][j]*bb[j];
+            //printf(" %d \t",i);
+            //tauc1[i] = tauc[i];
+            printf(" %f \t",tauc[i]);    
         }
-         
-        return(tauc);
-    }
+        
+        //printf("    %f \n ", tauc[2]);
+        //return tauc;
+    
 }
 /////////// Output to Matlab //////////////////
 /* for(i=0;i<3;i++) {