cansat
Dependencies: SDFileSystem mbed
Diff: main.cpp
- Revision:
- 1:a2629e589080
- Parent:
- 0:649fc30be6ec
- Child:
- 2:db3e3ca8d1eb
--- a/main.cpp Mon Feb 29 11:10:31 2016 +0000 +++ b/main.cpp Mon Feb 29 14:31:01 2016 +0000 @@ -5,95 +5,104 @@ SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board Serial gp(p28, p27); // tx, rx Serial pc(USBTX, USBRX); // tx, rx -PwmOut moterl(p21);//左モーター -PwmOut moterr(p22);//右モーター -DigitalOut led1(LED1); +PwmOut moter_l(p21);//左モーター +PwmOut moter_r(p22);//右モーター DigitalOut fet3(p23);//ニクロム線 -DigitalOut led2(LED2); -DigitalOut led3(LED3); -DigitalOut led4(LED4); DigitalOut janpa1(p19);//パラシュートの開きを検知 DigitalIn janpa2(p20);//パラシュートの開きを検知 -int gosa; - -char gpsc[100]; +int ido_gosa,kei_gosa; +int ido_goal=1000; //緯度の目標値 秒以下を入力 要設定 +int kei_goal=1000; //経度の目標値 秒以下を入力 要設定 +int old_ido,old_kei; +int ido,kei; +char gpsc[500]; int a,b,c,d; int i=0; -void gps() +void gps_kakiko() { - led1 = 1; - - printf("Hello World!\n"); - + mkdir("/sd/mydir", 0777); FILE *fp = fopen("/sd/mydir/sdtest.txt", "a"); if(fp == NULL) { error("Could not open file for write\n"); } - - led1 = 0; - led2 = 1; + while(i!=50) - { fputc(gp.getc(),fp); + { fputc(gp.getc(),fp);//sdに50文字づつ書き込み i++; } - fputc(a,fp); fclose(fp); - - led1 = 0; + } - -void start() -{ - janpa1=1; - while(janpa2 == 1) - { led4 = 0; - led3 = 1;}//2 - -} - - - void nikuromu() { - led4=1; - fet3=1;//3 + fet3=1; wait(60);//焼き切り時間 - led4=0; - led3=0; - led2=1;//4 } void moter() { - while(1) + + while(ido_gosa <= 10 && ido_gosa <= 10) { - float offset=0.0; - float offset2=0.0; - moterl.period(0.02); // 周期 - moterr.period(0.02); - moterl.pulsewidth(0.08); // servo position determined by a pulsewidth between 1-2ms - moterr.pulsewidth(0.08); //パルス幅 + + a=50; + {gpsc[a]= gp.getc(); + pc.printf("%c",gpsc[a]);//確認用 要削除 + + if(gpsc[a-34]=='A') + {if(gpsc[a-33]=='G') + {if(gpsc[a-32]=='G') + { + old_ido=ido; + old_kei=kei; + ido=gpsc[a-16]*1000+gpsc[a-15]*100+gpsc[a-14]*10+gpsc[a-13]; + kei=gpsc[a-3]*1000+gpsc[a-2]*100+gpsc[a-1]*10+gpsc[a]; + pc.printf("***%d***%d***",ido,kei);// 要削除 + + if(a>=50) + {a=25;} + }}} + moter_l.period(0.02); // 周期 + moter_r.period(0.02); + moter_l.pulsewidth(0.08); // servo position determined by a pulsewidth between 1-2ms + moter_r.pulsewidth(0.08); //パルス幅 + + while(kei_gosa <=10 || ido_gosa <=10)//先ず経度or緯度をあわせる + { moter_l.pulsewidth(0.10); + moter_r.pulsewidth(0.08); + wait(5); //方向転換90° 要設定 + moter_l.pulsewidth(0.08); + moter_r.pulsewidth(0.08); + wait(10); //gpsの変化待ち + + if(kei_gosa >=10 || ido_gosa >=10) + continue; // 方向転換をやりなおす + } + + while(kei_gosa <=10 || ido_gosa <=10) + { moter_l.pulsewidth(0.08); + moter_r.pulsewidth(0.08); + if(kei_gosa >=10 || ido_gosa >=10) + continue; // 進み続ける + } + moter_l.pulsewidth(0.0); + moter_r.pulsewidth(0.0); } - led2=led3=led4=1; - wait(1.0); - led2=led3=led4=0; - wait(1.0); - led2=led3=led4=1; -} +}} int main() { + janpa1=1; + if(janpa2==0){ gp.baud(9600); - timer.attach(&gps, 2.0);//割り込み - led4 = 1; - start(); - wait(60);//落下中 + timer.attach(&gps_kakiko, 2.0);//割り込み + wait(60);//落下中 要設定 nikuromu(); moter(); - + } return 0; }