ACS completed fully. All cases to be tested

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of ACS_Flowchart_BAE by Team Fox

Files at this revision

API Documentation at this revision

Comitter:
sakthipriya
Date:
Fri Jan 22 19:51:50 2016 +0000
Parent:
5:bb592f3185cc
Child:
7:a46a1dee4497
Commit message:
i2c prob again

Changed in this revision

ACS.cpp Show annotated file Show diff for this revision Revisions of this file
EPS.cpp Show annotated file Show diff for this revision Revisions of this file
TCTM.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ACS.cpp	Thu Dec 31 17:12:52 2015 +0000
+++ b/ACS.cpp	Fri Jan 22 19:51:50 2016 +0000
@@ -6,7 +6,7 @@
 #include "pni.h" //pni header file
 #include "pin_config.h"
 #include "ACS.h"
-
+#include "EPS.h"
 
 //********************************flags******************************************//
 extern uint32_t BAE_STATUS;
@@ -34,6 +34,7 @@
 int g_err_flag_TR_z=0;       // setting z-flag to zero
 
 extern float data[6];
+extern BAE_HK_actual actual_data;
 
 
 //DigitalOut gpo1(PTC0); // enable of att sens2 switch
@@ -291,8 +292,10 @@
       //          pc_acs.printf("%f\t",mag_data[i]);
             }
             for(int i=0; i<3; i++) {
-                data[i]=gyro_data[i];
-                data[i+3]=mag_data[i];
+               // data[i]=gyro_data[i];
+                actual_data.AngularSpeed_actual[i] = gyro_data[i];
+                actual_data.Bvalue_actual[i] = mag_data[i];
+                //data[i+3]=mag_data[i];
             }
           //  return(combined_values); //returning poiter combined values
         } 
--- a/EPS.cpp	Thu Dec 31 17:12:52 2015 +0000
+++ b/EPS.cpp	Fri Jan 22 19:51:50 2016 +0000
@@ -1,9 +1,11 @@
 #include "EPS.h"
 #include "pin_config.h"
+#include "iostream"
 /***********************************************global variable declaration***************************************************************/
 extern uint32_t BAE_STATUS;
 extern uint32_t BAE_ENABLE;
-extern uint8_t BAE_data[73]; 
+extern uint8_t BAE_data[74];
+extern char BAE_chardata[74];   
 
 //m_I2C.frequency(10000)
 const char RCOMP0= 0x97;
@@ -193,10 +195,12 @@
     
     for(Iteration=0;Iteration<3;Iteration++){
         quant_data.AngularSpeed_quant[Iteration]=actual_data.AngularSpeed_actual[Iteration];
+        printf("\n\r w value %f",quant_data.AngularSpeed_quant[Iteration]);
     }
     
     for(Iteration=0;Iteration<3;Iteration++){
         quant_data.Bvalue_quant[Iteration]=actual_data.Bvalue_actual[Iteration];
+        printf("\n\r b value %f",quant_data.Bvalue_quant[Iteration]);
     }
     
     quant_data.Batt_voltage_quant=quantiz(vstart,vstep,actual_data.Batt_voltage_actual);
@@ -210,7 +214,7 @@
     arch_data.faultPoll_status=actual_data.faultPoll_status;
     arch_data.faultIr_status=actual_data.faultIr_status;
     arch_data.Batt_voltage=quant_data.Batt_voltage_quant;    
-    
+    printf("\n\r in hk");
     
 }
 
@@ -229,8 +233,14 @@
     FCTN_CONVERT_FLOAT(quant_data.Batt_gauge_alerts,&BAE_data[33]);
     BAE_data[37] = quant_data.BAE_temp_quant;
     FCTN_CONVERT_FLOAT(quant_data.AngularSpeed_quant[0],&BAE_data[38]); 
+    //printf("\n\r outside %d %d %d %d", BAE_data[38],BAE_data[39],BAE_data[40],BAE_data[41]);
+    //std:: cout << "\n\r uint8  outside " << BAE_data[38] << '\t' << BAE_data[39] << '\t' << BAE_data[40] << '\t' << BAE_data[41] <<std::endl; 
     FCTN_CONVERT_FLOAT(quant_data.AngularSpeed_quant[1],&BAE_data[42]); 
+    //std:: cout << "\n\r uint8  outside " << BAE_data[42] << '\t' << BAE_data[43] << '\t' << BAE_data[44] << '\t' << BAE_data[45] <<std::endl;
+    // printf("\n\r outside %d %d %d %d", BAE_data[42],BAE_data[43],BAE_data[44],BAE_data[45]);
     FCTN_CONVERT_FLOAT(quant_data.AngularSpeed_quant[2],&BAE_data[46]); 
+     //printf("\n\r outside %d %d %d %d", BAE_data[46],BAE_data[47],BAE_data[48],BAE_data[49]);
+    //std:: cout << "\n\r uint8  outside " << BAE_data[46] << '\t' << BAE_data[47] << '\t' << BAE_data[48] << '\t' << BAE_data[49] <<std::endl;
     FCTN_CONVERT_FLOAT(quant_data.Bvalue_quant[0],&BAE_data[50]); 
     FCTN_CONVERT_FLOAT(quant_data.Bvalue_quant[1],&BAE_data[54]); 
     FCTN_CONVERT_FLOAT(quant_data.Bvalue_quant[2],&BAE_data[58]); 
@@ -247,6 +257,11 @@
     BAE_data[71] = arch_data.faultPoll_status; 
     BAE_data[72] = arch_data.faultIr_status;
     BAE_data[73] = arch_data.Batt_voltage;
+    for(int i=0; i<73;i++)
+        BAE_chardata[i] = (char)BAE_data[i];
+    BAE_chardata[73] = '\0';
+    printf("\n\r bae ats data %c %c %c %c", BAE_chardata[38],BAE_chardata[39],BAE_chardata[40],BAE_chardata[41]);
+    printf("\n\r BAE data is %s", BAE_chardata);
     
 }
 
--- a/TCTM.cpp	Thu Dec 31 17:12:52 2015 +0000
+++ b/TCTM.cpp	Fri Jan 22 19:51:50 2016 +0000
@@ -4,6 +4,10 @@
 #include "EPS.h"
 #include "pin_config.h"
 #include "FreescaleIAP.h"
+#include "inttypes.h"
+#include "iostream"
+#include "stdint.h"
+#include "cassert"
 
 extern DigitalOut gpo1; // enable of att sens2 switch
 extern DigitalOut gpo2; // enable of att sens switch
@@ -769,12 +773,20 @@
 
 // Convert float to 4 uint8_t
 
-void FCTN_CONVERT_FLOAT(float input, uint8_t* output)
+void FCTN_CONVERT_FLOAT(float input, uint8_t output[4])
 {
-    uint32_t temp;
-    temp = (uint32_t)input;
-    output[0] = (temp>>24)&0xFF;
-    output[2] = (temp>>16)&0xFF;
-    output[1] = (temp>>8)&0xFF; 
-    output[3] = temp & 0xFF;           // verify the logic 
+    assert(sizeof(float) == sizeof(uint32_t));
+    uint32_t* temp = reinterpret_cast<uint32_t*>(&input);
+
+    //float* output1 = reinterpret_cast<float*>(temp);
+    
+    printf("\n\r %f  ", input);
+    std::cout << "\n\r uint32"<<*temp << std::endl;
+
+    output[0] =(uint8_t )(((*temp)>>24)&0xFF);
+    output[2] =(uint8_t ) (((*temp)>>16)&0xFF);
+    output[1] =(uint8_t ) (((*temp)>>8)&0xFF); 
+    output[3] =(uint8_t ) ((*temp) & 0xFF);           // verify the logic 
+    //printf("\n\r inside %d %d %d %d", output[3],output[2],output[1],output[0]);
+    //std:: cout << "\n\r uint8  inside " << output[3] << '\t' << output[2] << '\t' << output[1] << '\t' << output[0] <<std::endl; 
 }
\ No newline at end of file
--- a/main.cpp	Thu Dec 31 17:12:52 2015 +0000
+++ b/main.cpp	Fri Jan 22 19:51:50 2016 +0000
@@ -39,7 +39,8 @@
 char EPS_BATTERY_HEAT_ENABLE = 'q';
 
 //.......................global variables..................................................................// new hk structure- everything has to changed based on this
-uint8_t BAE_data[73];     
+uint8_t BAE_data[74];  
+char BAE_chardata[74];     
     
 
 //*************************************Global declarations************************************************//
@@ -180,7 +181,7 @@
         }
     }
     
-    float b1[3]={-23.376,-37.56,14.739}, omega1[3]={-1.52,2.746,0.7629}, moment1[3]= {1.0498,-1.0535,1.3246};
+    //float b1[3]={-23.376,-37.56,14.739}, omega1[3]={-1.52,2.746,0.7629}, moment1[3]= {1.0498,-1.0535,1.3246};
     //b1[3] = {22, 22,10};
     //omega1[3] = {2.1,3.0,1.5};
     // gpo1 = 0;  // att sens2 switch is disabled
@@ -202,18 +203,18 @@
     pc.printf("gyro values\n\r"); //printing the angular velocity and magnetic field values
     for(int i=0; i<3; i++) 
     {
-        pc.printf("%f\n\r",data[i]);
+        pc.printf("%f\n\r",actual_data.AngularSpeed_actual[i]);
     }
     pc.printf("mag values\n\r");
-    for(int i=3; i<6; i++) 
+    for(int i=0; i<3; i++) 
     {
-        pc.printf("%f\n\r",data[i]);
+        pc.printf("%f\n\r",actual_data.Bvalue_actual[i]);
     }
-        for(int i=0;i<3;i++)
-    {
-    omega1[i]= data[i];
-    b1[i] = data[i+3];
-    }
+      //  for(int i=0;i<3;i++)
+//    {
+//    omega1[i]= data[i];
+//    b1[i] = data[i+3];
+//    }
     }//if ACS_DATA_ACQ_ENABLE = 1
      else
     {
@@ -262,7 +263,7 @@
                             FLAG();
                             printf("\n\r nominal");
                             ACS_STATUS = '4';                    // set ACS_STATUS = ACS_NOMINAL_ONLY
-                            FCTN_ACS_CNTRLALGO(b1,omega1);
+                            FCTN_ACS_CNTRLALGO(actual_data.Bvalue_actual,actual_data.AngularSpeed_actual);
                             printf("\n\r moment values returned by control algo \n");
                             for(int i=0; i<3; i++) 
                             {
@@ -286,7 +287,7 @@
                                     FLAG();
                                     printf("\n\r Entered detumbling \n");
                                     ACS_STATUS = '6';                    // set ACS_STATUS = ACS_DETUMBLING_ONLY  
-                                    FCTN_ACS_CNTRLALGO(b1,omega1);  // detumbling code has to be included
+                                    FCTN_ACS_CNTRLALGO(actual_data.Bvalue_actual,actual_data.AngularSpeed_actual);  // detumbling code has to be included
                                     FCTN_ACS_GENPWM_MAIN(moment) ; 
                                 }
                                 else
@@ -314,9 +315,6 @@
                 PWM3 = 0;                     //clear pwm pins
             }
     } //else for acs control off
-    
-
-  
     ACS_MAIN_STATUS = 'c'; //clear ACS_MAIN_STATUS flag 
         
 }
@@ -370,9 +368,10 @@
 //          EPS_STATUS = EPS_ERR_BATTERY_TEMP;
 //        }
         FCTN_HK_MAIN();
+       // printf("\n\r here");
         FCTN_APPEND_HKDATA();
         minMaxHkData();
-          
+        //printf("\n\r here");  
         EPS_MAIN_STATUS = 'c'; // clear EPS main status 
 
 }
@@ -401,7 +400,11 @@
         else if( slave.receive() == 1)                                     // slave writes to master
         {
              if(data_send_flag == 'h')
-                write_ack=slave.write((char*)BAE_data,73); 
+             {
+                //FCTN_APPEND_HKDATA();
+                // pc.printf("\n\r here");
+                write_ack=slave.write(BAE_chardata,74); 
+            }
             else if(data_send_flag == 't')
             {
                 write_ack=slave.write(telemetry,tm_len);
@@ -412,8 +415,8 @@
         else if( slave.receive()==3 ||  slave.receive()==2)             // slave read 
         {
            read_ack=slave.read(telecommand,tc_len);
-           pc.printf("\n\rTELECOMMAND received from CDMS is %s \n",telecommand);
-           pc.printf("\n\r Executing Telecommand \n"); 
+           //pc.printf("\n\rTELECOMMAND received from CDMS is %s \n",telecommand);
+           //pc.printf("\n\r Executing Telecommand \n"); 
            // FCTN_TC_DECODE((uint8_t*) telecommand);
            uint8_t* temp = FCTN_BAE_TM_TC((uint8_t*) telecommand);
            telemetry = (char*)temp;
@@ -422,6 +425,7 @@
             //pc.printf("%c", telemetry[i]);
         } 
        
+      
     } 
 }