Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@7:a47fdb7f9bc8, 2019-12-02 (annotated)
- Committer:
- saeichi
- Date:
- Mon Dec 02 10:24:31 2019 +0000
- Revision:
- 7:a47fdb7f9bc8
- Parent:
- 6:cf43f62b1e75
tougou;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KINU | 0:f728b8e6bdf2 | 1 | #include "mbed.h" |
KINU | 0:f728b8e6bdf2 | 2 | #include "JPEGCamera.h" |
KINU | 0:f728b8e6bdf2 | 3 | #include "us015.h" |
KINU | 3:f70ecf1e21d5 | 4 | #include "TB6612.h" |
saeichi | 5:9b5899b06e2e | 5 | #include <stdio.h> |
saeichi | 5:9b5899b06e2e | 6 | #include <base64.h> |
saeichi | 5:9b5899b06e2e | 7 | |
KINU | 0:f728b8e6bdf2 | 8 | DigitalOut myled(LED1); |
KINU | 0:f728b8e6bdf2 | 9 | US015 hs(p12,p11); |
YUPPY | 4:75090ff74dd0 | 10 | DigitalIn thermo(p20); |
saeichi | 5:9b5899b06e2e | 11 | DigitalOut Sb612switch(p15); //焦電スイッチ |
KINU | 0:f728b8e6bdf2 | 12 | DigitalOut Ultra(p12); |
saeichi | 5:9b5899b06e2e | 13 | Serial pc(USBTX,USBRX); // tx, rx |
saeichi | 5:9b5899b06e2e | 14 | JPEGCamera camera(p9, p10); // TX, RX |
saeichi | 5:9b5899b06e2e | 15 | TB6612 left1(p25,p17,p16); //モーターピン |
saeichi | 5:9b5899b06e2e | 16 | TB6612 right1(p26,p19,p18); //モーターピン |
saeichi | 5:9b5899b06e2e | 17 | Serial xbee(p13,p14); //xbee |
saeichi | 5:9b5899b06e2e | 18 | |
KINU | 0:f728b8e6bdf2 | 19 | int main(){ |
seijakunouenimutou | 2:c799e2dde99f | 20 | int i=1; |
KINU | 0:f728b8e6bdf2 | 21 | float th; |
KINU | 0:f728b8e6bdf2 | 22 | Timer tm; |
seijakunouenimutou | 2:c799e2dde99f | 23 | for(i=0;i<3;i++){ |
KINU | 0:f728b8e6bdf2 | 24 | pc.printf("start\r\n"); |
saeichi | 5:9b5899b06e2e | 25 | |
saeichi | 5:9b5899b06e2e | 26 | left1 = 100; //左モーター100% |
saeichi | 5:9b5899b06e2e | 27 | right1 = 100;//右モーター100% |
YUPPY | 4:75090ff74dd0 | 28 | |
YUPPY | 4:75090ff74dd0 | 29 | Sb612switch=0; //焦電off |
KINU | 0:f728b8e6bdf2 | 30 | Ultra=1;//超音波on |
KINU | 3:f70ecf1e21d5 | 31 | |
KINU | 0:f728b8e6bdf2 | 32 | while(1) { |
YUPPY | 4:75090ff74dd0 | 33 | printf("超音波on\r\n 焦電off\r\n" ) ; |
KINU | 0:f728b8e6bdf2 | 34 | hs.TrigerOut(); |
KINU | 0:f728b8e6bdf2 | 35 | wait(1); |
KINU | 0:f728b8e6bdf2 | 36 | int distance; |
KINU | 0:f728b8e6bdf2 | 37 | distance = hs.GetDistance(); |
YUPPY | 4:75090ff74dd0 | 38 | printf("distance=%d\r\n",distance);//距離出力 |
KINU | 0:f728b8e6bdf2 | 39 | |
YUPPY | 4:75090ff74dd0 | 40 | if(distance<=2000){//超音波反応 |
saeichi | 5:9b5899b06e2e | 41 | left1 = 0; //左モーター0% |
saeichi | 5:9b5899b06e2e | 42 | right1 = 0;//右モーター0% |
KINU | 3:f70ecf1e21d5 | 43 | printf("停止\n\r"); |
YUPPY | 4:75090ff74dd0 | 44 | wait(5.0); |
KINU | 3:f70ecf1e21d5 | 45 | |
KINU | 0:f728b8e6bdf2 | 46 | Ultra=0;//超音波off |
YUPPY | 4:75090ff74dd0 | 47 | Sb612switch=1; //焦電on |
YUPPY | 4:75090ff74dd0 | 48 | printf("超音波off\r\n焦電on\r\n "); |
YUPPY | 4:75090ff74dd0 | 49 | bool detected=false; |
KINU | 0:f728b8e6bdf2 | 50 | th = thermo; |
YUPPY | 4:75090ff74dd0 | 51 | if(th==1 && !detected) {//焦電反応ありの場合 |
KINU | 3:f70ecf1e21d5 | 52 | i++; |
KINU | 0:f728b8e6bdf2 | 53 | detected=true; |
KINU | 3:f70ecf1e21d5 | 54 | pc.printf("human\r\n"); |
KINU | 3:f70ecf1e21d5 | 55 | tm.reset(); |
KINU | 3:f70ecf1e21d5 | 56 | tm.start(); |
KINU | 0:f728b8e6bdf2 | 57 | |
KINU | 3:f70ecf1e21d5 | 58 | LocalFileSystem local("local"); |
KINU | 3:f70ecf1e21d5 | 59 | Timer timer; |
KINU | 3:f70ecf1e21d5 | 60 | timer.start(); |
KINU | 3:f70ecf1e21d5 | 61 | camera.setPictureSize(JPEGCamera::SIZE320x240); |
saeichi | 5:9b5899b06e2e | 62 | |
saeichi | 5:9b5899b06e2e | 63 | FILE *fp; |
saeichi | 5:9b5899b06e2e | 64 | base64 *bs; |
saeichi | 5:9b5899b06e2e | 65 | int c; |
KINU | 0:f728b8e6bdf2 | 66 | |
saeichi | 5:9b5899b06e2e | 67 | for (int r = 0; r < 1; r++) { |
KINU | 3:f70ecf1e21d5 | 68 | if (camera.isReady()) { |
KINU | 3:f70ecf1e21d5 | 69 | char filename[32]; |
saeichi | 5:9b5899b06e2e | 70 | sprintf(filename, "/local/pict%03d.jpg",r); |
KINU | 3:f70ecf1e21d5 | 71 | printf("Picture: %s ", filename); |
KINU | 3:f70ecf1e21d5 | 72 | if (camera.takePicture(filename)) { |
KINU | 3:f70ecf1e21d5 | 73 | while (camera.isProcessing()) { |
KINU | 0:f728b8e6bdf2 | 74 | camera.processPicture(); |
KINU | 0:f728b8e6bdf2 | 75 | printf("take pictuer!"); |
KINU | 3:f70ecf1e21d5 | 76 | } |
KINU | 3:f70ecf1e21d5 | 77 | }else{ |
KINU | 0:f728b8e6bdf2 | 78 | printf("take picture failed\r\n"); |
KINU | 3:f70ecf1e21d5 | 79 | } |
KINU | 3:f70ecf1e21d5 | 80 | }else{ |
KINU | 3:f70ecf1e21d5 | 81 | printf("camera is not ready\r\n"); |
KINU | 0:f728b8e6bdf2 | 82 | } |
KINU | 3:f70ecf1e21d5 | 83 | |
KINU | 3:f70ecf1e21d5 | 84 | printf("time = %f\n", timer.read()); |
seijakunouenimutou | 2:c799e2dde99f | 85 | |
saeichi | 5:9b5899b06e2e | 86 | |
saeichi | 5:9b5899b06e2e | 87 | |
saeichi | 5:9b5899b06e2e | 88 | xbee.printf("xbee connected!\r\n"); |
saeichi | 5:9b5899b06e2e | 89 | bs = new base64(); |
saeichi | 5:9b5899b06e2e | 90 | bs->Encode("/local/pict000.jpg","/local/data000.txt"); |
saeichi | 5:9b5899b06e2e | 91 | |
saeichi | 5:9b5899b06e2e | 92 | if((fp=fopen("/local/data000.txt","r"))!=NULL) |
saeichi | 5:9b5899b06e2e | 93 | { |
saeichi | 5:9b5899b06e2e | 94 | pc.printf("ok\r\n"); |
saeichi | 5:9b5899b06e2e | 95 | while((c=fgetc(fp))!=EOF){ |
saeichi | 5:9b5899b06e2e | 96 | xbee.printf("%c",c); |
saeichi | 5:9b5899b06e2e | 97 | } |
saeichi | 5:9b5899b06e2e | 98 | fclose(fp); |
saeichi | 5:9b5899b06e2e | 99 | } |
saeichi | 5:9b5899b06e2e | 100 | } |
saeichi | 7:a47fdb7f9bc8 | 101 | while(1){ |
seijakunouenimutou | 6:cf43f62b1e75 | 102 | |
saeichi | 7:a47fdb7f9bc8 | 103 | int received_data = xbee.getc(); |
seijakunouenimutou | 6:cf43f62b1e75 | 104 | |
saeichi | 7:a47fdb7f9bc8 | 105 | if (received_data == 82 || received_data == 114){ //Rまたはr |
saeichi | 7:a47fdb7f9bc8 | 106 | xbee.printf("_________________________________________________________________________________________________________________________________\r\n"); |
saeichi | 7:a47fdb7f9bc8 | 107 | if((fp=fopen("/local/data000.txt","r"))!=NULL) |
saeichi | 7:a47fdb7f9bc8 | 108 | { |
saeichi | 7:a47fdb7f9bc8 | 109 | while ((c=fgetc(fp))!=EOF){ |
saeichi | 7:a47fdb7f9bc8 | 110 | xbee.printf("%c",c); //再送 |
saeichi | 7:a47fdb7f9bc8 | 111 | } |
saeichi | 7:a47fdb7f9bc8 | 112 | fclose(fp); |
saeichi | 7:a47fdb7f9bc8 | 113 | } |
saeichi | 7:a47fdb7f9bc8 | 114 | } |
saeichi | 7:a47fdb7f9bc8 | 115 | else{ |
saeichi | 7:a47fdb7f9bc8 | 116 | break; |
saeichi | 7:a47fdb7f9bc8 | 117 | } |
saeichi | 7:a47fdb7f9bc8 | 118 | } |
saeichi | 7:a47fdb7f9bc8 | 119 | |
saeichi | 5:9b5899b06e2e | 120 | |
KINU | 3:f70ecf1e21d5 | 121 | }else{//焦電反応なしの場合 |
YUPPY | 4:75090ff74dd0 | 122 | printf("not found!\r\n"); |
YUPPY | 4:75090ff74dd0 | 123 | |
saeichi | 5:9b5899b06e2e | 124 | left1 = 70; //左モーター10% |
saeichi | 5:9b5899b06e2e | 125 | right1 = 100;//右モーター100%(右折) |
YUPPY | 4:75090ff74dd0 | 126 | Sb612switch=0; |
YUPPY | 4:75090ff74dd0 | 127 | Ultra=1; |
KINU | 3:f70ecf1e21d5 | 128 | detected=false; |
KINU | 3:f70ecf1e21d5 | 129 | printf("右折\n\r"); |
KINU | 3:f70ecf1e21d5 | 130 | wait(3.0); |
saeichi | 5:9b5899b06e2e | 131 | left1 = 100; //左モーター100% |
saeichi | 5:9b5899b06e2e | 132 | right1 = 100;//右モーター100% |
KINU | 3:f70ecf1e21d5 | 133 | } |
KINU | 3:f70ecf1e21d5 | 134 | }else{//超音波distance>2000 |
YUPPY | 4:75090ff74dd0 | 135 | printf("safety zone\r\n"); |
saeichi | 5:9b5899b06e2e | 136 | left1 = 100; //左モーター100% |
saeichi | 5:9b5899b06e2e | 137 | right1 = 70;//右モーター70%(左折) |
YUPPY | 4:75090ff74dd0 | 138 | printf("左折\r\n"); |
KINU | 3:f70ecf1e21d5 | 139 | } |
KINU | 3:f70ecf1e21d5 | 140 | |
KINU | 3:f70ecf1e21d5 | 141 | } |
KINU | 3:f70ecf1e21d5 | 142 | |
KINU | 0:f728b8e6bdf2 | 143 | } |
KINU | 3:f70ecf1e21d5 | 144 | |
KINU | 3:f70ecf1e21d5 | 145 | |
KINU | 0:f728b8e6bdf2 | 146 | |
KINU | 0:f728b8e6bdf2 | 147 | } |
saeichi | 5:9b5899b06e2e | 148 | |
YUPPY | 4:75090ff74dd0 | 149 |