Xbeeを実装、speakをfunctionに、rotate消した、calibrationで回るように、ゴール判定を消した

Dependencies:   ATP3012 mbed a HMC US015_2 getGPS

Committer:
miyajitakenari
Date:
Sat Dec 11 01:13:30 2021 +0000
Revision:
13:65ae2ea75c44
Parent:
12:740d999b1fea
Child:
14:a68617dbb76a
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
miyajitakenari 2:9bbc22250488 1 /*ライブラリ*/
miyajitakenari 0:79033ee3c961 2 #include "mbed.h"
miyajitakenari 0:79033ee3c961 3
miyajitakenari 0:79033ee3c961 4 // 自作関数
miyajitakenari 0:79033ee3c961 5 #include "Function.h"
miyajitakenari 0:79033ee3c961 6
miyajitakenari 0:79033ee3c961 7 // フライトピン・ニクロム線関係
miyajitakenari 0:79033ee3c961 8 DigitalIn flight_pin(A0);
miyajitakenari 0:79033ee3c961 9 DigitalOut nichrome(D13);
miyajitakenari 0:79033ee3c961 10 //
miyajitakenari 10:e25e06011fd2 11 #define cp_max 2 //CPの数を入力する
miyajitakenari 0:79033ee3c961 12
miyajitakenari 0:79033ee3c961 13 int main() {
miyajitakenari 0:79033ee3c961 14 // 変数宣言
miyajitakenari 0:79033ee3c961 15 double GPS_x, GPS_y; // 現在地の座標
miyajitakenari 0:79033ee3c961 16 double direction; // 次CPへの向き
miyajitakenari 10:e25e06011fd2 17 double CPs_x[2]={34.545588426585454, 34.5454484832847}; //CPリスト(x座標)
miyajitakenari 10:e25e06011fd2 18 double CPs_y[2]={135.50282053551706, 135.50262437335775}; // CPリスト(y座標)
miyajitakenari 0:79033ee3c961 19 double next_CP_x, next_CP_y;
miyajitakenari 0:79033ee3c961 20
miyajitakenari 0:79033ee3c961 21 // 落下検知
miyajitakenari 0:79033ee3c961 22 // パラシュート分離
miyajitakenari 0:79033ee3c961 23
miyajitakenari 10:e25e06011fd2 24 wait(3);//電源ついてから3v3が安定するまで、秒数は適当、必要かもわからん
miyajitakenari 3:ec2b7587be78 25 while(flight_pin){}
miyajitakenari 13:65ae2ea75c44 26 xbee.printf("flight_pin nuketa\n");
miyajitakenari 0:79033ee3c961 27 wait(35);//ピン抜けてから地面につくまで70m/2.8(m/s)=25(s)余裕を見て+10s
miyajitakenari 10:e25e06011fd2 28 //nichrome=1;
miyajitakenari 13:65ae2ea75c44 29 xbee.printf("nichrome in\n");
miyajitakenari 9:c96ceecb43e1 30 wait(10);
miyajitakenari 10:e25e06011fd2 31 nichrome=0;
miyajitakenari 0:79033ee3c961 32 // 落下終了
miyajitakenari 0:79033ee3c961 33
miyajitakenari 0:79033ee3c961 34
miyajitakenari 0:79033ee3c961 35 // 行動フロー開始
miyajitakenari 0:79033ee3c961 36 Calibration();
miyajitakenari 0:79033ee3c961 37 xbee.printf("XBee Connected\r\n");
miyajitakenari 0:79033ee3c961 38 xbee.printf("Fall point(lati,long)=(%lf , %lf)\r\n", gps.latitude, gps.longitude);
miyajitakenari 0:79033ee3c961 39 for (int i = 0; i<=cp_max-1 ; i++) {//最後のcp=goalまで移動
miyajitakenari 0:79033ee3c961 40 next_CP_x = CPs_x[i];
miyajitakenari 0:79033ee3c961 41 next_CP_y = CPs_y[i];
miyajitakenari 0:79033ee3c961 42
miyajitakenari 0:79033ee3c961 43 xbee.printf("next_i=%d\r\n", i);
miyajitakenari 0:79033ee3c961 44
miyajitakenari 0:79033ee3c961 45 while (1) {
miyajitakenari 10:e25e06011fd2 46 speak();
miyajitakenari 6:326208aabe68 47 while(FrontGet()) {
miyajitakenari 6:326208aabe68 48 xbee.printf("frontget\n\r");
miyajitakenari 6:326208aabe68 49 Move('1', 0); //停止
miyajitakenari 11:d00bfdcb7481 50 Move('4', 0.2); //時計回り回転
miyajitakenari 11:d00bfdcb7481 51 wait(0.5);
miyajitakenari 6:326208aabe68 52 Move('1', 0); //回転停止
miyajitakenari 6:326208aabe68 53 xbee.printf("front_avoid_rotate\n\r");
miyajitakenari 6:326208aabe68 54 }
miyajitakenari 10:e25e06011fd2 55
miyajitakenari 10:e25e06011fd2 56 //障害物よけて走ってから目的地に回頭、走らないと障害物に向くかも
miyajitakenari 10:e25e06011fd2 57 Move('2', 0.1);
miyajitakenari 10:e25e06011fd2 58 wait(1);
miyajitakenari 10:e25e06011fd2 59 Move('2', 0.5);
miyajitakenari 10:e25e06011fd2 60 wait(2);
miyajitakenari 10:e25e06011fd2 61 Move('1', 0);
miyajitakenari 10:e25e06011fd2 62 //ちょっと走るのおわり
miyajitakenari 12:740d999b1fea 63 //走りながらanglegetできたら、止まらない
miyajitakenari 10:e25e06011fd2 64
miyajitakenari 0:79033ee3c961 65 direction = AngleGet();
miyajitakenari 6:326208aabe68 66 xbee.printf("direction=%f\n\rrotation_start", direction);
miyajitakenari 0:79033ee3c961 67 //角度調節
miyajitakenari 0:79033ee3c961 68 while(1) {
miyajitakenari 6:326208aabe68 69 if(direction < 20 || direction > 340) {
miyajitakenari 5:cc7917e8c442 70 xbee.printf("direction finish\n\r");
miyajitakenari 6:326208aabe68 71 Move('1', 0); //停止
miyajitakenari 11:d00bfdcb7481 72 Move('2', 0.5);
miyajitakenari 6:326208aabe68 73 xbee.printf("now_angle=%f\r\n", direction);
miyajitakenari 0:79033ee3c961 74 break;
miyajitakenari 5:cc7917e8c442 75 }
miyajitakenari 6:326208aabe68 76 else {
miyajitakenari 6:326208aabe68 77 Move('4', 0.15);//時計回りに回転
miyajitakenari 8:0f7e6ba9a434 78 xbee.printf("now_angle=%lf\r\n", direction);
miyajitakenari 6:326208aabe68 79 }
miyajitakenari 0:79033ee3c961 80 }
miyajitakenari 6:326208aabe68 81
miyajitakenari 5:cc7917e8c442 82 xbee.printf("speed flag=");
miyajitakenari 0:79033ee3c961 83 wait(3);
miyajitakenari 6:326208aabe68 84 float as[2];//advance speed
miyajitakenari 0:79033ee3c961 85 if(xbee.readable()){
miyajitakenari 0:79033ee3c961 86 xbee.printf("advance speed=");
miyajitakenari 6:326208aabe68 87 xbee.scanf("%f",&as[1]);
miyajitakenari 0:79033ee3c961 88 }else{
miyajitakenari 6:326208aabe68 89 as[1]=0.5;
miyajitakenari 0:79033ee3c961 90 }
miyajitakenari 6:326208aabe68 91 Move('2', as[1]);
miyajitakenari 6:326208aabe68 92 xbee.printf("mortor mode:2 speed:%f",as[1]);
miyajitakenari 0:79033ee3c961 93 catchGPS();
miyajitakenari 0:79033ee3c961 94 xbee.printf("now point(lati, long)=%lf , %lf\r\n", gps.latitude, gps.longitude);
miyajitakenari 0:79033ee3c961 95
miyajitakenari 0:79033ee3c961 96 double lati = 111132.8715; //1度あたりの緯度の距離(m)
miyajitakenari 0:79033ee3c961 97 double longi = 91535.79099; //1度あたりの経度の距離(m)
miyajitakenari 4:975b0d9bd51b 98 GPS_x = gps.latitude;
miyajitakenari 4:975b0d9bd51b 99 GPS_y = gps.longitude;
miyajitakenari 4:975b0d9bd51b 100 if ((next_CP_x - GPS_x)*(next_CP_x - GPS_x)*lati*lati + (next_CP_y - GPS_y)*(next_CP_y - GPS_y)*longi*longi < 25) { // CP到着判定 //試験で調整
miyajitakenari 0:79033ee3c961 101 xbee.printf("now leach cp[%d]=x_%f,y_%f",i,next_CP_x ,next_CP_y);
miyajitakenari 0:79033ee3c961 102 break;
miyajitakenari 0:79033ee3c961 103 }
miyajitakenari 0:79033ee3c961 104
miyajitakenari 0:79033ee3c961 105 }//while(1){}
miyajitakenari 0:79033ee3c961 106 }//for(){}
miyajitakenari 0:79033ee3c961 107 // 行動フロー終了
miyajitakenari 0:79033ee3c961 108 xbee.printf("End\r\n");
miyajitakenari 0:79033ee3c961 109 Move('1', 0); //停止
miyajitakenari 3:ec2b7587be78 110 xbee.printf("mortor mode:1 speed:0");
miyajitakenari 0:79033ee3c961 111 return 0;
miyajitakenari 0:79033ee3c961 112 }