all ok yesMU2
Dependencies: mbed mbedTimer SDFileSystem MU2 GPS
main.cpp@4:0d087e3f731d, 2019-08-06 (annotated)
- Committer:
- takepiyo
- Date:
- Tue Aug 06 08:54:58 2019 +0000
- Revision:
- 4:0d087e3f731d
- Parent:
- 3:4f1bac105598
- Child:
- 5:6d0de80387cf
- Child:
- 6:b7bf39bc3487
0806EM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nerosho | 0:d0f3991839ec | 1 | #include "mbed.h" |
Nerosho | 0:d0f3991839ec | 2 | #include "MU2.h" |
Nerosho | 0:d0f3991839ec | 3 | #include "SDFileSystem.h" |
takepiyo | 3:4f1bac105598 | 4 | #include "inletclose.h" |
Nerosho | 2:d6dc5c2224cc | 5 | //#include "GPS.h" |
Nerosho | 1:a8772ca26d1b | 6 | |
takepiyo | 4:0d087e3f731d | 7 | MU2 MuPort(p28,p27); |
takepiyo | 3:4f1bac105598 | 8 | SDFileSystem sd(p11, p12, p13, p14, "sd"); |
Nerosho | 2:d6dc5c2224cc | 9 | //GPS gps(p13,p14); |
takepiyo | 3:4f1bac105598 | 10 | Serial gps(p9,p10); //tx, rx |
takepiyo | 3:4f1bac105598 | 11 | |
takepiyo | 3:4f1bac105598 | 12 | Inlet inlet(p26,p15,p16);//モーター出力,感圧センサー1入力,感圧センサー2入力 |
Nerosho | 2:d6dc5c2224cc | 13 | |
Nerosho | 0:d0f3991839ec | 14 | |
takepiyo | 3:4f1bac105598 | 15 | //DigitalIn flight(p21); //フライトピン |
takepiyo | 3:4f1bac105598 | 16 | DigitalOut FIRE(p24); //溶断 |
Nerosho | 1:a8772ca26d1b | 17 | |
Nerosho | 1:a8772ca26d1b | 18 | DigitalOut myled(LED1); |
takepiyo | 4:0d087e3f731d | 19 | DigitalOut myled2(LED2); |
Nerosho | 1:a8772ca26d1b | 20 | DigitalOut myled3(LED3); |
Nerosho | 1:a8772ca26d1b | 21 | DigitalOut myled4(LED4); |
Nerosho | 0:d0f3991839ec | 22 | |
Nerosho | 0:d0f3991839ec | 23 | int main() |
Nerosho | 0:d0f3991839ec | 24 | { |
Nerosho | 2:d6dc5c2224cc | 25 | |
Nerosho | 1:a8772ca26d1b | 26 | wait(3); |
Nerosho | 0:d0f3991839ec | 27 | |
Nerosho | 2:d6dc5c2224cc | 28 | //FILE* fp1= fopen("/sd/cansat/log3.txt", "w"); |
takepiyo | 3:4f1bac105598 | 29 | FILE* fp2= fopen("/sd/cansat/gpsdata11.csv", "w"); |
takepiyo | 3:4f1bac105598 | 30 | |
Nerosho | 2:d6dc5c2224cc | 31 | /*if(fp1 == NULL || fp2 == NULL) |
takepiyo | 3:4f1bac105598 | 32 | { |
Nerosho | 2:d6dc5c2224cc | 33 | (fp1 == NULL) ? fprintf(stderr, "fname1 open error.\n") : fclose(fp1); |
Nerosho | 2:d6dc5c2224cc | 34 | (fp2 == NULL) ? fprintf(stderr, "fname2 open error.\n") : fclose(fp2); |
Nerosho | 2:d6dc5c2224cc | 35 | return -1; |
takepiyo | 3:4f1bac105598 | 36 | }*/ |
Nerosho | 2:d6dc5c2224cc | 37 | |
takepiyo | 3:4f1bac105598 | 38 | //溶断機構部分 |
Nerosho | 2:d6dc5c2224cc | 39 | |
Nerosho | 2:d6dc5c2224cc | 40 | //fprintf(fp1, "CanSat start!\r\n"); |
Nerosho | 0:d0f3991839ec | 41 | |
takepiyo | 3:4f1bac105598 | 42 | //fprintf(fp1, "Fire!!\r\n"); |
takepiyo | 3:4f1bac105598 | 43 | //FIRE=1; |
takepiyo | 3:4f1bac105598 | 44 | myled=1;//テストようにLED光らせてる |
takepiyo | 3:4f1bac105598 | 45 | wait(5);//溶断にかかる時間TBD秒 |
takepiyo | 3:4f1bac105598 | 46 | //FIRE=0; |
takepiyo | 3:4f1bac105598 | 47 | myled=0; |
takepiyo | 3:4f1bac105598 | 48 | |
takepiyo | 3:4f1bac105598 | 49 | //溶断機構終わり |
Nerosho | 0:d0f3991839ec | 50 | |
Nerosho | 2:d6dc5c2224cc | 51 | gps.baud(9600); |
Nerosho | 2:d6dc5c2224cc | 52 | char recvGPS=0; |
Nerosho | 2:d6dc5c2224cc | 53 | char getGPS[128]; |
Nerosho | 2:d6dc5c2224cc | 54 | int i=0; |
takepiyo | 3:4f1bac105598 | 55 | int timer=0; |
takepiyo | 3:4f1bac105598 | 56 | |
Nerosho | 2:d6dc5c2224cc | 57 | //fprintf(fp1, "GPS start!\r\n"); |
Nerosho | 2:d6dc5c2224cc | 58 | |
takepiyo | 3:4f1bac105598 | 59 | while(1) |
takepiyo | 3:4f1bac105598 | 60 | { |
takepiyo | 4:0d087e3f731d | 61 | myled3=1; |
takepiyo | 4:0d087e3f731d | 62 | myled2=0; |
takepiyo | 3:4f1bac105598 | 63 | if(gps.readable()) |
takepiyo | 3:4f1bac105598 | 64 | { |
Nerosho | 2:d6dc5c2224cc | 65 | recvGPS=gps.getc(); |
Nerosho | 2:d6dc5c2224cc | 66 | getGPS[i]=recvGPS; |
Nerosho | 2:d6dc5c2224cc | 67 | |
takepiyo | 3:4f1bac105598 | 68 | if(getGPS[i]=='\n') |
takepiyo | 3:4f1bac105598 | 69 | { |
Nerosho | 2:d6dc5c2224cc | 70 | |
takepiyo | 3:4f1bac105598 | 71 | if((getGPS[5]=='G')&&(getGPS[6]=='A')) |
takepiyo | 3:4f1bac105598 | 72 | { |
takepiyo | 4:0d087e3f731d | 73 | |
takepiyo | 3:4f1bac105598 | 74 | MuPort.send(getGPS); |
takepiyo | 3:4f1bac105598 | 75 | |
Nerosho | 2:d6dc5c2224cc | 76 | /*if(fp == NULL) { |
Nerosho | 2:d6dc5c2224cc | 77 | error("Could not open file for write\n"); |
Nerosho | 2:d6dc5c2224cc | 78 | }*/ |
takepiyo | 3:4f1bac105598 | 79 | |
Nerosho | 2:d6dc5c2224cc | 80 | fprintf(fp2, "%s\n",getGPS); |
Nerosho | 2:d6dc5c2224cc | 81 | //fclose(fp); |
takepiyo | 3:4f1bac105598 | 82 | |
takepiyo | 3:4f1bac105598 | 83 | wait(0.1); |
takepiyo | 4:0d087e3f731d | 84 | timer++; |
Nerosho | 2:d6dc5c2224cc | 85 | } |
Nerosho | 2:d6dc5c2224cc | 86 | |
Nerosho | 2:d6dc5c2224cc | 87 | i=0; |
Nerosho | 2:d6dc5c2224cc | 88 | } |
Nerosho | 2:d6dc5c2224cc | 89 | i++; |
takepiyo | 4:0d087e3f731d | 90 | if(timer>10)//落下開始してからTBD秒後whileを抜ける. |
takepiyo | 3:4f1bac105598 | 91 | { |
takepiyo | 3:4f1bac105598 | 92 | break; |
takepiyo | 3:4f1bac105598 | 93 | } |
Nerosho | 2:d6dc5c2224cc | 94 | } |
Nerosho | 2:d6dc5c2224cc | 95 | |
Nerosho | 2:d6dc5c2224cc | 96 | // wait(1); |
Nerosho | 2:d6dc5c2224cc | 97 | //fclose(fp); |
Nerosho | 0:d0f3991839ec | 98 | } |
takepiyo | 3:4f1bac105598 | 99 | |
takepiyo | 3:4f1bac105598 | 100 | while(1) |
takepiyo | 3:4f1bac105598 | 101 | { |
takepiyo | 4:0d087e3f731d | 102 | myled3=0; |
takepiyo | 4:0d087e3f731d | 103 | myled2=1; |
takepiyo | 3:4f1bac105598 | 104 | if(gps.readable()) |
takepiyo | 3:4f1bac105598 | 105 | { |
takepiyo | 3:4f1bac105598 | 106 | recvGPS=gps.getc(); |
takepiyo | 3:4f1bac105598 | 107 | getGPS[i]=recvGPS; |
takepiyo | 3:4f1bac105598 | 108 | |
takepiyo | 3:4f1bac105598 | 109 | if(getGPS[i]=='\n') |
takepiyo | 3:4f1bac105598 | 110 | { |
takepiyo | 3:4f1bac105598 | 111 | |
takepiyo | 3:4f1bac105598 | 112 | if((getGPS[5]=='G')&&(getGPS[6]=='A')) |
takepiyo | 3:4f1bac105598 | 113 | { |
takepiyo | 4:0d087e3f731d | 114 | MuPort.send(getGPS); |
takepiyo | 3:4f1bac105598 | 115 | |
takepiyo | 3:4f1bac105598 | 116 | /*if(fp == NULL) { |
takepiyo | 3:4f1bac105598 | 117 | error("Could not open file for write\n"); |
takepiyo | 3:4f1bac105598 | 118 | }*/ |
takepiyo | 3:4f1bac105598 | 119 | |
takepiyo | 3:4f1bac105598 | 120 | fprintf(fp2, "%s\n",getGPS); |
takepiyo | 3:4f1bac105598 | 121 | //fclose(fp); |
takepiyo | 3:4f1bac105598 | 122 | wait(0.1); |
takepiyo | 3:4f1bac105598 | 123 | } |
takepiyo | 3:4f1bac105598 | 124 | |
takepiyo | 3:4f1bac105598 | 125 | i=0; |
takepiyo | 3:4f1bac105598 | 126 | } |
takepiyo | 3:4f1bac105598 | 127 | i++; |
takepiyo | 3:4f1bac105598 | 128 | inlet.Close(0.9); |
takepiyo | 3:4f1bac105598 | 129 | } |
takepiyo | 3:4f1bac105598 | 130 | |
takepiyo | 3:4f1bac105598 | 131 | // wait(1); |
takepiyo | 3:4f1bac105598 | 132 | //fclose(fp); |
takepiyo | 3:4f1bac105598 | 133 | } |
takepiyo | 3:4f1bac105598 | 134 | |
takepiyo | 3:4f1bac105598 | 135 | |
Nerosho | 2:d6dc5c2224cc | 136 | //fclose(fp1); |
Nerosho | 2:d6dc5c2224cc | 137 | fclose(fp2); |
Nerosho | 2:d6dc5c2224cc | 138 | |
Nerosho | 2:d6dc5c2224cc | 139 | } |
Nerosho | 2:d6dc5c2224cc | 140 | |
Nerosho | 2:d6dc5c2224cc | 141 | |
Nerosho | 2:d6dc5c2224cc | 142 |