testprogram

Dependencies:   SDFileSystem mbed

Committer:
hissa214
Date:
Thu Feb 23 11:24:58 2017 +0000
Revision:
0:4e3377fa0a25
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hissa214 0:4e3377fa0a25 1 #include "mbed.h"
hissa214 0:4e3377fa0a25 2 #include "SDFileSystem.h"
hissa214 0:4e3377fa0a25 3
hissa214 0:4e3377fa0a25 4 Serial pc(USBTX,USBRX);//シリアル通信
hissa214 0:4e3377fa0a25 5 SDFileSystem sd(p5,p6,p7,p8,"sd");//SDスロットピン
hissa214 0:4e3377fa0a25 6 PwmOut servo(p24);//パラシュート分離用サーボ
hissa214 0:4e3377fa0a25 7 //PwmOut servo(p21);//パラシュート分離用サーボブレボ
hissa214 0:4e3377fa0a25 8 AnalogIn accel_x(p20);//加速度X軸
hissa214 0:4e3377fa0a25 9 AnalogIn accel_y(p19);//加速度Y軸
hissa214 0:4e3377fa0a25 10 AnalogIn accel_z(p18);//加速度Z軸
hissa214 0:4e3377fa0a25 11 DigitalIn cds(p29);//光センサ
hissa214 0:4e3377fa0a25 12 PwmOut moterL(p21);
hissa214 0:4e3377fa0a25 13 PwmOut moterR(p22);
hissa214 0:4e3377fa0a25 14 DigitalOut stby (p11);//モータドライバ
hissa214 0:4e3377fa0a25 15 DigitalOut AIN(p12);//モータドライバ正転逆転
hissa214 0:4e3377fa0a25 16 DigitalOut led1(LED1);
hissa214 0:4e3377fa0a25 17 float x,y,z;
hissa214 0:4e3377fa0a25 18
hissa214 0:4e3377fa0a25 19 int main()
hissa214 0:4e3377fa0a25 20
hissa214 0:4e3377fa0a25 21 {
hissa214 0:4e3377fa0a25 22 stby=1;
hissa214 0:4e3377fa0a25 23 AIN=1;
hissa214 0:4e3377fa0a25 24 float pwidth;
hissa214 0:4e3377fa0a25 25 servo.period_ms(20);//出力周期 20ms=(50Hz)
hissa214 0:4e3377fa0a25 26
hissa214 0:4e3377fa0a25 27 while(1) {
hissa214 0:4e3377fa0a25 28 x = accel_x;//xyzの値をそれぞれ格納
hissa214 0:4e3377fa0a25 29 y = accel_y;
hissa214 0:4e3377fa0a25 30 z = accel_z;
hissa214 0:4e3377fa0a25 31
hissa214 0:4e3377fa0a25 32 pc.printf("X:%1.3f Y:%1.3f Z:%1.3f \r\n", accel_x.read() ,accel_y.read() ,accel_z.read() );
hissa214 0:4e3377fa0a25 33 pwidth=0.001;
hissa214 0:4e3377fa0a25 34 servo.pulsewidth(pwidth);
hissa214 0:4e3377fa0a25 35 if(cds==1){
hissa214 0:4e3377fa0a25 36 led1=1;
hissa214 0:4e3377fa0a25 37 }
hissa214 0:4e3377fa0a25 38 if(x>=0.8 || y>=0.8 || z>=0.8){//*************調整必要
hissa214 0:4e3377fa0a25 39 pwidth=0.00075;
hissa214 0:4e3377fa0a25 40 servo.pulsewidth(pwidth);
hissa214 0:4e3377fa0a25 41 wait(10.0);
hissa214 0:4e3377fa0a25 42 moterL.pulsewidth(0.0020); //パルス幅指定
hissa214 0:4e3377fa0a25 43 moterR.pulsewidth(0.0020);
hissa214 0:4e3377fa0a25 44
hissa214 0:4e3377fa0a25 45 //return(0);
hissa214 0:4e3377fa0a25 46 }
hissa214 0:4e3377fa0a25 47 //return(0);
hissa214 0:4e3377fa0a25 48
hissa214 0:4e3377fa0a25 49 if(x<0.8 || y<0.8 || z<0.8){
hissa214 0:4e3377fa0a25 50 FILE *fp = fopen ("/sd/AccLog.txt","a"); //GPSデータをSDに書き込み
hissa214 0:4e3377fa0a25 51 if(fp == NULL) {
hissa214 0:4e3377fa0a25 52 error("Could not open file for write\n");
hissa214 0:4e3377fa0a25 53 }
hissa214 0:4e3377fa0a25 54 fprintf(fp,"x:%.3f ",x);
hissa214 0:4e3377fa0a25 55 fprintf(fp,"y:%.3f ",y);
hissa214 0:4e3377fa0a25 56 fprintf(fp,"z:%.3f\r\n",z);
hissa214 0:4e3377fa0a25 57 fclose(fp);
hissa214 0:4e3377fa0a25 58 }
hissa214 0:4e3377fa0a25 59
hissa214 0:4e3377fa0a25 60
hissa214 0:4e3377fa0a25 61
hissa214 0:4e3377fa0a25 62 }
hissa214 0:4e3377fa0a25 63 }