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

Dependencies:   ATP3012 mbed a HMC US015_2 getGPS

main.cpp

Committer:
miyajitakenari
Date:
2021-11-10
Revision:
3:ec2b7587be78
Parent:
2:9bbc22250488
Child:
4:975b0d9bd51b

File content as of revision 3:ec2b7587be78:

/*ライブラリ*/
#include "mbed.h"

// 自作関数
#include "Function.h"

// フライトピン・ニクロム線関係
DigitalIn flight_pin(A0);
DigitalOut nichrome(D13);
// 
#define cp_max 3    //CPの数を入力する

int main() {
    // 変数宣言
    double GPS_x, GPS_y;  // 現在地の座標
    double direction;     // 次CPへの向き
    double CPs_x[3]={34.54608391847546, 34.545845666047306, 34.545666059919796};  //CPリスト(x座標)
    double CPs_y[3]={135.50338843400897, 135.50368659080985, 135.50347298593758};    // CPリスト(y座標)
    double next_CP_x, next_CP_y;
    
    // 落下検知
    // パラシュート分離
    
    wait(3);//電源ついてから3v3が安定するまで、秒数は適当、必要かもわからん
    while(flight_pin){}
        pc.printf("flight_pin nuketa");
        xbee.printf("flight_pin nuketa");
        wait(35);//ピン抜けてから地面につくまで70m/2.8(m/s)=25(s)余裕を見て+10s
        nichrome=1;
        pc.printf("nichrome in");
        xbee.printf("nichrome in");
        wait(30);
        nichrome=0;
    // 落下終了
    
    
    // 行動フロー開始
    Calibration();
    xbee.printf("XBee Connected\r\n");
    pc.printf("xbee_Connected\r\n");
    pc.printf("Fall point(lati,long)=(%lf , %lf)\r\n", gps.latitude, gps.longitude);
    xbee.printf("Fall point(lati,long)=(%lf , %lf)\r\n", gps.latitude, gps.longitude);
    for (int i = 0; i<=cp_max-1 ; i++) {//最後のcp=goalまで移動
        next_CP_x = CPs_x[i];
        next_CP_y = CPs_y[i];
        
        pc.printf("next_i=%d\r\n", i);
        xbee.printf("next_i=%d\r\n", i);
            
        while (1) {
                speak();
                direction = AngleGet();
                pc.printf("direction=%f\n", direction);
                xbee.printf("direction=%f\n", direction);
                //角度調節
                while(1) {
                    if(direction < 5 || direction > 355) {  //角度判定
                        break;
                    }
                    else {
                        Move('1', 0);//停止
                        pc.printf("mortor mode:1 speed:0");
                        xbee.printf("mortor mode:1 speed:0");
                        Move('4', 0.5);//時計回りに回転
                        pc.printf("mortor mode:4 speed:0.5");
                        pc.printf("mortor mode:4 speed:0.5");
                    }
                }
                
                while(FrontGet()) {
                    Move('1', 0);      //停止
                    pc.printf("mortor mode:1 speed:0");
                    xbee.printf("mortor mode:1 speed:0");
                    Move('4', 0.5);    //時計回り回転
                    pc.printf("mortor mode:4 speed:0.5");
                    xbee.printf("mortor mode:4 speed:0.5");
                    wait(1);
                    Move('1', 0);      //回転停止
                    pc.printf("mortor mode:1 speed:0");
                    xbee.printf("mortor mode:1 speed:0");
                } 
                pc.printf("\n\rflag=xbee ni Input");
                xbee.printf("\n\rspeed flag=");
                wait(3);
                float as;//advance speed
                if(xbee.readable()){
                    pc.printf("advance speed=xbee Input");
                    xbee.printf("advance speed=");
                    xbee.scanf("%f",&as);
                    }else{
                        as=0.5;
                        }
                Move('2', as);
                pc.printf("mortor mode:2 speed:%f",as);
                xbee.printf("mortor mode:2 speed:%f",as);
                catchGPS();
                pc.printf("%lf %lf\r\n", gps.latitude, gps.longitude);
                xbee.printf("now point(lati, long)=%lf , %lf\r\n", gps.latitude, gps.longitude);
                
                double lati = 111132.8715;    //1度あたりの緯度の距離(m)
                double longi = 91535.79099;    //1度あたりの経度の距離(m)
                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到着判定 //試験で調整
                    pc.printf("now leach cp[%d]=x_%f,y_%f",i,next_CP_x ,next_CP_y);
                    xbee.printf("now leach cp[%d]=x_%f,y_%f",i,next_CP_x ,next_CP_y);
                    break;
                }
                
            }//while(1){}
        }//for(){}
    // 行動フロー終了
    pc.printf("End\r\n");
    xbee.printf("End\r\n");
    Move('1', 0);      //停止
    pc.printf("mortor mode:1 speed:0");
    xbee.printf("mortor mode:1 speed:0");
    return 0;
}