sakthi priya amirtharaj
/
BAE_hw_test1_2
control algo applied for mnm
Fork of BAE_hw_test1_1 by
Revision 9:8b74ed33be76, committed 2015-03-01
- Comitter:
- sakthipriya
- Date:
- Sun Mar 01 07:41:51 2015 +0000
- Parent:
- 8:939b37cdcb92
- Commit message:
- control algo applied for mnm
Changed in this revision
diff -r 939b37cdcb92 -r 8b74ed33be76 ACS.cpp --- 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++) {
diff -r 939b37cdcb92 -r 8b74ed33be76 ACS.h --- a/ACS.h Sun Mar 01 05:30:12 2015 +0000 +++ b/ACS.h Sun Mar 01 07:41:51 2015 +0000 @@ -5,7 +5,7 @@ float * FUNC_ACS_MAG_EXEC(void); void FUNC_ACS_MAG_INIT(); //void Read_data_acs() -float * FUNC_ACS_CNTRLALGO(float*,float*); +void FUNC_ACS_CNTRLALGO(float*,float*,float a[]); float * FUNC_ACS_EXEC_GYR(); void FUNC_ACS_INIT_GYR();
diff -r 939b37cdcb92 -r 8b74ed33be76 main.cpp --- a/main.cpp Sun Mar 01 05:30:12 2015 +0000 +++ b/main.cpp Sun Mar 01 07:41:51 2015 +0000 @@ -96,7 +96,9 @@ { float *mag_field; float *omega; - float *moment; + float mag_field1[3]; + float omega1[1]; + float moment[3]; float *mnm_data; while(1) { @@ -118,15 +120,20 @@ } for(int i = 0 ; i<3;i++) { - omega[i] = mnm_data[i]; + omega1[i] = mnm_data[i]; } for( int i = 3;i<6;i++) { - mag_field[i-3] = mnm_data[i]; + mag_field1[i-3] = mnm_data[i]; } if(acs_pflag == 1) { - moment = FUNC_ACS_CNTRLALGO(mag_field,omega); + FUNC_ACS_CNTRLALGO(mag_field1,omega1,moment); + printf("\n\r control algo values "); + for(int i=0; i<3; i++) + { + printf("%f\t",moment[i]); + } FUNC_ACS_GENPWM(moment); }