kk

Dependencies:   SDFileSystem mbed

Fork of cansat_kk by monoCanSat

Committer:
mosukro
Date:
Mon Feb 29 18:07:55 2016 +0000
Revision:
2:be9046fb5859
Parent:
1:fa44a6246bcc
Child:
3:efaa785283a6
160301

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nike3221 0:649fc30be6ec 1 #include "mbed.h"
Nike3221 0:649fc30be6ec 2 #include "SDFileSystem.h"
Nike3221 0:649fc30be6ec 3
Nike3221 0:649fc30be6ec 4 Ticker timer;
Nike3221 0:649fc30be6ec 5 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
mosukro 1:fa44a6246bcc 6 Serial gps(p28, p27); // tx, rx
Nike3221 0:649fc30be6ec 7 Serial pc(USBTX, USBRX); // tx, rx
Nike3221 0:649fc30be6ec 8 PwmOut moterl(p21);//左モーター
Nike3221 0:649fc30be6ec 9 PwmOut moterr(p22);//右モーター
Nike3221 0:649fc30be6ec 10 DigitalOut led1(LED1);
Nike3221 0:649fc30be6ec 11 DigitalOut fet3(p23);//ニクロム線
Nike3221 0:649fc30be6ec 12 DigitalOut led2(LED2);
Nike3221 0:649fc30be6ec 13 DigitalOut led3(LED3);
Nike3221 0:649fc30be6ec 14 DigitalOut led4(LED4);
Nike3221 0:649fc30be6ec 15 DigitalOut janpa1(p19);//パラシュートの開きを検知
Nike3221 0:649fc30be6ec 16 DigitalIn janpa2(p20);//パラシュートの開きを検知
Nike3221 0:649fc30be6ec 17
mosukro 1:fa44a6246bcc 18 char gps_data[256];
mosukro 1:fa44a6246bcc 19 float longitude,latitude,gpstime,knot,angle;
Nike3221 0:649fc30be6ec 20 int i=0;
mosukro 2:be9046fb5859 21 char *gps_target = "$GPRMC,174813.000,A,3606.9349,N,13927.4196,E,0.42,221.65,280216,,,A*6D";
mosukro 2:be9046fb5859 22 float longitude_target,latitude_target,gpstime_target,knot_target,angle_target;
Nike3221 0:649fc30be6ec 23
mosukro 1:fa44a6246bcc 24 void gps_rx()//GPSデータ受信割り込み
Nike3221 0:649fc30be6ec 25 {
mosukro 1:fa44a6246bcc 26 gps_data[i] = gps.getc();
mosukro 1:fa44a6246bcc 27 if( gps_data[i] == '$' )
mosukro 2:be9046fb5859 28 {
mosukro 1:fa44a6246bcc 29 //$から受信データを保持する
mosukro 1:fa44a6246bcc 30 gps_data[0] = '$';
mosukro 1:fa44a6246bcc 31 i = 1;
mosukro 1:fa44a6246bcc 32 }
mosukro 1:fa44a6246bcc 33 else if( gps_data[i-1] == '\r' && gps_data[i] == '\n' )
mosukro 1:fa44a6246bcc 34 {
mosukro 1:fa44a6246bcc 35 // 改行コードまでのデータを解析する
mosukro 1:fa44a6246bcc 36 gps_data[i+1] = '\0';
mosukro 1:fa44a6246bcc 37 if(memcmp(gps_data, "$GPRMC",6) == 0)
mosukro 1:fa44a6246bcc 38 {
mosukro 1:fa44a6246bcc 39 // $GPRMCで始ってればデータを分けて格納
mosukro 1:fa44a6246bcc 40 sscanf(gps_data,"$GPRMC,%f,A,%f,N,%f,E,%f,%f",&gpstime,&longitude,&latitude,&knot,&angle);
mosukro 1:fa44a6246bcc 41 }
mosukro 1:fa44a6246bcc 42 //データをSDに書き込み
mosukro 1:fa44a6246bcc 43 mkdir("/sd/mydir", 0777);
mosukro 1:fa44a6246bcc 44 FILE *fp = fopen("/sd/mydir/gpsdata.txt", "a");
mosukro 1:fa44a6246bcc 45 if(fp == NULL)
mosukro 1:fa44a6246bcc 46 {
mosukro 1:fa44a6246bcc 47 error("Could not open file for write\n");
mosukro 1:fa44a6246bcc 48 }
mosukro 1:fa44a6246bcc 49 fprintf(fp,"%s \n",gps_data);
mosukro 1:fa44a6246bcc 50 fclose(fp);
Nike3221 0:649fc30be6ec 51
mosukro 1:fa44a6246bcc 52 //PCにデータ送信
mosukro 1:fa44a6246bcc 53 pc.printf("%s \n",gps_data);
mosukro 1:fa44a6246bcc 54 i = 0;
mosukro 1:fa44a6246bcc 55 }
mosukro 1:fa44a6246bcc 56 else
mosukro 1:fa44a6246bcc 57 {
mosukro 1:fa44a6246bcc 58 //改行コードが来るまでカウントを続ける
mosukro 1:fa44a6246bcc 59 i++;
mosukro 2:be9046fb5859 60 if(i==255)
mosukro 2:be9046fb5859 61 {
mosukro 1:fa44a6246bcc 62 pc.printf("*** Error! ***\n");
mosukro 1:fa44a6246bcc 63 }
mosukro 1:fa44a6246bcc 64 }
Nike3221 0:649fc30be6ec 65
Nike3221 0:649fc30be6ec 66 }
Nike3221 0:649fc30be6ec 67
mosukro 1:fa44a6246bcc 68 void move()
Nike3221 0:649fc30be6ec 69 {
mosukro 1:fa44a6246bcc 70 //動作
mosukro 2:be9046fb5859 71 switch (count)
mosukro 2:be9046fb5859 72 {
mosukro 2:be9046fb5859 73 case 0:
mosukro 2:be9046fb5859 74 if( (target_angle+3)>=angle || (target_angle-3)<=angle )
mosukro 2:be9046fb5859 75 {
mosukro 2:be9046fb5859 76 //
mosukro 2:be9046fb5859 77
mosukro 2:be9046fb5859 78 }
mosukro 2:be9046fb5859 79 break;
mosukro 2:be9046fb5859 80 case 1:
mosukro 2:be9046fb5859 81 文2;
mosukro 2:be9046fb5859 82 break;
mosukro 2:be9046fb5859 83 case 2:
mosukro 2:be9046fb5859 84 文n;
mosukro 2:be9046fb5859 85 break;
mosukro 2:be9046fb5859 86 default:
mosukro 2:be9046fb5859 87 文;
mosukro 2:be9046fb5859 88 break;
mosukro 2:be9046fb5859 89 }
Nike3221 0:649fc30be6ec 90 }
mosukro 1:fa44a6246bcc 91
mosukro 1:fa44a6246bcc 92 int main()
mosukro 1:fa44a6246bcc 93 {
mosukro 1:fa44a6246bcc 94 gps.baud(9600);
mosukro 1:fa44a6246bcc 95 gps.attach(gps_rx, Serial::RxIrq);//GPS割り込み
mosukro 2:be9046fb5859 96 sscanf(gps_target,"$GPRMC,%f,A,%f,N,%f,E,%f,%f",&gpstime_target,&longitude_target,&latitude_target,&knot_target,&angle_target);
mosukro 1:fa44a6246bcc 97
Nike3221 0:649fc30be6ec 98 while(1)
Nike3221 0:649fc30be6ec 99 {
mosukro 1:fa44a6246bcc 100 move();
Nike3221 0:649fc30be6ec 101 }
mosukro 1:fa44a6246bcc 102
Nike3221 0:649fc30be6ec 103 }