統合試験用です。
Dependencies: ATP3012 mbed TB6612FNG HMC US015 getGPS
main.cpp@20:02afaa2186f3, 2021-11-04 (annotated)
- Committer:
- ushiroji
- Date:
- Thu Nov 04 11:35:18 2021 +0000
- Revision:
- 20:02afaa2186f3
- Parent:
- 19:046524ac0985
add Calibration to Function.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
user_ | 6:1cda8471adc3 | 1 | // ライブラリ |
ushiroji | 0:5a1b52164bbe | 2 | #include "mbed.h" |
ushiroji | 14:1b5be519bd49 | 3 | |
user_ | 6:1cda8471adc3 | 4 | // 自作関数 |
ushiroji | 14:1b5be519bd49 | 5 | #include "Function.h" |
ushiroji | 15:4779723a4f75 | 6 | #include "speak.h" |
ushiroji | 0:5a1b52164bbe | 7 | |
user_ | 7:8fab045d2616 | 8 | // フライトピン・ニクロム線関係 |
user_ | 7:8fab045d2616 | 9 | DigitalIn flight_pin(A0); |
user_ | 7:8fab045d2616 | 10 | DigitalOut nichrome(D13); |
user_ | 8:5fe1b4bbd108 | 11 | // |
ushiroji | 18:42cbba4fb371 | 12 | #define cp_max 3 //CPの数を入力する |
ushiroji | 0:5a1b52164bbe | 13 | |
ushiroji | 0:5a1b52164bbe | 14 | int main() { |
ushiroji | 0:5a1b52164bbe | 15 | // 変数宣言 |
user_ | 6:1cda8471adc3 | 16 | double GPS_x, GPS_y; // 現在地の座標 |
user_ | 6:1cda8471adc3 | 17 | double direction; // 次CPへの向き |
ushiroji | 20:02afaa2186f3 | 18 | double CPs_x[3]={34.54608391847546, 34.545845666047306, 34.545666059919796}; //CPリスト(x座標) |
ushiroji | 20:02afaa2186f3 | 19 | double CPs_y[3]={135.50338843400897, 135.50368659080985, 135.50347298593758}; // CPリスト(y座標) |
user_ | 6:1cda8471adc3 | 20 | double next_CP_x, next_CP_y; |
user_ | 6:1cda8471adc3 | 21 | |
user_ | 6:1cda8471adc3 | 22 | // 落下検知 |
user_ | 7:8fab045d2616 | 23 | // パラシュート分離 |
ushiroji | 18:42cbba4fb371 | 24 | |
ushiroji | 14:1b5be519bd49 | 25 | wait(3);//電源ついてから3v3が安定するまで、秒数は適当、必要かもわからん |
ushiroji | 14:1b5be519bd49 | 26 | while(flight_pin){ |
user_ | 7:8fab045d2616 | 27 | pc.printf("flight_pin nuketa"); |
user_ | 7:8fab045d2616 | 28 | wait(35);//ピン抜けてから地面につくまで70m/2.8(m/s)=25(s)余裕を見て+10s |
user_ | 7:8fab045d2616 | 29 | nichrome=1; |
user_ | 7:8fab045d2616 | 30 | pc.printf("nichrome in"); |
user_ | 7:8fab045d2616 | 31 | wait(30); |
user_ | 7:8fab045d2616 | 32 | nichrome=0; |
ushiroji | 14:1b5be519bd49 | 33 | } |
user_ | 7:8fab045d2616 | 34 | // 落下終了 |
user_ | 6:1cda8471adc3 | 35 | |
user_ | 7:8fab045d2616 | 36 | |
user_ | 6:1cda8471adc3 | 37 | // 行動フロー開始 |
ushiroji | 20:02afaa2186f3 | 38 | Calibration(); |
ushiroji | 17:1b6a84ab4433 | 39 | while (next_CP_x != CPs_x[cp_max-1] && next_CP_y != CPs_y[cp_max-1]) { // ゴール判定 |
ushiroji | 17:1b6a84ab4433 | 40 | for (int i = 0; i<=cp_max-1 ; i++) { |
user_ | 6:1cda8471adc3 | 41 | // 移動 |
ushiroji | 17:1b6a84ab4433 | 42 | next_CP_x = CPs_x[i]; |
ushiroji | 17:1b6a84ab4433 | 43 | next_CP_y = CPs_y[i]; |
ushiroji | 17:1b6a84ab4433 | 44 | |
ushiroji | 17:1b6a84ab4433 | 45 | pc.printf("i=%d\r\n", i); |
ushiroji | 17:1b6a84ab4433 | 46 | pc.printf("%lf %lf\r\n", gps.latitude, gps.longitude); |
ushiroji | 14:1b5be519bd49 | 47 | |
ushiroji | 14:1b5be519bd49 | 48 | while (1) { |
ushiroji | 15:4779723a4f75 | 49 | speak(); |
ushiroji | 18:42cbba4fb371 | 50 | |
ushiroji | 14:1b5be519bd49 | 51 | direction = AngleGet(); |
ushiroji | 17:1b6a84ab4433 | 52 | pc.printf("direction=%f\n", direction); |
ushiroji | 16:b5a60a976bf7 | 53 | while(1) { |
ushiroji | 16:b5a60a976bf7 | 54 | if(direction < 5 || direction > 355) { //角度判定 |
ushiroji | 16:b5a60a976bf7 | 55 | Move('2', 1); |
ushiroji | 16:b5a60a976bf7 | 56 | break; |
ushiroji | 16:b5a60a976bf7 | 57 | } |
ushiroji | 16:b5a60a976bf7 | 58 | else { |
ushiroji | 16:b5a60a976bf7 | 59 | Move('1', 0); |
ushiroji | 16:b5a60a976bf7 | 60 | Move('4', 0.5); |
ushiroji | 16:b5a60a976bf7 | 61 | } |
ushiroji | 14:1b5be519bd49 | 62 | } |
user_ | 8:5fe1b4bbd108 | 63 | |
ushiroji | 14:1b5be519bd49 | 64 | if (FrontGet()) { |
ushiroji | 14:1b5be519bd49 | 65 | Move('1', 0); //停止 |
ushiroji | 14:1b5be519bd49 | 66 | Move('4', 0.5); //回転 |
ushiroji | 14:1b5be519bd49 | 67 | wait(1); |
ushiroji | 14:1b5be519bd49 | 68 | Move('1', 0); //回転停止 |
ushiroji | 14:1b5be519bd49 | 69 | continue; |
ushiroji | 14:1b5be519bd49 | 70 | } |
ushiroji | 14:1b5be519bd49 | 71 | else { |
ushiroji | 14:1b5be519bd49 | 72 | Move('2', 0.5); |
ushiroji | 14:1b5be519bd49 | 73 | } |
ushiroji | 14:1b5be519bd49 | 74 | catchGPS(); |
ushiroji | 17:1b6a84ab4433 | 75 | pc.printf("%lf %lf\r\n", gps.latitude, gps.longitude); |
ushiroji | 20:02afaa2186f3 | 76 | |
ushiroji | 20:02afaa2186f3 | 77 | double lati = 111132.8715; //1度あたりの緯度の距離(m) |
ushiroji | 20:02afaa2186f3 | 78 | double longi = 91535.79099; //1度あたりの経度の距離(m) |
ushiroji | 20:02afaa2186f3 | 79 | 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 < 100) { // CP到着判定 //試験で調整 |
ushiroji | 17:1b6a84ab4433 | 80 | pc.printf("now leach cp[%d]=x_%f,y_%f",i,next_CP_x ,next_CP_y); |
ushiroji | 14:1b5be519bd49 | 81 | break; |
ushiroji | 14:1b5be519bd49 | 82 | } |
ushiroji | 17:1b6a84ab4433 | 83 | |
user_ | 8:5fe1b4bbd108 | 84 | } |
ushiroji | 3:74d0faefdd78 | 85 | } |
user_ | 6:1cda8471adc3 | 86 | // 行動フロー終了 |
ushiroji | 17:1b6a84ab4433 | 87 | pc.printf("End\r\n"); |
ushiroji | 18:42cbba4fb371 | 88 | Move('1', 0); //停止 |
user_ | 6:1cda8471adc3 | 89 | return 0; |
ushiroji | 14:1b5be519bd49 | 90 | } |
ushiroji | 5:56eddb7b4a9e | 91 | } |