ACS completed fully. All cases to be tested
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of ACS_Flowchart_BAE by
Diff: main.cpp
- Revision:
- 9:194afacf7449
- Parent:
- 8:82250e41da81
- Child:
- 12:af1d7e18b868
diff -r 82250e41da81 -r 194afacf7449 main.cpp --- a/main.cpp Sat Mar 12 12:54:14 2016 +0000 +++ b/main.cpp Fri Apr 01 21:13:16 2016 +0000 @@ -9,6 +9,7 @@ #define tm_len 134 #define tc_len 135 #define batt_heat_low 20 + //***************************************************** flags *************************************************************// uint32_t BAE_STATUS = 0x00000000; uint32_t BAE_ENABLE = 0xFFFFFFFF; @@ -17,7 +18,7 @@ char data_send_flag = 'h'; //.........acs...............// -char ACS_INIT_STATUS = 'q'; +/* char ACS_INIT_STATUS = 'q'; char ACS_DATA_ACQ_STATUS = 'q'; char ACS_ATS_STATUS = 'q'; char ACS_MAIN_STATUS = 'q'; @@ -25,11 +26,21 @@ char ACS_ATS_ENABLE = 'q'; char ACS_DATA_ACQ_ENABLE = 'q'; -char ACS_STATE = 'q'; +char ACS_STATE = 'q';*/ + +uint8_t ACS_INIT_STATUS = 0; +uint8_t ACS_DATA_ACQ_STATUS = 0; +uint8_t ACS_ATS_STATUS = 0; +uint8_t ACS_MAIN_STATUS = 0; +uint8_t ACS_STATUS = 0; + +uint8_t ACS_ATS_ENABLE = 1; +uint8_t ACS_DATA_ACQ_ENABLE = 1; +uint8_t ACS_STATE = 4; //.....................eps...................// //eps init -char EPS_INIT_STATUS = 'q'; +/*char EPS_INIT_STATUS = 'q'; char EPS_BATTERY_GAUGE_STATUS = 'q'; //eps main char EPS_MAIN_STATUS = 'q'; @@ -37,6 +48,16 @@ char EPS_STATUS = 'q'; char EPS_BATTERY_HEAT_ENABLE = 'q'; +*/ + +uint8_t EPS_INIT_STATUS = 0; +uint8_t EPS_BATTERY_GAUGE_STATUS = 0; +//eps main +uint8_t EPS_MAIN_STATUS = 0; +uint8_t EPS_BATTERY_TEMP_STATUS = 0; +uint8_t EPS_STATUS = 7; //invalid status + +uint8_t EPS_BATTERY_HEAT_ENABLE = 0; //.......................global variables..................................................................// new hk structure- everything has to changed based on this uint8_t BAE_data[74]; @@ -72,14 +93,14 @@ bool if2check = 1; //*****************************************************Assigning pins******************************************************// -DigitalOut gpo1(PTC0); // enable of att sens2 switch -DigitalOut gpo2(PTC16); // enable of att sens switch +DigitalOut ATS1_SW_ENABLE(PTC0); // enable of att sens2 switch +DigitalOut ATS2_SW_ENABLE(PTC16); // enable of att sens switch InterruptIn irpt_4m_mstr(PIN38); //I2c interrupt from CDMS DigitalOut irpt_2_mstr(PIN4); //I2C interrupt to CDMS I2CSlave slave (PIN1,PIN2); DigitalOut batt_heat(PIN96); -//gpo1 = 0; +//ATS1_SW_ENABLE = 0; PwmOut PWM1(PIN93); //x //Functions used to generate PWM signal PwmOut PWM2(PIN94); //y PwmOut PWM3(PIN95); //z //PWM output comes from pins p6 @@ -91,7 +112,7 @@ DigitalIn pf3(PIN83);//Fault Bar for TRXY driver //Interrupt based faults -//InterruptIn ir1(PIN73);//Battery Gauge - Alert Bar Signal +InterruptIn ir1(PIN73);//Battery Gauge - Alert Bar Signal InterruptIn ir2(PIN72);//TRXY Driver TR switch Fault InterruptIn ir3(PIN89);//TRZ Driver Fault Bar InterruptIn ir4(PIN91);//TRZ Driver TR switch Fault @@ -99,7 +120,7 @@ InterruptIn ir6(PIN80);//Beacon- Switch OC bar InterruptIn ir7(PIN42);//Charger IC - Fault Bar -DigitalOut TRXY_SW(PIN71); //TR XY Switch +DigitalOut TRXY_SW_EN(PIN71); //TR XY Switch DigitalOut DRV_Z_SLP(PIN88); //Sleep pin of driver z DigitalOut TRZ_SW(PIN40); //TR Z Switch DigitalOut CDMS_RESET(PIN7); // CDMS RESET @@ -131,47 +152,47 @@ void F_ACS() { - //........dummy check..........// - PWM1 = 0.56; - printf ("\n\r pwm1 value %f",PWM1); + //...................// if(pf1check == 1) { if(iterP1 >= 3) { - gpo1 = 1; // turn off ats1 permanently + ATS1_SW_ENABLE = 1; // turn off ats1 permanently //FCTN_SWITCH_ATS(0); // switch on ATS2 } else { - gpo1 = 0; + ATS1_SW_ENABLE = 0; iterP1++; } + pf1check = 0; } if(pf2check == 1) { if(iterP1 >= 3) { - gpo2 = 1; // turn off ats2 permanently - ACS_DATA_ACQ_ENABLE == 'd'; - ACS_STATE == '2' ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY + ATS2_SW_ENABLE = 1; // turn off ats2 permanently + ACS_DATA_ACQ_ENABLE == 0; + ACS_STATE == 2 ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY } else { - gpo2 = 0; + ATS2_SW_ENABLE = 0; iterP2++; } + pf2check = 0; } if(if1check == 1) { if(iterI1 >= 3) { - TRXY_SW = 0; // turn off TRXY permanently + TRXY_SW_EN = 0; // turn off TRXY permanently } else { - TRXY_SW = 1; //switch on TRXY + TRXY_SW_EN = 1; //switch on TRXY iterI1++; } } @@ -180,7 +201,7 @@ if(iterI2 >= 3) { TRZ_SW = 0; // turn off TRZ permanently - ACS_STATE == '2' ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY + ACS_STATE == 2 ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY } else { @@ -192,19 +213,19 @@ //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 - // gpo2 = 0; // att sens switch is disabled + // ATS1_SW_ENABLE = 0; // att sens2 switch is disabled + // ATS2_SW_ENABLE = 0; // att sens switch is disabled //Thread::signal_wait(0x1); - ACS_MAIN_STATUS = 's'; //set ACS_MAIN_STATUS flag + ACS_MAIN_STATUS = 1; //set ACS_MAIN_STATUS flag PWM1 = 0; //clear pwm pins PWM2 = 0; //clear pwm pins PWM3 = 0; //clear pwm pins pc.printf("\n\rEntered ACS %f\n",t_start.read()); - if(ACS_DATA_ACQ_ENABLE == 'e')// check if ACS_DATA_ACQ_ENABLE = 1? + if(ACS_DATA_ACQ_ENABLE == 1)// check if ACS_DATA_ACQ_ENABLE = 1? { FLAG(); FCTN_ATS_DATA_ACQ(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3 @@ -228,11 +249,11 @@ { // Z axis actuation is the only final solution, } - if(ACS_STATE == '0') // check ACS_STATE = ACS_CONTROL_OFF? + if(ACS_STATE == 0) // check ACS_STATE = ACS_CONTROL_OFF? { printf("\n\r acs control off\n"); FLAG(); - ACS_STATUS = '0'; // set ACS_STATUS = ACS_CONTROL_OFF + ACS_STATUS = 0; // set ACS_STATUS = ACS_CONTROL_OFF PWM1 = 0; //clear pwm pins PWM2 = 0; //clear pwm pins PWM3 = 0; //clear pwm pins @@ -242,11 +263,11 @@ if(actual_data.power_mode>1) { - if(ACS_STATE == '2') // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY + if(ACS_STATE == 2) // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY { FLAG(); printf("\n\r z axis moment only\n"); - ACS_STATUS = '2'; // set ACS_STATUS = ACS_ZAXIS_MOMENT_ONLY + ACS_STATUS = 2; // set ACS_STATUS = ACS_ZAXIS_MOMENT_ONLY // FCTN_ACS_CNTRLALGO(b1, omega1); moment[0] = 0; moment[1] = 0; @@ -255,22 +276,22 @@ } else { - if(ACS_STATE == '3') // check ACS_STATE = ACS_DATA_ACQ_FAILURE + if(ACS_STATE == 3) // check ACS_STATE = ACS_DATA_ACQ_FAILURE { FLAG(); printf("\n\r acs data failure "); - ACS_STATUS = '3'; // set ACS_STATUS = ACS_DATA_ACQ_FAILURE + ACS_STATUS = 3; // set ACS_STATUS = ACS_DATA_ACQ_FAILURE PWM1 = 0; //clear pwm pins PWM2 = 0; //clear pwm pins PWM3 = 0; //clear pwm pins } else { - if(ACS_STATE == '4') // check ACS_STATE = ACS_NOMINAL_ONLY + if(ACS_STATE == 4) // check ACS_STATE = ACS_NOMINAL_ONLY { FLAG(); printf("\n\r nominal"); - ACS_STATUS = '4'; // set ACS_STATUS = ACS_NOMINAL_ONLY + ACS_STATUS = 4; // set ACS_STATUS = ACS_NOMINAL_ONLY 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++) @@ -281,20 +302,20 @@ } else { - if(ACS_STATE == '5') // check ACS_STATE = ACS_AUTO_CONTROL + if(ACS_STATE == 5) // check ACS_STATE = ACS_AUTO_CONTROL { FLAG(); printf("\n\r auto control"); - ACS_STATUS = '5'; // set ACS_STATUS = ACS_AUTO_CONTROL + ACS_STATUS = 5; // set ACS_STATUS = ACS_AUTO_CONTROL //FCTN_ACS_AUTOCTRL_LOGIC // gotta include this code } else { - if(ACS_STATE == '6') // check ACS_STATE = ACS_DETUMBLING_ONLY + if(ACS_STATE == 6) // check ACS_STATE = ACS_DETUMBLING_ONLY { FLAG(); printf("\n\r Entered detumbling \n"); - ACS_STATUS = '6'; // set ACS_STATUS = ACS_DETUMBLING_ONLY + ACS_STATUS = 6; // set ACS_STATUS = ACS_DETUMBLING_ONLY FCTN_ACS_CNTRLALGO(actual_data.Bvalue_actual,actual_data.AngularSpeed_actual); // detumbling code has to be included FCTN_ACS_GENPWM_MAIN(moment) ; } @@ -302,7 +323,7 @@ { FLAG(); printf("\n\r invalid state"); - ACS_STATUS = '7' ; // set ACS_STATUS = INVALID STATE + ACS_STATUS = 7 ; // set ACS_STATUS = INVALID STATE PWM1 = 0; //clear pwm pins PWM2 = 0; //clear pwm pins PWM3 = 0; //clear pwm pins @@ -317,13 +338,13 @@ { FLAG(); printf("\n\r low power"); - ACS_STATUS = '1'; // set ACS_STATUS = ACS_LOW_POWER + ACS_STATUS = 1; // set ACS_STATUS = ACS_LOW_POWER PWM1 = 0; //clear pwm pins PWM2 = 0; //clear pwm pins PWM3 = 0; //clear pwm pins } } //else for acs control off - ACS_MAIN_STATUS = 'c'; //clear ACS_MAIN_STATUS flag + ACS_MAIN_STATUS = 0; //clear ACS_MAIN_STATUS flag } //***************************************************EPS THREAD***********************************************// @@ -332,11 +353,11 @@ { pc.printf("\n\rEntered EPS %f\n",t_start.read()); - EPS_MAIN_STATUS = 's'; // Set EPS main status + EPS_MAIN_STATUS = 1; // Set EPS main status FCTN_BATT_TEMP_SENSOR_MAIN(actual_data.Batt_temp_actual); pc.printf("\n\r Battery temperature %f %f" ,actual_data.Batt_temp_actual[0], actual_data.Batt_temp_actual[1]); - EPS_BATTERY_TEMP_STATUS = 's'; //set EPS_BATTERY_TEMP_STATUS - if(EPS_BATTERY_HEAT_ENABLE == 'e') + EPS_BATTERY_TEMP_STATUS = 1; //set EPS_BATTERY_TEMP_STATUS + if(EPS_BATTERY_HEAT_ENABLE == 1) { if((actual_data.Batt_temp_actual[0] < batt_heat_low) && (actual_data.Batt_temp_actual[1] < batt_heat_low)) // to confirm { @@ -348,7 +369,7 @@ } } - else if(EPS_BATTERY_HEAT_ENABLE == 'd') + else if(EPS_BATTERY_HEAT_ENABLE == 0) { EPS_STATUS = 1;//EPS_STATUS = EPS_BATTERY_HEATER_DISABLED } @@ -356,13 +377,13 @@ if (actual_data.Batt_gauge_actual[1] == 200) //data not received { actual_data.power_mode = 1; - EPS_BATTERY_GAUGE_STATUS = 'c'; //clear EPS_BATTERY_GAUGE_STATUS + EPS_BATTERY_GAUGE_STATUS = 0; //clear EPS_BATTERY_GAUGE_STATUS } else { FCTN_EPS_POWERMODE(actual_data.Batt_gauge_actual[1]); //updating power level - EPS_BATTERY_GAUGE_STATUS = 's'; //set EPS_BATTERY_GAUGE_STATUS + EPS_BATTERY_GAUGE_STATUS = 1; //set EPS_BATTERY_GAUGE_STATUS } // if( Temperature data received) //{ @@ -372,7 +393,7 @@ // else // { // Set battery temp to XX -// EPS_BATTERY_TEMP_STATUS = 'c'; //clear EPS_BATTERY_TEMP_STATUS +// EPS_BATTERY_TEMP_STATUS = 0; //clear EPS_BATTERY_TEMP_STATUS // EPS_STATUS = EPS_ERR_BATTERY_TEMP; // } FCTN_HK_MAIN(); @@ -380,7 +401,7 @@ FCTN_APPEND_HKDATA(); minMaxHkData(); //printf("\n\r here"); - EPS_MAIN_STATUS = 'c'; // clear EPS main status + EPS_MAIN_STATUS = 0; // clear EPS main status } @@ -472,7 +493,7 @@ void ir2clear() { actual_data.faultIr_status |= 0x02; - TRXY_SW = 0; // Switch off TR XY + TRXY_SW_EN = 0; // Switch off TR XY if1check = 1; } @@ -525,7 +546,7 @@ { pf1check=1; actual_data.faultPoll_status |=0x01 ; - gpo1 = 1; // turn off ats1 // to be turned on next cycle in ACS + ATS1_SW_ENABLE = 1; // turn off ats1 // to be turned on next cycle in ACS } else actual_data.faultPoll_status &= 0xFE; @@ -533,7 +554,7 @@ { pf2check=1; actual_data.faultPoll_status |=0x02 ; - gpo2 = 1; // turn off ats2 // turn on in ACS + ATS2_SW_ENABLE = 1; // turn off ats2 // turn on in ACS } else actual_data.faultPoll_status &= 0xFD; @@ -613,27 +634,27 @@ { //.............acs..................// - if(ACS_INIT_STATUS == 's') + if(ACS_INIT_STATUS == 1) BAE_STATUS = BAE_STATUS | 0x00000080; //set ACS_INIT_STATUS flag - else if(ACS_INIT_STATUS == 'c') + else if(ACS_INIT_STATUS == 0) BAE_STATUS &= 0xFFFFFF7F; //clear ACS_INIT_STATUS flag - if(ACS_DATA_ACQ_STATUS == 's') + if(ACS_DATA_ACQ_STATUS == 1) BAE_STATUS =BAE_STATUS | 0x00000100; //set ACS_DATA_ACQ_STATUS flag - else if(ACS_DATA_ACQ_STATUS == 'c') + else if(ACS_DATA_ACQ_STATUS == 0) BAE_STATUS &= 0xFFFFFEFF; //clear ACS_DATA_ACQ_STATUS flag - if(ACS_ATS_ENABLE == 'e') + if(ACS_ATS_ENABLE == 1) BAE_ENABLE |= 0x00000004; - else if(ACS_ATS_ENABLE == 'd') + else if(ACS_ATS_ENABLE == 0) BAE_ENABLE = BAE_ENABLE &0xFFFFFFFB | 0x00000004; if(ACS_DATA_ACQ_STATUS == 'f') BAE_STATUS |= 0x00000200; - if(ACS_MAIN_STATUS == 's') + if(ACS_MAIN_STATUS == 1) BAE_STATUS = (BAE_STATUS | 0x00001000); //set ACS_MAIN_STATUS flag - else if(ACS_MAIN_STATUS == 'c') + else if(ACS_MAIN_STATUS == 0) BAE_STATUS &= 0xFFFFEFFF; //clear ACS_MAIN_STATUS flag if(ACS_STATUS == '0') @@ -669,27 +690,27 @@ //...............eps......................// -if (EPS_INIT_STATUS=='s') // Set EPS_INIT_STATUS +if (EPS_INIT_STATUS==1) // Set EPS_INIT_STATUS BAE_STATUS |= 0x00010000; -else if(EPS_INIT_STATUS=='c') // Clear +else if(EPS_INIT_STATUS==0) // Clear BAE_STATUS &= 0xFFFEFFFF; -if (EPS_MAIN_STATUS=='s') // Set EPS_MAIIN_STATUS +if (EPS_MAIN_STATUS==1) // Set EPS_MAIIN_STATUS BAE_STATUS |= 0x00040000; -else if(EPS_MAIN_STATUS=='c') // Clear +else if(EPS_MAIN_STATUS==0) // Clear BAE_STATUS &= 0xFFFBFFFF; -if (EPS_BATTERY_GAUGE_STATUS=='s') // Set EPS_BATTERY_GAUGE_STATUS +if (EPS_BATTERY_GAUGE_STATUS==1) // Set EPS_BATTERY_GAUGE_STATUS BAE_STATUS |= 0x00020000; -else if(EPS_BATTERY_GAUGE_STATUS=='c') // Clear +else if(EPS_BATTERY_GAUGE_STATUS==0) // Clear BAE_STATUS &= 0xFFFDFFFF; -if (EPS_BATTERY_TEMP_STATUS=='s') // Set EPS_BATTERY_TEMP_STATUS +if (EPS_BATTERY_TEMP_STATUS==1) // Set EPS_BATTERY_TEMP_STATUS BAE_STATUS |= 0x00080000; -else if(EPS_BATTERY_TEMP_STATUS=='c') // Clear +else if(EPS_BATTERY_TEMP_STATUS==0) // Clear BAE_STATUS &= 0xFFF7FFFF; if (EPS_STATUS==0) @@ -706,9 +727,9 @@ BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00050000; // Set EPS_BATTERY_HEATER_ON - if(EPS_BATTERY_HEAT_ENABLE == 'e') + if(EPS_BATTERY_HEAT_ENABLE == 1) BAE_ENABLE |= 0x00000080; - else if(EPS_BATTERY_HEAT_ENABLE == 'd') + else if(EPS_BATTERY_HEAT_ENABLE == 0) BAE_ENABLE = BAE_ENABLE &0xFFFFFF7; @@ -721,9 +742,13 @@ printf("\n\r Initialising BAE "); //..........intial status....// ACS_STATE = '4'; - ACS_ATS_ENABLE = 'e'; - ACS_DATA_ACQ_ENABLE = 'e'; - EPS_BATTERY_HEAT_ENABLE = 'e'; + ACS_ATS_ENABLE = 1; + ACS_DATA_ACQ_ENABLE = 1; + EPS_BATTERY_HEAT_ENABLE = 1; + //............intializing pins................// + ATS1_SW_ENABLE = 0; + ATS2_SW_ENABLE = 1; + //............................// FCTN_ACS_INIT(); FCTN_EPS_INIT(); @@ -746,9 +771,9 @@ } */ - //ACS_INIT_STATUS = 'c'; - //ACS_DATA_ACQ_STATUS = 'c'; - gpo1 = 0; + //ACS_INIT_STATUS = 0; + //ACS_DATA_ACQ_STATUS = 0; + FLAG(); FCTN_BAE_INIT(); @@ -775,7 +800,7 @@ t_start.start(); pc.printf("\n\rStarted scheduler %f\n\r",t_start.read()); - gpo1 = 0; // att sens2 switch is enabled + ATS1_SW_ENABLE = 0; // att sens2 switch is enabled //FCTN_BAE_INIT(); while(1); //required to prevent main from terminating }