2017年3月,伊豆大島共同打上実験 CORE_缶ロケチーム電装

Dependencies:   MPU6050 MS5607 mbed SDFileSystem

main.cpp

Committer:
mikawataru
Date:
2017-02-18
Revision:
2:b6eb08d059cc
Parent:
1:ec75f428c6b3
Child:
3:9cd74af355cc

File content as of revision 2:b6eb08d059cc:

#include "mbed.h"
#include "MS5607I2C.h"
#include "MPU6050.h"
#include "SDFileSystem.h"

#define RATE 10

MS5607I2C ms5607(p9, p10, false);
MPU6050 mpu(p9,p10);
DigitalIn sw(p21);
DigitalOut myled(LED1);
Serial pc(USBTX, USBRX);
SDFileSystem sd(p11, p12, p13, p14, "sd");

Timer timer;
Ticker loop_measure;

int8_t cnt = 0;
bool mode = 0;
float pressure[2][RATE],temperature[2][RATE];
float acc[2][RATE][3],gyro[2][RATE][3];
float t[2][RATE],alt,alt_max,alt_launch;
FILE *fp;

void _Launch(){
   alt_launch = alt;
   myled = 1;

}
void _measure(){
   t[mode][cnt] = timer.read();
   pressure[mode][cnt] = ms5607.getPressure();
   temperature[mode][cnt] = ms5607.getTemperature();
   mpu.getAccelero(&acc[mode][cnt][0]);
   mpu.getGyro(&gyro[mode][cnt][0]);
   alt = ms5607.getAltitude();
   fprintf(fp, "%f,%f,%f,%f,%f,%f,%f,%f,%f\r\n",
               t[mode][cnt],pressure[mode][cnt],temperature[mode][cnt],acc[mode][cnt][0],
               acc[mode][cnt][1],acc[mode][cnt][2],gyro[mode][cnt][0],gyro[mode][cnt][1],gyro[mode][cnt][2]
            );
   cnt++;
   if(cnt==RATE){
      fclose(fp);
      fp = fopen("/sd/log.txt", "a");
      mode =! mode;
      cnt = 0;
    }
}

int main() {
   timer.start();
   fp = fopen("/sd/log.txt", "w");
   fprintf(fp, "pressure,temperature,ax,ay,az,gx,gy,gz\r\n");
   myled = 0;
   loop_measure.attach(&_measure,1.0/RATE);
   while(1){
        if(sw==0)_Launch();
   }
}