2018年度計器mbed用プログラム

Dependencies:   BufferedSoftSerial2 INA226_ver1 mbed-rtos mbed SDFileSystem-RTOS

Fork of keiki2017 by albatross

Files at this revision

API Documentation at this revision

Comitter:
tsumagari
Date:
Sat Jan 28 10:17:50 2017 +0000
Branch:
noThread2017ver.
Parent:
26:50272431cd1e
Child:
28:02e21f1fbe3d
Child:
33:69ad9920f693
Commit message:
Thread??ver.????????????????????????

Changed in this revision

BufferedSoftSerial.lib Show annotated file Show diff for this revision Revisions of this file
Cadence.h Show annotated file Show diff for this revision Revisions of this file
Cadence.h.orig Show diff for this revision Revisions of this file
Fusokukei.h Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/BufferedSoftSerial.lib	Wed Jan 25 12:24:10 2017 +0000
+++ b/BufferedSoftSerial.lib	Sat Jan 28 10:17:50 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/tsumagari/code/BufferedSoftSerial/#050e2b137e78
+http://developer.mbed.org/users/Sissors/code/BufferedSoftSerial/#671a6724ce79
--- a/Cadence.h	Wed Jan 25 12:24:10 2017 +0000
+++ b/Cadence.h	Sat Jan 28 10:17:50 2017 +0000
@@ -2,64 +2,52 @@
 #define CADENCE_H
 
 #include "mbed.h"
+#include "BufferedSoftSerial.h"
 #include <string>
 
-class Cadence : public RawSerial{
+double cadence;
+
+class Cadence : public /*BufferedSoft*/RawSerial{
     private:
-    static const int DATAS_NUM = 75;
-    
+    static const int DATAS_NUM = 69 + 4 + 1; //経過時間の文字数は最大4
+//;1816; 00 00000 0;168 ;001; 10133 e9;34 00;00 0e;00 00;10 70;06 89;G; -005; -009; -006;    //2+4+67+2(\r\n)
+//                                     -- --                                        ----
     protected:
     
     public:
-    string strC,strV;
+    char strC[4],strV[4];
     char data[DATAS_NUM];
     string strData;
     int data_count, data_num;
-    double cadence, voltage;
-    Cadence(PinName tx, PinName rx, const char* name = NULL) : RawSerial(tx, rx){
+    double voltage, safeflag;
+    int cadence_i, voltage_i;
+    Cadence(PinName tx, PinName rx/*, const char* name = NULL*/) : /*BufferedSoft*/RawSerial(tx, rx/*, NULL*/){
         for(int i=0;i<DATAS_NUM;i++) data[i]= NULL;
-        data_num=0;
         data_count=0;
         baud(115200);
         cadence=0;
         voltage=0;
+        strC[0] = '0';
+        strV[0] = '0';
     }
     void readData(){ //Ticker で定期的に呼び出して値を更新
-      if(readable()){
+      if(readable()){ 
         data_count = 0;
-        data_num = 0;
-        cadence = 0;
         do{
-            if(readable()) {
+            if(readable()){
                 data[data_count] = getc();
-                data_count++;
+                if(data[data_count] != '\n') data_count++;
             }
-        }while(data[data_count-1] != '\n');
-        strData = data;
-        if( int strlength = strData.length() > DATAS_NUM-4 ){
-//            for(int i = 0; i<4; i++){
-//                strC += data[data_count-6+i];
-//                strV += data[data_count-43+i];
-//            }
-            switch (strData.length()){
-                case DATAS_NUM-3 :
-                    strData.erase(0,2);
-                    break;
-                case DATAS_NUM-2 :
-                    strData.erase(0,3);
-                    break;
-                case DATAS_NUM-1 :
-                    strData.erase(0,4);
-                    break;
-                case DATAS_NUM :
-                    strData.erase(0,5);
+        }while( data[data_count-1] != '\r' && data_count < DATAS_NUM );
+        if( data_count > 71 ) {
+            for(int i = 0; i<4; i++){
+                strC[i] = data[data_count - 6 + i]; // 7 = 5 + 1
+                strV[i] = data[data_count - 43 + i]; // 44 = 42 + 1
             }
-            strV = strData.substr(26,4);
-            strC = strData.substr(64,4);
-            sscanf(strV.c_str(),"%lf",&voltage);
-            sscanf(strC.c_str(),"%lf",&cadence);
-            cadence /= 6.0;
-            voltage *= 0.001;
+            sscanf(strC,"%4d",&cadence_i);
+            sscanf(strV,"%4d",&voltage_i);
+            cadence = cadence_i/6.0;
+            voltage = voltage_i/1000.0;
         }
       }
     }
--- a/Cadence.h.orig	Wed Jan 25 12:24:10 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-#ifndef CADENCE_H
-#define CADENCE_H
-
-#include "mbed.h"
-#include <string>
-
-class Cadence : public RawSerial{
-    private:
-    static const int DATAS_NUM = 75;
-    
-    protected:
-    
-    public:
-    string strC,strV;
-    char data[DATAS_NUM];
-    string strData;
-    int data_count, data_num;
-    double cadence, voltage;
-    Cadence(PinName tx, PinName rx, const char* name = NULL) : RawSerial(tx, rx){
-        for(int i=0;i<DATAS_NUM;i++) data[i]= NULL;
-        data_num=0;
-        data_count=0;
-        baud(115200);
-        cadence=0;
-        voltage=0;
-    }
-    void readData(){ //Ticker で定期的に呼び出して値を更新
-        data_count = 0;
-        data_num = 0;
-        cadence = 0;
-        do{
-            if(readable()) {
-                data[data_count] = getc();
-                data_count++;
-            }
-        }while(data[data_count-1] != '\n');
-        
-        strData = data;
-        if(strData.length() > DATAS_NUM-4 ){
-            switch (strData.length()){
-                case DATAS_NUM-3 :
-                    strData.erase(0,2);
-                    break;
-                case DATAS_NUM-2 :
-                    strData.erase(0,3);
-                    break;
-                case DATAS_NUM-1 :
-                    strData.erase(0,4);
-                    break;
-                case DATAS_NUM :
-                    strData.erase(0,5);
-            }
-            strV = strData.substr(26,4);
-            strC = strData.substr(64,4);
-            sscanf(strV.c_str(),"%lf",&voltage);
-            sscanf(strC.c_str(),"%lf",&cadence);
-            //cadence /= 6.0;
-//            voltage *= 0.001;
-        }
-    }
-};
-#endif
\ No newline at end of file
--- a/Fusokukei.h	Wed Jan 25 12:24:10 2017 +0000
+++ b/Fusokukei.h	Sat Jan 28 10:17:50 2017 +0000
@@ -4,7 +4,7 @@
 #include "mbed.h"
 
 
-#define AIR_K 4.70581884 //0.14737
+#define AIR_K 4.70591884 //0.14737
 #define AIR_N 1.12
 #define AIR_A 1.4314
 #define AIR_B 0.209
@@ -18,7 +18,6 @@
 float air_sum[AIR_SUM_NUM] = {0.0};
 
 class Fusokukei{
-    double air_r;
     protected:
     
     public:      
@@ -35,8 +34,7 @@
     }
     
     void calcAirSpeed(float x){
-          air_r = x/150;
-          air_sum[air_counter % AIR_SUM_NUM] = (float)AIR_K * (float)pow(air_r, 1 / AIR_N);
+          air_sum[air_counter % AIR_SUM_NUM] = (float)AIR_K * (float)pow((double)(x/150.0), 1 / AIR_N);
           if(air_counter % AIR_SUM_NUM == 0)
             air_counter = 0;
           airSpeed_ave = make_ave(air_sum, AIR_SUM_NUM);
--- a/SDFileSystem.lib	Wed Jan 25 12:24:10 2017 +0000
+++ b/SDFileSystem.lib	Sat Jan 28 10:17:50 2017 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
+http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- a/main.cpp	Wed Jan 25 12:24:10 2017 +0000
+++ b/main.cpp	Sat Jan 28 10:17:50 2017 +0000
@@ -1,30 +1,22 @@
 //計器プログラム
-
 #include "mbed.h"
-#include "rtos.h"
+//#include "rtos.h"
 #include "Fusokukei.h"
 #include "MPU6050.h"
-#include "SDFileSystem.h"
 #include "BufferedSoftSerial.h"
 #include "Cadence.h"
 
-#define KX_VALUE_MIN 0.4
-#define KX_VALUE_MAX 0.8
 #define SOUDA_DATAS_NUM 18
-#define YOKUTAN_DATAS_NUM 14
-#define WRITE_DATAS_NUM 18
+#define WRITE_DATAS_NUM 20
+#define SD_WRITE_NUM 1
+#define MPU_LOOP_TIME 0.01
 #define AIR_LOOP_TIME 0.01
 #define WRITE_DATAS_LOOP_TIME 1
 #define ROLL_R_MAX_DEG 2
 #define ROLL_L_MAX_DEG 2
-#define SD_WRITE_NUM 20
+#define MPU_DELT_MIN 250
 #define INIT_SERVO_PERIOD_MS 20
 
-#define MPU_LOOP_TIME 0.01
-#define MPU_DELT_MIN 250
-
-Mutex ssMutex;
-
 //-----------------------------------(resetInterrupt def)
 extern "C" void mbed_reset();
 InterruptIn resetPin(p26);
@@ -38,77 +30,55 @@
 }
 //-------------------------------------------------------
 
-
-Cadence cadence(p13,p14);
-
 RawSerial pc(USBTX,USBRX);
-//RawSerial Android(p13,p14);
+RawSerial android(p9,p10);
+BufferedSoftSerial soudaSerial(p17,p18);
 BufferedSoftSerial twe(p11,p12);
-RawSerial Android(p9,p10);
-BufferedSoftSerial soudaSerial(p17,p18);
-//Ticker writeDatasTicker;
+Cadence cadence_twe(p13,p14);
+Ticker cadenceUpdateTicker;
+Ticker writeDatasTicker;
 Timer writeTimer;
 
-InterruptIn FusokukeiPin(p22);
+InterruptIn FusokukeiPin(p23);
 Ticker FusokukeiTicker;
 Fusokukei air;
 volatile int air_kaitensu= 0;
 
+Timer sonarTimer;
+AnalogIn sonarPin(p15);
+//InterruputIn sonarPin(p15);
+//double sonarDistTime
+double sonarDist;
+float sonarV;
+
+
 float sum = 0;
 uint32_t sumCount = 0;
 MPU6050 mpu6050;
 Timer t;
-//
-//AnalogIn kx_X(p17);
-//AnalogIn kx_Y(p16);
-//AnalogIn kx_Z(p15);
-//float KX_X,KX_Y,KX_Z;
-
-
-//Timer sonarTimer;
-//InterruptIn sonarPin(p22);
-AnalogIn sonarPin(p15);
-//double sonarDistTime=0;
-double sonarV = 0.0, sonarDist = 0.0;
+Ticker mpu6050Ticker;
 
 DigitalOut RollAlarmR(p20);
 DigitalOut RollAlarmL(p19);
-//DigitalOut led(LED1);
+DigitalOut led(LED1);
 DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-
-SDFileSystem sd(p5, p6, p7, p8, "sd");
-FILE* fp;
-
-PwmOut kisokuServo(p26);
-PwmOut geikakuServo(p22);
 
 char soudaDatas[SOUDA_DATAS_NUM];
 float writeDatas[SD_WRITE_NUM][WRITE_DATAS_NUM];
 volatile int write_datas_index = 0;
 
-void cadenceDataReceive();
 void air_countUp();
 void call_calcAirSpeed();
+void sonarInterruptStart();
+void sonarInterruptStop();
 void init();
 void FusokukeiInit();
-void SdInit();
 void MpuInit();
-//void SonarInit();
 void mpuProcessing();
 void DataReceiveFromSouda();
-void SDprintf(void const *argument);
 void WriteDatas();
-//float calcAttackAngle();
-//float calcKXdeg(float x);
-
-void cadenceDataReceive(){
-    while(1){
-        cadence.readData();
-        Thread::wait(0.01);
-    }
-}
+float calcAttackAngle();
+float calcKXdeg(float x);
 
 void air_countUp(){
     air_kaitensu++;
@@ -119,31 +89,45 @@
     air_kaitensu = 0;
 }
 
-//void sonarInterruptStart(){
-//    sonarTimer.start();
-//    led3 = 1;
-//}
-//void sonarInterruptStop(){
+void sonarInterruptStart(){
+    sonarTimer.start();
+}
+
+void sonarInterruptStop(){
 //    sonarTimer.stop();
-//    led3 = 0;
 //    sonarDistTime = sonarTimer.read_us();
 //    sonarTimer.reset();
-//}
+//    sonarDist = sonarDistTime*0.018624 - 13.511;
+}
+void sonarCalc(){
+    sonarV = 0;
+    for(int i = 0; i<20; i++){
+        sonarV += sonarPin.read();
+        wait(0.01);
+    }
+    sonarDist = (sonarV/20)*2064.5;// volt*3.3*1000/1.6 (電圧/距離:3.2mV/2cm)
+}
+
+void updateCadence(){
+        cadence_twe.readData();
+}
 
 void init(){
 //--------------------------------------(resetInterrupt init)
     resetPin.rise(resetInterrupt);
     resetPin.mode(PullDown);
 //-----------------------------------------------------------
-    twe.baud(115200);
-    Android.baud(9600);
-    soudaSerial.baud(9600);
-    kisokuServo.period_ms(INIT_SERVO_PERIOD_MS);
-    geikakuServo.period_ms(INIT_SERVO_PERIOD_MS);
+    twe.baud(19200);//BufferedSoftSerialでは19200が上限。twelite側でもBPS無効化が必要
+    //writeTimer.start();
     FusokukeiInit();
-//    MpuInit(); //mpuProcessing内で
-//    SonarInit();
-//    SdInit();//SDprintf 内で
+    MpuInit(); 
+    //writeDatasTicker.attach(&WriteDatas,1);
+//    cadenceUpdateTicker.attach(&updateCadence, 1);
+    
+//-----for InterruptMode of sonar----------------------------
+//    sonarPin.rise(&sonarInterruptStart);
+//    sonarPin.fall(&sonarInterruptStop);
+//-----------------------------------------------------------
 }
 
 void FusokukeiInit(){
@@ -151,197 +135,134 @@
     FusokukeiTicker.attach(&call_calcAirSpeed, AIR_LOOP_TIME);
 }
 
-double calcPulse(int deg){
-    return (0.0006+(deg/180.0)*(0.00235-0.00045));
-}
-
-void SdInit(){
-    mkdir("/sd/mydir", 0777);
-    fp = fopen("/sd/mydir/sdtest2.csv", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
-    fprintf(fp, "Hello fun SD Card World!\n\r");
-    fclose(fp);
-//    Thread sd_thread(&SDprintf);
-}
 void MpuInit(){
     i2c.frequency(400000);  // use fast (400 kHz) I2C
     t.start();
     uint8_t whoami = mpu6050.readByte(MPU6050_ADDRESS, WHO_AM_I_MPU6050);  // Read WHO_AM_I register for MPU-6050
     if (whoami == 0x68) { // WHO_AM_I should always be 0x68
-        Thread::wait(1);
+        wait(1);
         mpu6050.MPU6050SelfTest(SelfTest); // Start by performing self test and reporting values
-        Thread::wait(1);
+        wait(1);
         if(SelfTest[0] < 1.0f && SelfTest[1] < 1.0f && SelfTest[2] < 1.0f && SelfTest[3] < 1.0f && SelfTest[4] < 1.0f && SelfTest[5] < 1.0f) {
             mpu6050.resetMPU6050(); // Reset registers to default in preparation for device calibration
             mpu6050.calibrateMPU6050(gyroBias, accelBias); // Calibrate gyro and accelerometers, load biases in bias registers
             mpu6050.initMPU6050(); //pc.printf("MPU6050 initialized for active data mode....\n\r"); // Initialize device for active mode read of acclerometer, gyroscope, and temperature
-            Thread::wait(2);
+            wait(2);
         } else {
         }
     } else {
-        pc.printf("MPU6050 not ready...\n\r");
         //pc.printf("out\n\r"); // Loop forever if communication doesn't happen
     }   
 }
 
-//void SonarInit(){
-//    sonarPin.rise(&sonarInterruptStart);
-//    sonarPin.fall(&sonarInterruptStop);
-//}
-void sonarCalc(void const *argument){
-//    return sonarDistTime*0.018624 - 13.511;
-    while(1){
-        sonarV = 0;
-        for(int i =0; i<20; i++){
-            sonarV += sonarPin.read();
-            Thread::wait(0.01);
-        }
-        sonarDist = (sonarV/20)*2062.5;
-        Thread::wait(0.01);
+double calcPulse(int deg){
+    return (0.0006+(deg/180.0)*(0.00235-0.00045));
+
+}
+
+void mpuProcessing(){
+    if(mpu6050.readByte(MPU6050_ADDRESS, INT_STATUS) & 0x01) {  // check if data ready interrupt
+        mpu6050.readAccelData(accelCount);  // Read the x/y/z adc values
+        mpu6050.getAres();
+        ax = (float)accelCount[0]*aRes - accelBias[0];  // get actual g value, this depends on scale being set
+        ay = (float)accelCount[1]*aRes - accelBias[1];
+        az = (float)accelCount[2]*aRes - accelBias[2];
+        mpu6050.readGyroData(gyroCount);  // Read the x/y/z adc values
+        mpu6050.getGres();
+        gx = (float)gyroCount[0]*gRes; // - gyroBias[0];  // get actual gyro value, this depends on scale being set
+        gy = (float)gyroCount[1]*gRes; // - gyroBias[1];
+        gz = (float)gyroCount[2]*gRes; // - gyroBias[2];
+        tempCount = mpu6050.readTempData();  // Read the x/y/z adc values
+        temperature = (tempCount) / 340. + 36.53; // Temperature in degrees Centigrade
+    }
+    Now = t.read_us();
+    deltat = (float)((Now - lastUpdate)/1000000.0f) ; // set integration time by time elapsed since last filter update
+    lastUpdate = Now;
+    sum += deltat;
+    sumCount++;
+    if(lastUpdate - firstUpdate > 10000000.0f) {
+        beta = 0.04;  // decrease filter gain after stabilized
+        zeta = 0.015; // increasey bias drift gain after stabilized
+    }
+    mpu6050.MadgwickQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f);
+    delt_t = t.read_ms() - count;
+    if (delt_t > MPU_DELT_MIN) {
+        yaw   = atan2(2.0f * (q[1] * q[2] + q[0] * q[3]), q[0] * q[0] + q[1] * q[1] - q[2] * q[2] - q[3] * q[3]);
+        pitch = -asin(2.0f * (q[1] * q[3] - q[0] * q[2]));
+        roll  = atan2(2.0f * (q[0] * q[1] + q[2] * q[3]), q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3]);
+        pitch *= 180.0f / PI;
+        yaw   *= 180.0f / PI;
+        roll  *= 180.0f / PI;
+        myled= !myled;
+        count = t.read_ms();
+        sum = 0;
+        sumCount = 0;
     }
 }
 
-void mpuProcessing(void const *argument){
-    MpuInit();
-    while(1){
-        Thread::wait(0.1);
-        if(mpu6050.readByte(MPU6050_ADDRESS, INT_STATUS) & 0x01) {  // check if data ready interrupt
-            mpu6050.readAccelData(accelCount);  // Read the x/y/z adc values
-            mpu6050.getAres();
-            ax = (float)accelCount[0]*aRes - accelBias[0];  // get actual g value, this depends on scale being set
-            ay = (float)accelCount[1]*aRes - accelBias[1];
-            az = (float)accelCount[2]*aRes - accelBias[2];
-            mpu6050.readGyroData(gyroCount);  // Read the x/y/z adc values
-            mpu6050.getGres();
-            gx = (float)gyroCount[0]*gRes; // - gyroBias[0];  // get actual gyro value, this depends on scale being set
-            gy = (float)gyroCount[1]*gRes; // - gyroBias[1];
-            gz = (float)gyroCount[2]*gRes; // - gyroBias[2];
-            tempCount = mpu6050.readTempData();  // Read the x/y/z adc values
-            temperature = (tempCount) / 340. + 36.53; // Temperature in degrees Centigrade
-        }
-        Now = t.read_us();
-        deltat = (float)((Now - lastUpdate)/1000000.0f) ; // set integration time by time elapsed since last filter update
-        lastUpdate = Now;
-        sum += deltat;
-        sumCount++;
-        if(lastUpdate - firstUpdate > 10000000.0f) {
-            beta = 0.04;  // decrease filter gain after stabilized
-            zeta = 0.015; // increasey bias drift gain after stabilized
-        }
-        mpu6050.MadgwickQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f);
-        delt_t = t.read_ms() - count;
-        if (delt_t > MPU_DELT_MIN) {
-            yaw   = atan2(2.0f * (q[1] * q[2] + q[0] * q[3]), q[0] * q[0] + q[1] * q[1] - q[2] * q[2] - q[3] * q[3]);
-            pitch = -asin(2.0f * (q[1] * q[3] - q[0] * q[2]));
-            roll  = atan2(2.0f * (q[0] * q[1] + q[2] * q[3]), q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3]);
-            pitch *= 180.0f / PI;
-            yaw   *= 180.0f / PI;
-            roll  *= 180.0f / PI;
-            myled= !myled;
-            count = t.read_ms();
-            sum = 0;
-            sumCount = 0;
-        }
+void DataReceiveFromSouda(){
+    led2 = !led2;
+    char c = soudaSerial.getc();
+    while( c != ';' ){
+        c = soudaSerial.getc();
     }
-}
-
-void DataReceiveFromSouda(void const *argument){
-    while(1){
-        led2 = !led2;
-        for(int i = 0; i < SOUDA_DATAS_NUM; i++){
-            if(soudaSerial.readable()) {
-//                ssMutex.lock();
-                soudaDatas[i] = (char)soudaSerial.getc();
-//                ssMutex.unlock();
-                if(soudaDatas[i]==';') i=-1;
-            }else i--;
-        }
-    }
-}
-
-void SDprintf(void const *argument){
-    SdInit();
-    while(1){
-        if(write_datas_index == SD_WRITE_NUM-1){
-//            led4 = !led4;
-            fp = fopen("/sd/mydir/sdtest.csv", "a");
-            if(fp == NULL) {
-                error("Could not open file for write\n");
-            }
-            for(int i = 0; i < SD_WRITE_NUM; i++){
-                for(int j = 0; j < WRITE_DATAS_NUM; j++){
-                    fprintf(fp,"%f,", writeDatas[i][j]);
-                }
-            }
-            fprintf(fp,"\n\r");
-            fclose(fp);
-            write_datas_index=0;
-        }
-        Thread::wait(0.01);
+    for(int i = 0; i < SOUDA_DATAS_NUM; i++){
+        soudaDatas[i] = soudaSerial.getc();
     }
 }
 
 void WriteDatas(){
     int i;
-    for(i = 0; i < 6; i++){ //翼端のmpu
-        if(!(i%2)){
-            writeDatas[write_datas_index][i] = (int)( (soudaDatas[i*2]<<8) + soudaDatas[(i+1)*2] );
-        }else{
-            writeDatas[write_datas_index][i] = (int)( (soudaDatas[i*2-1]<<8) + soudaDatas[i*2+1] );
-        }
-//        writeDatas[write_datas_index][i] = i;
+    for(i = 0; i < SOUDA_DATAS_NUM; i++){
+        //writeDatas[write_datas_index][i] = 0.0;    
+        writeDatas[write_datas_index][i] = (float)soudaDatas[i];
     }
-    for(i = 6; i < 12; i++){//翼端のV,操舵
-        //writeDatas[write_datas_index][i] = 0.0;    
-        writeDatas[write_datas_index][i] = (float)soudaDatas[i+6];
-    }
-    writeDatas[write_datas_index][i++] = cadence.cadence;
-    writeDatas[write_datas_index][i++] = sonarDist;
     writeDatas[write_datas_index][i++] = pitch;
     writeDatas[write_datas_index][i++] = roll;
     writeDatas[write_datas_index][i++] = yaw;
     writeDatas[write_datas_index][i++] = airSpeed;
+    writeDatas[write_datas_index][i++] = sonarDist;
+    writeDatas[write_datas_index][i++] = cadence;
     //writeDatas[write_datas_index][i++] = writeTimer.read();
-    for(i = 0; i < WRITE_DATAS_NUM; i++){
-        pc.printf("%f   ", writeDatas[write_datas_index][i]);
+    //for(i = 0; i < WRITE_DATAS_NUM; i++){
+//        pc.printf("%f   ", writeDatas[write_datas_index][i]);
 //        twe.printf("%f,", writeDatas[write_datas_index][i]);
-    }
-    pc.printf("\n\r");
+//    }
+//    pc.printf("\n\r");
 //    twe.printf("\n\r");
-    if(write_datas_index < SD_WRITE_NUM-1){
-        write_datas_index++;
-    } 
+//    if(write_datas_index == SD_WRITE_NUM-1){
+//        write_datas_index=0;
+//    }
+//    else{
+//        write_datas_index++;
+//    } 
     for(int i = 0; i < SOUDA_DATAS_NUM; i++){
-//        pc.printf("%i   ",soudaDatas[i]);
-        ssMutex.lock();
+        pc.printf("%i   ",soudaDatas[i]);
         twe.printf("%i,",soudaDatas[i]);
-        ssMutex.unlock();
+//        android.printf("%i,",soudaDatas[i]);
     }
-//    twe.printf("%f\n\r",cadence.cadence);
-//    pc.printf("%f\n\r",cadence.cadence);
     //pc.printf("\n\r");
-
-if(Android.writeable()){
-    Android.printf("%f,%f,%f",airSpeed,roll,0);
-}
-    ssMutex.lock();
     twe.printf("%f,%f,%f,",pitch,roll,yaw);
-//    twe.printf("%f,%f,%f,",calcKXdeg(kx_X.read()),calcKXdeg(KX_Y),calcKXdeg(KX_Z));   
-    twe.printf("%f,\r\n",airSpeed); 
-    ssMutex.unlock();
-//    pc.printf("%f,%f,%f\n\r",pitch,roll,yaw);
+    twe.printf("%f,%f,%f\r\n",airSpeed,sonarDist,cadence); 
+    pc.printf("%f,%f,%f\n\r",pitch,roll,yaw);
     //pc.printf("%f,%f,%f\n\r",calcKXdeg(kx_X.read()),calcKXdeg(KX_Y),calcKXdeg(KX_Z));   
-//    pc.printf("%f\n\r",airSpeed);
+    pc.printf("%f,%f,%f\n\r",airSpeed,sonarDist,cadence);
+    pc.putc(cadence_twe.strV[0]);
+    if(android.writeable()){
+//        for(int i = 0; i<SOUDA_DATAS_NUM; i++){
+//            android.printf("%i,",soudaDatas[i]);
+//        }
+//        android.printf("%f,%f,%f,",pitch,roll,yaw);
+//        android.printf("%f,%f,\r\n",airSpeed,sonarDist); 
+        android.printf("%f,%f,test\n\r",roll,airSpeed);
+    }
     //SDprintf();
-    pc.printf("%d\n\r",write_datas_index);
 }
 
 void WriteDatasF(){
     pc.printf("airSpeed:%f\n\r",airSpeed);
 }
-//
+
 //float calcKXdeg(float x){
 //    return -310.54*x+156.65;
 //}
@@ -357,6 +278,7 @@
     else{
         RollAlarmL = 0;
     }
+    
     if((roll > 0) && (roll < 180-ROLL_R_MAX_DEG)){
         RollAlarmR = 1;
     }
@@ -365,21 +287,32 @@
     }
 }
 
-
+void WriteServo(){
+    //kisokuServo.pulsewidth(calcPulse(airSpeed*10));
+//    kisokuServo.pulsewidth(calcPulse(9*airSpeed));
+    if(pitch<0){
+//        geikakuServo.pulsewidth(calcPulse(0));
+    }
+    else{
+//        geikakuServo.pulsewidth(calcPulse(abs(pitch*90/13.0)));
+    }
+    //pc.printf("a:%f",airSpeed);
+    //pc.printf("p:%f\r\n",pitch);
+    //kisokuServo.pulsewidth(calcPulse(0));
+    //geikakuServo.pulsewidth(calcPulse(0));
+}
 
 int main(){
-    Thread sd_thread(&SDprintf);//必ずmain内で
-    Thread sonar_thread(&sonarCalc);
-    Thread mpu_thread(&mpuProcessing);
-    Thread soudaSerial_thread(&DataReceiveFromSouda);
-    Thread cadence_thread(&cadenceDataReceive);
+//    Thread cadence_thread(&updateCadence);
     init();
     while(1){
         pc.printf("test\n\r");
-//        mpuProcessing();
+        mpuProcessing();
+        sonarCalc();
         RollAlarm();
-//        DataReceiveFromSouda();
-//        cadence.readData();
+        DataReceiveFromSouda();
+        updateCadence();
         WriteDatas();
+//        WriteServo();
     }
 }
\ No newline at end of file
--- a/mbed-rtos.lib	Wed Jan 25 12:24:10 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- a/mbed.bld	Wed Jan 25 12:24:10 2017 +0000
+++ b/mbed.bld	Sat Jan 28 10:17:50 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/252557024ec3
\ No newline at end of file