201803_oshima Team.F.C.

Dependencies:   BMP180 MPU6050 SDFileSystem mbed

Fork of 201803_oshima_jodan by Haruki Sashida

Revision:
14:16a16047aed2
Parent:
13:4c1633775de7
Child:
17:6538f06e2f47
--- a/main.cpp	Sun Mar 18 01:20:54 2018 +0000
+++ b/main.cpp	Mon Mar 19 17:09:25 2018 +0000
@@ -6,8 +6,9 @@
 
 #define UNLOCK 1
 #define LOCK 0
+#define HANTEI 12 //判定開始タイマー
 #define TIMER 30 //開放タイマー
-#define RATE 50//判定周期 謎の不具合により、145行目のkaihou.attach(_open,1/RATE);はコメントアウトしてるので、直接数字をいじってください
+#define RATE 50.0//判定周期 浮動小数点型で記述してください
 #define ALT 1 //落下判断高度
  
 SDFileSystem    sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
@@ -21,6 +22,7 @@
 Serial          gps(p13,p14);
 Serial          pc(USBTX,USBRX);
 PwmOut          servo_para(p22);
+PwmOut          servo_para2(p23);
 
 LocalFileSystem local("local");
 FILE *fp;
@@ -93,9 +95,10 @@
         }
 
     }
-    
-    mpu.setAcceleroRange(0);
-    mpu.setGyroRange(0);
+yabai:
+
+    mpu.setAcceleroRange(3);
+    mpu.setGyroRange(3);
     bmp.Initialize(60,BMP180_OSS_ULTRA_LOW_POWER);
     twe.printf("I2C_initialize_ok\r\n");
     
@@ -115,6 +118,7 @@
     fclose(lfp);
     twe.printf("lacal_ok\r\n");
     
+    mkdir("/sd/mydir", 0777);
     fp = fopen("/sd/mydir/sdtest.txt", "a");
     if(fp == NULL) {
         error("Could not open file for write\n");
@@ -132,16 +136,15 @@
     
     while(fly == 1);        //フライトピン抜けるまで待機
     
-yabai:
-    twe.printf("SEPARATE!!!!!!!\r\n");
+
+    twe.printf("launch!!!!!!!\r\n");
     i = 0;
     Alt_buff[0] = 0;
     fp = fopen("/sd/mydir/sdtest.txt", "a");
     if(fp == NULL)twe.printf("ERROR\r\n");
     timer1.start();
-//    kaihou.attach(_open,1/RATE);
-    kaihou.attach(_open,0.02);
-    
+    kaihou.attach(_open,1.0/RATE);
+
     
     while(1){
 
@@ -190,7 +193,7 @@
         fprintf(fp, "%f,%f,%f,%f,%f,%f,%f,%d,%d\r\n",Alt_now,a[0],a[1],a[2],d[0],d[1],d[2],t,Cnt_para); 
         if(Alt_now > Max_Alt) Max_Alt = Alt_now;
         i = 0;
-        if(tf_para == true){    //パラ開くまでは頂点判定
+        if(tf_para == true && t > HANTEI ){    //パラ開くまでは頂点判定
             Alt_buff[Cnt_buff+1] = Alt_now; 
             if(Alt_buff[Cnt_buff]-Alt_buff[Cnt_buff+1] > ALT) Cnt_para++; //直前の値(0.2秒前より1ALTm降下)より小さければカウント+1
 //            twe.printf("Cnt_para:%d\r\n", Cnt_para); 
@@ -272,9 +275,11 @@
 
 void _para(int motion){
     if(motion==UNLOCK){
-            servo_para.pulsewidth(0.001); // pulse servo out sita
+            servo_para.pulsewidth(0.0008); // pulse servo out sita
+            servo_para2.pulsewidth(0.0008);
     }else if(motion==LOCK){
-            servo_para.pulsewidth(0.002); // pulse servo outu sita     
+            servo_para.pulsewidth(0.0023); // pulse servo outu sita
+            servo_para2.pulsewidth(0.0023);     
     }
 }