cansat_B 2019 / Mbed 2 deprecated tougou-no3

Dependencies:   mbed

main.cpp

Committer:
YUPPY
Date:
2019-11-28
Revision:
4:75090ff74dd0
Parent:
3:f70ecf1e21d5
Child:
5:9b5899b06e2e

File content as of revision 4:75090ff74dd0:

#include "mbed.h"
#include "JPEGCamera.h"
#include "us015.h"
#include "TB6612.h"
DigitalOut myled(LED1);
US015 hs(p12,p11);
DigitalIn thermo(p20);
DigitalOut Sb612switch(p15);//焦電スイッチ
DigitalOut Ultra(p12);
Serial pc(USBTX,USBRX); // tx, rx
JPEGCamera camera(p9, p10); // TX, RX
TB6612 left(p25,p17,p16);//モーターピン
TB6612 right(p26,p19,p18);//モーターピン
int main(){
  int i=1;
  float th;
  Timer tm;
  for(i=0;i<3;i++){
  pc.printf("start\r\n");
  left = 100; //左モーター100%
  right = 100;//右モーター100%
 
    Sb612switch=0; //焦電off
    Ultra=1;//超音波on
    
    while(1) {
         printf("超音波on\r\n 焦電off\r\n" )  ;
         hs.TrigerOut();
         wait(1);
         int distance;
         distance = hs.GetDistance();
         printf("distance=%d\r\n",distance);//距離出力
        
        if(distance<=2000){//超音波反応
         left = 0; //左モーター0%
         right = 0;//右モーター0%
         printf("停止\n\r");
         wait(5.0);
         
         Ultra=0;//超音波off
         Sb612switch=1; //焦電on
          printf("超音波off\r\n焦電on\r\n  ");
           bool detected=false;
             th = thermo;
             if(th==1 && !detected) {//焦電反応ありの場合
               i++; 
               detected=true;
               pc.printf("human\r\n");
               tm.reset();
               tm.start();
          
               LocalFileSystem local("local");
               Timer timer;
               timer.start();
               camera.setPictureSize(JPEGCamera::SIZE320x240);

            
               if (camera.isReady()) {
                 char filename[32];
                 sprintf(filename, "/local/pict%03d.jpg",i);
                 printf("Picture: %s ", filename);
                 if (camera.takePicture(filename)) { 
                  while (camera.isProcessing()) {
                    camera.processPicture();
                    printf("take pictuer!");
                   }
                 }else{
                 printf("take picture failed\r\n");
                 }
               }else{
                 printf("camera is not ready\r\n");
                }
               
               printf("time = %f\n", timer.read());
               
              }else{//焦電反応なしの場合
              printf("not found!\r\n");
               
               left = 70; //左モーター10%
               right = 100;//右モーター100%(右折)
               Sb612switch=0;
               Ultra=1;
               detected=false;
               printf("右折\n\r");
               wait(3.0);
               left = 100; //左モーター100%
               right = 100;//右モーター100%
              }           
       }else{//超音波distance>2000
          printf("safety zone\r\n");
          left = 100; //左モーター100%
          right = 70;//右モーター70%(左折)
          printf("左折\r\n");
         }

    }

}


 
  }