2017.11伊豆大島共同打ち上げ実験のデータ取得&保存用プログラム

Dependencies:   BMP180 MPU6050 SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Revision:
4:4920f8106896
Parent:
3:71a45bae8a37
Child:
5:1e66d892109b
--- a/main.cpp	Sat Oct 21 16:11:16 2017 +0000
+++ b/main.cpp	Sun Oct 22 04:37:12 2017 +0000
@@ -33,14 +33,18 @@
 /*  グローバル変数 */
 float   a[3];
 float   Land_Alt;
-float   Max_Alt=0;
+float   Max_Alt = 0;
 float   Alt_buff[10];
 float   Pressure,Temperature,Altitude;
 float   Time;
 char    gps_data[256];
 char    c;
-int     cnt_gps;
-int     Log_cnt=0;
+int     cnt_gps  = 0;
+int     Log_cnt  = 0;
+int     Phase    = 0;
+bool    Launched = false;
+bool    Opened   = false;
+bool    Leafing  = false;
 
 
 int main() {
@@ -52,12 +56,12 @@
     mkdir("/sd/mydir", 0777);
     oshirase1 = 0;
     oshirase2 = 0;
-/*    while(1){
+    while(1){
         if(_input(c)==-1){
             oshirase1 = 0;
             oshirase2 = 1;
-*/            _flight();
-/*            break;
+            _flight();
+            break;
         }else if(_input(c)==1){
             oshirase1 = 1;
             oshirase2 = 0;
@@ -74,12 +78,13 @@
             }
         }
     }
-*/    while(1);
+    while(1);
 }
 
 
 /*  フライトモード用関数  */
 void _flight(){
+    oshirase2.input();
 
     /*  地上高度取得  */
     for(int i=0;i<10;i++){
@@ -91,15 +96,30 @@
     FILE *lfp = fopen("/local/alt.txt","a");
     fprintf(lfp,"地上高度:%f\r\n",Land_Alt);
     fclose(lfp);
-    for(int i=0;i<10;i++)pc.printf("%f\n\r",Alt_buff[i]);
+//    for(int i=0;i<10;i++)pc.printf("%f\n\r",Alt_buff[i]);
     
     /*  データ取得開始 */
     timer.start();
     logtimer.attach(_log,1.0/RATE);
-    alt_timer.start();  //発射判定後にスタートするようにする!!
 
-    /*  GPS取得&送信    */
     while(1){
+        /*  フェーズ管理  */
+        if(Phase==0){
+            if(oshirase2==1){
+                Phase    = 1;   //上昇フェーズへ移行
+                alt_timer.start();
+            }
+        }else if(Phase==1){
+            if(oshirase2==0){
+                Phase = 2;      //降下1フェーズへ移行
+            }
+        }else if(Phase==2){
+            if(oshirase2==1){
+                Phase = 3;      //降下2フェーズへ移行
+            }
+        }
+
+        /*  GPS取得&送信    */
         gps_data[cnt_gps] = gps.getc();
         if(gps_data[cnt_gps] == '$' || cnt_gps ==256){
             cnt_gps = 0;
@@ -112,7 +132,7 @@
                 if(rlock==1){
                     lat_north = _DMS2DEG(lat_north);
                     lon_east = _DMS2DEG(lon_east);
-                    twe.printf("max altitude:%f\r\n",Max_Alt);
+                    twe.printf("phase:%d,max altitude:%f\r\n",Phase,Max_Alt);
                     twe.printf("%s\r\n",gps_data);
                     twe.printf("Lat:%f,Lon:%f\r\ntime:%f,sat_num:%d\r\n",lat_north,lon_east,world_time,sat_num);
                 }else{
@@ -133,29 +153,31 @@
     mpu.getAccelero(a);
     bmp.ReadData(&Temperature,&Pressure);
     Altitude = _getAlt(Pressure,Temperature);
-    //TODO:発射判定後に行うようにする!!(ここから)
+
+    /*  最高高度取得&保存   */
     if(Altitude > Max_Alt){
-        Max_Alt = Altitude;
-        alt_timer.reset();
+            Max_Alt = Altitude;
+            alt_timer.reset();
     }
     if(alt_timer.read() > MAX_JUDGE_TIME_s){
+        alt_timer.stop();
         alt_timer.reset();
-        alt_timer.stop();
         FILE *lfp = fopen("/local/alt.txt","a");
         fprintf(lfp,"最高高度:%f\r\n",Max_Alt);
         fclose(lfp);
     }
-    //TODO:発射判定後に行うようにする!!(ここまで)
+
+    /*  データ保存   */
     if(Log_cnt==0) {
         fp = fopen("/sd/mydir/sdtest.txt", "a");
     }
-    fprintf(fp, "%f, %f, %f, %f, %f, %f, %f \r\n",Time, Temperature, Pressure, Altitude, a[0],a[1],a[2]);
+    fprintf(fp, "%d,%f, %f, %f, %f, %f, %f, %f \r\n",Phase, Time, Temperature, Pressure, Altitude, a[0],a[1],a[2]);
     Log_cnt++;
     if(Log_cnt==RATE){
         fclose(fp);
         Log_cnt = 0;
     }
-    pc.printf("%f, %f, %f, %f, %f, %f, %f \r\n",Time, Temperature, Pressure, Altitude, a[0],a[1],a[2]);
+//    pc.printf("%d,%f, %f, %f, %f, %f, %f, %f \r\n",Phase, Time, Temperature, Pressure, Altitude, a[0],a[1],a[2]);
 }
 
 
@@ -202,6 +224,12 @@
     if(c=='f'){
         // pc.printf("flight mode on\r\n");
         return -1;
+    }else if(c=='s'){
+        return 1;
+    }else if(c=='p'){
+        return 3;
+    }else if(c=='l'){
+        return 7;
     }
     return 0;
 }
\ No newline at end of file