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

Dependencies:   BMP180 MPU6050 SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Revision:
3:71a45bae8a37
Parent:
2:0cf17bba70ec
Child:
4:4920f8106896
--- a/main.cpp	Fri Oct 20 03:53:03 2017 +0000
+++ b/main.cpp	Sat Oct 21 16:11:16 2017 +0000
@@ -13,6 +13,8 @@
 Timer           timer;
 Timer           alt_timer;
 Ticker          logtimer;
+DigitalOut      oshirase1(p19);
+DigitalInOut    oshirase2(p20);
 Serial          pc(USBTX,USBRX);
 Serial          gps(p13,p14);
 Serial          twe(p9,p10);
@@ -26,6 +28,7 @@
 float   _getAlt(float press, float temp);
 float   _DMS2DEG(float raw_data);
 float   _median(float data[], int num);
+//int     _input(char c);
 
 /*  グローバル変数 */
 float   a[3];
@@ -35,6 +38,7 @@
 float   Pressure,Temperature,Altitude;
 float   Time;
 char    gps_data[256];
+char    c;
 int     cnt_gps;
 int     Log_cnt=0;
 
@@ -44,9 +48,33 @@
     twe.baud(115200); 
     mpu.setAcceleroRange(0);
     bmp.Initialize(64,BMP180_OSS_ULTRA_LOW_POWER);  
+    oshirase2.output();
     mkdir("/sd/mydir", 0777);
-
-    _flight();
+    oshirase1 = 0;
+    oshirase2 = 0;
+/*    while(1){
+        if(_input(c)==-1){
+            oshirase1 = 0;
+            oshirase2 = 1;
+*/            _flight();
+/*            break;
+        }else if(_input(c)==1){
+            oshirase1 = 1;
+            oshirase2 = 0;
+            while(1){
+                if(_input(c)==3){
+                    oshirase1 = 1;
+                    oshirase2 = 1;
+                    break;
+                }else if(_input(c)==7){
+                    oshirase1 = 0;
+                    oshirase2 = 0;
+                    break;
+                }
+            }
+        }
+    }
+*/    while(1);
 }
 
 
@@ -59,6 +87,7 @@
         Alt_buff[i] = _getAlt(Pressure,Temperature);
     }
     Land_Alt = _median(Alt_buff,10);
+    Max_Alt  = Land_Alt;
     FILE *lfp = fopen("/local/alt.txt","a");
     fprintf(lfp,"地上高度:%f\r\n",Land_Alt);
     fclose(lfp);
@@ -67,7 +96,7 @@
     /*  データ取得開始 */
     timer.start();
     logtimer.attach(_log,1.0/RATE);
-    alt_timer.start();
+    alt_timer.start();  //発射判定後にスタートするようにする!!
 
     /*  GPS取得&送信    */
     while(1){
@@ -104,6 +133,7 @@
     mpu.getAccelero(a);
     bmp.ReadData(&Temperature,&Pressure);
     Altitude = _getAlt(Pressure,Temperature);
+    //TODO:発射判定後に行うようにする!!(ここから)
     if(Altitude > Max_Alt){
         Max_Alt = Altitude;
         alt_timer.reset();
@@ -115,6 +145,7 @@
         fprintf(lfp,"最高高度:%f\r\n",Max_Alt);
         fclose(lfp);
     }
+    //TODO:発射判定後に行うようにする!!(ここまで)
     if(Log_cnt==0) {
         fp = fopen("/sd/mydir/sdtest.txt", "a");
     }
@@ -134,6 +165,7 @@
 }
 
 
+/*  緯度経度計算関数    */
 float _DMS2DEG(float raw_data){
     int d = (int)(raw_data/100);
     float m = (raw_data - (float)d*100);
@@ -162,3 +194,14 @@
     delete[] data_cpy;
     return ans;
 }
+
+int _input(char c){
+    if(c!='\0'){
+      // pc.printf("%c\r\n",c);  
+    } 
+    if(c=='f'){
+        // pc.printf("flight mode on\r\n");
+        return -1;
+    }
+    return 0;
+}
\ No newline at end of file