![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
2017年3月,伊豆大島共同打上実験 CORE_缶ロケチーム電装
Dependencies: MPU6050 MS5607 mbed SDFileSystem
main.cpp@2:b6eb08d059cc, 2017-02-18 (annotated)
- Committer:
- mikawataru
- Date:
- Sat Feb 18 17:32:44 2017 +0000
- Revision:
- 2:b6eb08d059cc
- Parent:
- 1:ec75f428c6b3
- Child:
- 3:9cd74af355cc
???????????10Hz???
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mikawataru | 0:10a9c9c5ce83 | 1 | #include "mbed.h" |
mikawataru | 0:10a9c9c5ce83 | 2 | #include "MS5607I2C.h" |
mikawataru | 0:10a9c9c5ce83 | 3 | #include "MPU6050.h" |
mikawataru | 1:ec75f428c6b3 | 4 | #include "SDFileSystem.h" |
mikawataru | 0:10a9c9c5ce83 | 5 | |
mikawataru | 2:b6eb08d059cc | 6 | #define RATE 10 |
mikawataru | 0:10a9c9c5ce83 | 7 | |
mikawataru | 0:10a9c9c5ce83 | 8 | MS5607I2C ms5607(p9, p10, false); |
mikawataru | 0:10a9c9c5ce83 | 9 | MPU6050 mpu(p9,p10); |
mikawataru | 0:10a9c9c5ce83 | 10 | DigitalIn sw(p21); |
mikawataru | 0:10a9c9c5ce83 | 11 | DigitalOut myled(LED1); |
mikawataru | 0:10a9c9c5ce83 | 12 | Serial pc(USBTX, USBRX); |
mikawataru | 1:ec75f428c6b3 | 13 | SDFileSystem sd(p11, p12, p13, p14, "sd"); |
mikawataru | 0:10a9c9c5ce83 | 14 | |
mikawataru | 1:ec75f428c6b3 | 15 | Timer timer; |
mikawataru | 0:10a9c9c5ce83 | 16 | Ticker loop_measure; |
mikawataru | 0:10a9c9c5ce83 | 17 | |
mikawataru | 0:10a9c9c5ce83 | 18 | int8_t cnt = 0; |
mikawataru | 1:ec75f428c6b3 | 19 | bool mode = 0; |
mikawataru | 1:ec75f428c6b3 | 20 | float pressure[2][RATE],temperature[2][RATE]; |
mikawataru | 1:ec75f428c6b3 | 21 | float acc[2][RATE][3],gyro[2][RATE][3]; |
mikawataru | 2:b6eb08d059cc | 22 | float t[2][RATE],alt,alt_max,alt_launch; |
mikawataru | 1:ec75f428c6b3 | 23 | FILE *fp; |
mikawataru | 1:ec75f428c6b3 | 24 | |
mikawataru | 0:10a9c9c5ce83 | 25 | void _Launch(){ |
mikawataru | 2:b6eb08d059cc | 26 | alt_launch = alt; |
mikawataru | 0:10a9c9c5ce83 | 27 | myled = 1; |
mikawataru | 2:b6eb08d059cc | 28 | |
mikawataru | 0:10a9c9c5ce83 | 29 | } |
mikawataru | 0:10a9c9c5ce83 | 30 | void _measure(){ |
mikawataru | 1:ec75f428c6b3 | 31 | t[mode][cnt] = timer.read(); |
mikawataru | 1:ec75f428c6b3 | 32 | pressure[mode][cnt] = ms5607.getPressure(); |
mikawataru | 1:ec75f428c6b3 | 33 | temperature[mode][cnt] = ms5607.getTemperature(); |
mikawataru | 1:ec75f428c6b3 | 34 | mpu.getAccelero(&acc[mode][cnt][0]); |
mikawataru | 1:ec75f428c6b3 | 35 | mpu.getGyro(&gyro[mode][cnt][0]); |
mikawataru | 2:b6eb08d059cc | 36 | alt = ms5607.getAltitude(); |
mikawataru | 1:ec75f428c6b3 | 37 | fprintf(fp, "%f,%f,%f,%f,%f,%f,%f,%f,%f\r\n", |
mikawataru | 1:ec75f428c6b3 | 38 | t[mode][cnt],pressure[mode][cnt],temperature[mode][cnt],acc[mode][cnt][0], |
mikawataru | 1:ec75f428c6b3 | 39 | acc[mode][cnt][1],acc[mode][cnt][2],gyro[mode][cnt][0],gyro[mode][cnt][1],gyro[mode][cnt][2] |
mikawataru | 1:ec75f428c6b3 | 40 | ); |
mikawataru | 0:10a9c9c5ce83 | 41 | cnt++; |
mikawataru | 1:ec75f428c6b3 | 42 | if(cnt==RATE){ |
mikawataru | 1:ec75f428c6b3 | 43 | fclose(fp); |
mikawataru | 2:b6eb08d059cc | 44 | fp = fopen("/sd/log.txt", "a"); |
mikawataru | 1:ec75f428c6b3 | 45 | mode =! mode; |
mikawataru | 1:ec75f428c6b3 | 46 | cnt = 0; |
mikawataru | 1:ec75f428c6b3 | 47 | } |
mikawataru | 0:10a9c9c5ce83 | 48 | } |
mikawataru | 0:10a9c9c5ce83 | 49 | |
mikawataru | 0:10a9c9c5ce83 | 50 | int main() { |
mikawataru | 1:ec75f428c6b3 | 51 | timer.start(); |
mikawataru | 2:b6eb08d059cc | 52 | fp = fopen("/sd/log.txt", "w"); |
mikawataru | 1:ec75f428c6b3 | 53 | fprintf(fp, "pressure,temperature,ax,ay,az,gx,gy,gz\r\n"); |
mikawataru | 0:10a9c9c5ce83 | 54 | myled = 0; |
mikawataru | 1:ec75f428c6b3 | 55 | loop_measure.attach(&_measure,1.0/RATE); |
mikawataru | 0:10a9c9c5ce83 | 56 | while(1){ |
mikawataru | 1:ec75f428c6b3 | 57 | if(sw==0)_Launch(); |
mikawataru | 0:10a9c9c5ce83 | 58 | } |
mikawataru | 0:10a9c9c5ce83 | 59 | } |