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

Dependencies:   BMP180 MPU6050 SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
oichan
Date:
Sun Oct 29 13:40:18 2017 +0000
Parent:
5:1e66d892109b
Child:
7:5f8080485160
Commit message:
10/29 fm test model

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Oct 22 15:07:04 2017 +0000
+++ b/main.cpp	Sun Oct 29 13:40:18 2017 +0000
@@ -15,7 +15,7 @@
 Ticker          logtimer;
 DigitalOut      oshirase1(p19);
 DigitalInOut    oshirase2(p20);
-Serial          pc(USBTX,USBRX);
+//Serial          pc(USBTX,USBRX);
 Serial          gps(p13,p14);
 Serial          twe(p9,p10);
 SDFileSystem    sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
@@ -28,7 +28,7 @@
 float   _getAlt(float press, float temp);
 float   _DMS2DEG(float raw_data);
 float   _median(float data[], int num);
-int     _input(char c);
+int     _input(char moji);
 
 /*  グローバル変数 */
 float   a[3];
@@ -39,35 +39,38 @@
 float   Time;
 char    gps_data[256];
 char    c;
+char    command;
 int     cnt_gps  = 0;
 int     Log_cnt  = 0;
 int     Phase    = 0;
 
 
 int main() {
-    printf("Hello World!\n");
+//    pc.printf("Hello World!\n");
+    oshirase2.output();
+    oshirase1 = 0;
+    oshirase2 = 0;
     twe.baud(115200); 
     mpu.setAcceleroRange(0);
     bmp.Initialize(64,BMP180_OSS_ULTRA_LOW_POWER);  
-    oshirase2.output();
     mkdir("/sd/mydir", 0777);
-    oshirase1 = 0;
-    oshirase2 = 0;
     while(1){
-        if(_input(c)==-1){
+        command = twe.getc();
+        if(_input(command)==-1){        //フライトモードへ移行
             oshirase1 = 0;
             oshirase2 = 1;
             _flight();
             break;
-        }else if(_input(c)==1){
+        }else if(_input(command)==1){   //サーボ動かすだけモードへ
             oshirase1 = 1;
             oshirase2 = 0;
             while(1){
-                if(_input(c)==3){
+                command = twe.getc();
+                if(_input(command)==3){         //開放用サーボ(MG996)を動かす
                     oshirase1 = 1;
                     oshirase2 = 1;
                     break;
-                }else if(_input(c)==7){
+                }else if(_input(command)==7){   //リーフィングのサーボ(SG92)を動かす
                     oshirase1 = 0;
                     oshirase2 = 0;
                     break;
@@ -82,6 +85,8 @@
 /*  フライトモード用関数  */
 void _flight(){
     oshirase2.input();
+    twe.printf("flight mode on\r\n");
+//    pc.printf("flight mode on\r\n");
 
     /*  地上高度取得  */
     for(int i=0;i<10;i++){
@@ -93,13 +98,15 @@
     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]);
+    twe.printf("地上高度:%f\r\n",Land_Alt);
+//    for(int i=0;i<10;i++)pc.printf("%f\n\r",Alt_buff[i]);
     
     /*  データ取得開始 */
     timer.start();
     logtimer.attach(_log,1.0/RATE);
 
     while(1){
+
         /*  フェーズ管理  */
         if(Phase==0){
             if(oshirase2==1){
@@ -115,6 +122,11 @@
                 Phase = 3;  //降下2フェーズへ移行
             }
         }
+        
+        /*  30分ごとにタイマーをリセット(オーバーフロー対策)  */
+        if(Time > 60*30){
+            timer.reset();
+        }
 
         /*  GPS取得&送信    */
         gps_data[cnt_gps] = gps.getc();
@@ -133,7 +145,7 @@
                     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{
-                    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);
                 }
             }
@@ -155,13 +167,13 @@
     if(Altitude > Max_Alt){
             Max_Alt = Altitude;
             alt_timer.reset();
-    }
-    if(alt_timer.read() > MAX_JUDGE_TIME_s){
+    }else if(alt_timer.read() > MAX_JUDGE_TIME_s){
         alt_timer.stop();
         alt_timer.reset();
         FILE *lfp = fopen("/local/alt.txt","a");
         fprintf(lfp,"最高高度:%f\r\n",Max_Alt);
         fclose(lfp);
+//        pc.printf("最高高度:%f\r\n",Max_Alt);
     }
 
     /*  データ保存   */
@@ -174,7 +186,7 @@
         fclose(fp);
         Log_cnt = 0;
     }
-    pc.printf("%d,%f, %f, %f, %f, %f, %f, %f \r\n",Phase, 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]);
 }
 
 
@@ -214,18 +226,18 @@
     return ans;
 }
 
-int _input(char c){
-    if(c!='\0'){
-       pc.printf("%c\r\n",c);  
+/*  コマンド判別用関数   */
+int _input(char moji){
+    if(moji!='\0'){
+       twe.printf("%c\r\n",c);  
     } 
-    if(c=='f'){
-         pc.printf("flight mode on\r\n");
+    if(moji=='f'){
         return -1;
-    }else if(c=='s'){
+    }else if(moji=='s'){
         return 1;
-    }else if(c=='p'){
+    }else if(moji=='p'){
         return 3;
-    }else if(c=='l'){
+    }else if(moji=='l'){
         return 7;
     }
     return 0;