this program is designed for the CHITISAT's OBC, and is a prototype for the flight plan vs altitude

Dependencies:   ADS1015 BMP280 SDFileSystem SENSOR mbed

Revision:
1:a147ca4f8fa0
Parent:
0:642a7818292a
Child:
2:ba3323e788fc
diff -r 642a7818292a -r a147ca4f8fa0 main.cpp
--- a/main.cpp	Fri Jun 08 21:35:41 2018 +0000
+++ b/main.cpp	Thu Jun 14 13:17:54 2018 +0000
@@ -1,4 +1,4 @@
-       /*Programa principal del computador a bordo del cubesat "CHITISAT"
+/*Programa principal del computador a bordo del cubesat "CHITISAT"
 */
 //***********************************************************************
 #include "mbed.h"
@@ -11,7 +11,6 @@
 //***** declaracion de puertos
 SDFileSystem sd(PA_12, PA_6, PA_1, PB_0 , "sd");// puerto SPI para el Storage
 //LocalFileSystem sd("local");// puerto SPI para el Storage
-
 Serial sc(PB_6, PB_7,9600); //puerto para el sistema de comunicacioness
 //I2C i2c(PB_4,PA_7);             // puerto i2c    
 BMP280 bmp(i2c,0xEC);           //Default address = 0x76
@@ -24,7 +23,7 @@
 AnalogIn corriente(PA_3);       // sensor analogico de corriente
 AnalogIn temp3(ADC_TEMP);       //sensor de temperatura del arm
 DigitalOut Vcondicional(PA_8); //encendido de los sensores(logica negada)
-DigitalOut camara(PB_5);
+DigitalOut camera(PB_5);
 DigitalOut led(PB_3);
 MPU6050 mpu6050;
 Timer t;
@@ -97,6 +96,7 @@
     //******* inicio
     obc.printf("iniciando sensores:\n");
     //encenciendo sensores
+    wait(2);
     Vcondicional=0;
     //iniciando camara    
         camera=0;
@@ -155,10 +155,10 @@
                         take_mision();
                         h=get_altura();
                         save_tl();
-                        tipo=2;
+                        build_tr2();
+                        tipo=3;
                         RS[12]= guardar(tipo);
                         save_mision();
-                        build_tr2();
                         send_tr();
                         obc.printf("altura minima con tc1 %f\n",h);
                         }
@@ -168,9 +168,9 @@
                         take_tl();
                         h=get_altura();
                         save_tl();
-                        tipo=2;
+                        build_tr1();
+                        tipo=3;
                         RS[12]= guardar(tipo);
-                        build_tr1();
                         send_tr();
                         obc.printf("altura minima con tc %f\n",h);
                         }
@@ -196,25 +196,32 @@
     sc.putc(stby);
     obc.printf("standby: %d",stby);
     }
-    float hant=h;
-    float hact=get_altura();
-    while(hact>=0){
+    float hant;
+    hant=altura1;
+    h=get_altura();
+    float hact=altura1;
+    float dif;
+    dif=hant-hact;
+    obc.printf("altan=%f altac=%f dif=%f\n",hant,hact,dif);
+    while(dif!=0){
         obc.printf("********************sleep mode**************************");
     //while(hact!=0.0){
         hant=hact;
-        hact=get_altura();
+        h=get_altura();
+        hact=altura1;
         take_tl();
         take_mision();
         save_tl();
         tipo=2;
         RS[12]= guardar(tipo);
         save_mision();
-        hact=hact-hant;
-        obc.printf("diferente de cero alt=%f\n",h);
+        dif=hant-hact;
+        obc.printf("diferente de cero\n altan=%f altac=%f dif=%f\n",hant,hact,dif);
+        led=!led;
         }
     //******* OFF MODE
     //camara=1;       // apagando camara
-        wait(0.5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    );
+        wait(0.5);
         camera=0;
         wait(1);
         camera=1;
@@ -226,7 +233,8 @@
     obc.printf("sos: %d\n",sos);
     //obc.printf("%d\n",alt);
     //activar modo reset
-    PWR_EnterSTANDBYMode();
+    HAL_PWR_EnterSTANDBYMode ();
+
     //apagar obc
 }
 //********* Funciones
@@ -252,23 +260,23 @@
     mpu6050.getAres();
     
     // Now we'll calculate the accleration value into actual g's
-    imu[3] = (float)accelCount[0]*aRes - accelBias[0];  // get actual g value, this depends on scale being set
-    imu[4]= (float)accelCount[1]*aRes - accelBias[1];   
-    imu[5]= (float)accelCount[2]*aRes - accelBias[2];  
+    imu[3]= accelCount[0];//*aRes - accelBias[0];  // get actual g value, this depends on scale being set
+    imu[4]= accelCount[1];//*aRes - accelBias[1];   
+    imu[5]= accelCount[2];//*aRes - accelBias[2];  
    
     mpu6050.readGyroData(gyroCount);  // Read the x/y/z adc values
     mpu6050.getGres();
  
     // Calculate the gyro value into actual degrees per second
-    imu[6]= (float)gyroCount[0]*gRes; // - gyroBias[0];  // get actual gyro value, this depends on scale being set
-    imu[7]= (float)gyroCount[1]*gRes; // - gyroBias[1];  
-    imu[8]= (float)gyroCount[2]*gRes; // - gyroBias[2];   
+    imu[6]= gyroCount[0];//*gRes; // - gyroBias[0];  // get actual gyro value, this depends on scale being set
+    imu[7]= gyroCount[1];//*gRes; // - gyroBias[1];  
+    imu[8]= gyroCount[2];//*gRes; // - gyroBias[2];   
     float temobcount = mpu6050.readTempData();  // Read the x/y/z adc values
     temperature = (temobcount) / 340. + 36.53; // Temperature in degrees Centigrade
    }  
     for(i=3;i<=8;i++){
         //imu.read();       
-        IMU[i]=imu[i]*10;//para la toma de datos
+        IMU[i]=imu[i];//*10;//para la toma de datos
         //obc.printf("%d\n",IMU[i]);
         }
     press=bmp.getPressure();
@@ -286,11 +294,21 @@
     }
     
 void take_mision(void){
+        int h1, h2, tiempo;
+        h1=altura1*10;
+        h2=h*10;
+        tiempo=t.read();
+        tiempo=tiempo*100;
+        senfis[0]=h1;
+        senfis[1]=h2;
+        senfis[2]=tiempo;
+        /*
         ads.setGain(GAIN_TWOTHIRDS);
         for(int i=0;i<=3;i++){
         senfis[i]= ads.readADC_SingleEnded(i);
+        */
        // obc.printf("\n senfis%d:%d 0x%.4x\n",i,senfis[i],senfis[i]);
-        }
+        //}
         obc.printf("tomando mision\n");
     }
 void save_tl(void){ 
@@ -464,7 +482,7 @@
             Pp[i]= bmp.getPressure();          // pi es la condicion inical para la presion 
             Ps=Ps+Pp[i];
             led=!led;
-            //obc.printf("%.2f\n",Pp[i]);
+            obc.printf("%.2f\n",Pp[i]);
             wait(0.05);
             }
             //LA MEDIA DE TODOS LOS DATOS NOS DA LA PRESION REAL
@@ -562,7 +580,7 @@
              BR=1;// abbrir documento de condiciones iniciles y cambiar Br para doocumentar el resetprogramado
                     NVIC_SystemReset();}
                 fscanf(dp,"%d",&ND);
-            fclose(dp);
+             fclose(dp);
             ND=ND+1;
                         // creando la carpeta y guardando los datos iniciales en la carpeta de datos de prueba
              FILE *dp1=fopen("/sd/carpetas/numero.txt","w");
@@ -626,12 +644,23 @@
     }
     else
     {
-        FILE *pp=fopen(file,"a");
-        if (pp == NULL) {printf("no se inicion 5...");}
-        fprintf(pp,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\r\n",t.read(),imu[0],imu[1],imu[2],imu[3],imu[4],imu[5],imu[6],imu[7],imu[8],press,temperature,temp[1],sensor_adc[0],sensor_adc[1],sensor_adc[2],suv,h);
-        //fprintf(pp,"%f %f %f %f %f\r\n",t.read(),BMPTemp,P,h,altura1); //guarda en el sd
-        fclose(pp);
-        return (2);
+        if(tipo==2)
+        {
+            FILE *pp=fopen(file,"a");
+            if (pp == NULL) {printf("no se inicion 5...");}
+            fprintf(pp,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\r\n",t.read(),imu[0],imu[1],imu[2],imu[3],imu[4],imu[5],imu[6],imu[7],imu[8],press,temperature,temp[1],sensor_adc[0],sensor_adc[1],sensor_adc[2],suv,h);
+            //fprintf(pp,"%f %f %f %f %f\r\n",t.read(),BMPTemp,P,h,altura1); //guarda en el sd
+            fclose(pp);
+            return (2);
+        }
+        else
+        {
+            FILE *pp=fopen(file,"a");
+            if (pp == NULL) {printf("no se inicion 5...");}
+            fprintf(pp,"%f %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \r\n",t.read(),trama[0],trama[1],trama[2],trama[3],trama[4],trama[5],trama[6],trama[7],trama[8], trama[9],trama[10],trama[11],trama[12],trama[13],trama[14],trama[15],trama[16],trama[17],trama[18], trama[19],trama[20],trama[21],trama[22],trama[23],trama[24],trama[25],trama[26],trama[27],trama[28], trama[29], trama[30]);
+            //fprintf(pp,"%f %f %f %f %f\r\n",t.read(),BMPTemp,P,h,altura1); //guarda en el sd
+            fclose(pp);
+            return (2);
+        }
     }
-    
 }
\ No newline at end of file