2019伊豆のコード

Dependencies:   mbed LSM9DS1 IM920 SDFileSystem LPS331 ADXL345_I2C GPS_Interface millis

Revision:
2:cad76b5be4ba
Parent:
0:cebf1f73ffd5
Child:
3:1f93c4510fb1
diff -r c2829a442621 -r cad76b5be4ba main.cpp
--- a/main.cpp	Sat Mar 02 15:20:47 2019 +0000
+++ b/main.cpp	Wed Mar 06 05:35:46 2019 +0000
@@ -8,7 +8,7 @@
 #include "LPS22HB.h"
 
 //ピン
-DigitalInOut flightpin(p12);
+DigitalIn flightpin(p12);
 Serial pc(USBTX, USBRX);
 LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH);
 LSM9DS1 lsm(p9,p10);
@@ -40,8 +40,8 @@
     init(&fp);//初期化
     
     //サーボclose
-    //servo_1.pulsewidth(0.76/1000);//ms/1000
-    //servo_2.pulsewidth(1.94/1000);
+    servo_1.pulsewidth(0.89/1000);//ms/1000
+    servo_2.pulsewidth(1.94/1000);
     
     while(strncmp(receive,"start",sizeof(receive))!=0){//無線での開始指令待ち txda tartと受信したら計測開始
         im920.poll();
@@ -62,7 +62,7 @@
             im920.send("Mbed reset",11);
             NVIC_SystemReset();
         }
-        if(lsm.ax*lsm.ax+lsm.ay*lsm.ay+lsm.az*lsm.az>=4.0/*&&flightpinAttached==false*/){//加速度2.0G以上かつフライトピンがぬけていたらコマンドがなくても開始
+        if(lsm.ax*lsm.ax+lsm.ay*lsm.ay+lsm.az*lsm.az>=4.0 &&flightpinAttached==false){//加速度2.0G以上かつフライトピンがぬけていたらコマンドがなくても開始
             im920.send("Forced start",13);
             break;
         }
@@ -83,17 +83,17 @@
         //センサ・フライトピン読み取り 高度計測
         readValues(sequence);
         flightpinAttached=flightpin;
-        altitude=calcAltitude(lps331.pressure,lps331.temperature);
+        altitude=calcAltitude(lps331.getPressure(),lps331.getTemperature());
         
         pc.printf("%.2f\r\n",(float)timer/1000);
-        /*pc.printf("%f,%f\r\n", lps331.pressure, lps331.temperature);
+        /*pc.printf("%f,%f\r\n", lps331.getPressure(), lps331.getTemperature());
         pc.printf("accX=%.3f / accY=%.3f / accZ=%.3f\r\n",lsm.ax,lsm.ay,lsm.az);
         pc.printf("gyroX=%.3f / gyroY=%.3f / gyroZ=%.3f\r\n",lsm.gx,lsm.gy,lsm.gz);
         pc.printf("magnX=%.3f / magnY=%.3f / magnZ=%.3f\r\n",lsm.mx,lsm.my,lsm.mz);
         pc.printf("\r\n");*/
         
         //地上局への送信
-        if(timer%1000==0){//1秒おきに経過時間送信
+        if(timer%5000==0){//5秒おきに経過時間送信
             im920.send(valueToChar((float)timer/1000),7);
         }
         
@@ -117,8 +117,8 @@
                     im920.send("Start speed reducing",21);
                     reducerExpantionedTime=timer;
                     //サーボopen
-                    //servo_1.pulsewidth(1.28/1000);//ms/1000
-                    //servo_2.pulsewidth(1.32/1000);
+                    servo_1.pulsewidth(1.28/1000);//ms/1000
+                    servo_2.pulsewidth(1.32/1000);
                     sequence=2;
                 }
                 break;
@@ -134,10 +134,10 @@
         //SD書き込み time,temp,pres,temp_hw,pres_hw,accXYZ,gyroXYZ,magnXYZ,longitude,latitude
         if(sequence==1){//飛行中
             fprintf(fp,"%.2f,%f,%f,%f,%f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\r\n",
-            (float)timer/1000,lps331.temperature,lps331.pressure,lps33hw.temperature(),lps33hw.pressure(),lsm.ax,lsm.ay,lsm.az,lsm.gx,lsm.gy,lsm.gz,lsm.mx,lsm.my,lsm.mz);
+            (float)timer/1000,lps331.getTemperature(),lps331.getPressure(),lps33hw.temperature(),lps33hw.pressure(),lsm.ax,lsm.ay,lsm.az,lsm.gx,lsm.gy,lsm.gz,lsm.mx,lsm.my,lsm.mz);
         }else{//飛行中以外はGPS情報も保存
             fprintf(fp,"%.2f,%f,%f,%f,%f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%f,%f\r\n",
-            (float)timer/1000,lps331.temperature,lps331.pressure,lps33hw.temperature(),lps33hw.pressure(),lsm.ax,lsm.ay,lsm.az,lsm.gx,lsm.gy,lsm.gz,lsm.mx,lsm.my,lsm.mz,gps.longitude,gps.latitude);
+            (float)timer/1000,lps331.getTemperature(),lps331.getPressure(),lps33hw.temperature(),lps33hw.pressure(),lsm.ax,lsm.ay,lsm.az,lsm.gx,lsm.gy,lsm.gz,lsm.mx,lsm.my,lsm.mz,gps.longitude,gps.latitude);
         }
         
         timer+=timeInterval;
@@ -184,7 +184,8 @@
     }
     
     //LPS33HW
-    if(lps33hw.whoAmI()){
+
+    if(!lps33hw.whoAmI()){// who_am_i == b1 → false
         pc.printf("LPS33HW is available\r\n");
         im920.send("LPS33HW...OK",13);
     }else {
@@ -220,7 +221,7 @@
     }
     
     //フライトピン
-    flightpin.output();
+    //flightpin.output();
     
     //各種設定
     lps331.setResolution(LPS331_I2C_PRESSURE_AVG_512, LPS331_I2C_TEMP_AVG_128);
@@ -251,7 +252,7 @@
     }
     
     //LPS33HW
-    if(lps33hw.whoAmI()){
+    if(!lps33hw.whoAmI()){
         pc.printf("LPS33HW is available\r\n");
         im920.send("LPS33HW...OK",13);
     }else {