mainまでいけました カメラのとこからコンパイルできません

Dependencies:   mbed CameraUS015sb612-3

Revision:
4:1354e56c7dd3
Parent:
3:5d0c4b13f4e8
Child:
5:5aa7223226df
--- a/main.cpp	Fri Nov 08 19:48:16 2019 +0000
+++ b/main.cpp	Wed Nov 20 08:06:46 2019 +0000
@@ -1,28 +1,23 @@
 #define cansatB
+#define min(x, y) ((x) < (y)) ? (x) : (y)
 #include "mbed.h"       //mbed
 #include "getGPS.h"         //GPS
 #include "math.h"         //GPS
 #include "TB6612.h"      //motorDriver
-#include "XBee.h"        //XBee
-#include <SoftwareSerial.h>   //カメラ
-#include <SD.h>//SDカード
-#include <JPEGCamera.h>//カメラ
+#include "JPEGCamera.h"//カメラ
+#include "base64.h"//写真ーXBee
 #include "us015.h"  // 超音波センサ
 #include <stdio.h>
 US015 hs(p12,p11);                  //P12 :超音波センサ トリガ出力  //p11 :超音波センサ  エコー入力
-Serial pc(USBTX,USBRX);            //GPs
 GPS gps (p28,p27);                 //GPS
-PwmOut motorSpeedR(p26);  //モーター
-PwmOut motorSpeedL(p25);  //モーター
-DigitalIn flight(p22,p23);      //フライトピン
+
 DigitalOut FET(p21);                //FET
-XBee xbee(p13, p14);               // XBee
+DigitalOut Ultra(p12);
 DigitalIn thermo(p20);     //焦電センサ↓
 DigitalOut led(LED1);     
-Serial pc(USBTX, USBRX); // tx, rx  焦電センサ↑
-Serial pc (p9);     //カメラ
-TB6612 left(p25,p17,p16);
-TB6612 right(p26,p19,p18);
+Serial pc(USBTX,USBRX); // tx, rx  焦電センサ↑
+TB6612 left(p25,p17,p16);//motor
+TB6612 right(p26,p19,p18);//motor
 
 int main() {            //FET
     FET = 0;
@@ -52,7 +47,6 @@
     }
     }
     }
-
 int main() {       //以下GPS
      double a;
      double b;
@@ -104,7 +98,13 @@
 
          if (distance<5){
              printf("%lf\r\n",distance);   
+        left = 100; //左モーター100%
+        right = 100;//右モーター100%
+        printf("直進\n\r");
              }else{
+             left = 0; 
+             right = 0;
+             printf("停止\n\r");
              pc.printf("5m clear!");
              break;
               }
@@ -117,64 +117,215 @@
         return 0;          //注意!void()に変えること.このままだとここで終わる
      }
       
-int main() {
+    int main(){
+  float th;
+  Timer tm;
+  pc.printf("start\r\n");
+
+  bool detected=false;
+    thermo=0; //焦電off
+    Ultra=1;//超音波on
+   
     while(1) {
-        left = 100; //左モーター100%
-        right = 100;//右モーター100%
-        wait(1.0);
-        left = 30;//左30%
-        right = 30;//右30%
-        wait(1.0);
-        printf("OK");
+         hs.TrigerOut();
+         wait(1);
+         int distance;
+         distance = hs.GetDistance();
+         printf("%d\r\n",distance);//距離出力
+        
+        if(distance<2000){//超音波反応
+         Ultra=0;//超音波off
+         thermo=1;//焦電on
+         left = 0; //左モーター0%
+        right = 0;//右モーター0%
+        printf("停止\n\r");
+          if(true)
+             th = thermo;
+             if(th=1 && !detected) {//焦電反応ありの場合
+               detected=true;
+             pc.printf("human\r\n");
+             tm.reset();
+             tm.start();
+             thermo=0;
+       const int RESPONSE_TIMEOUT = 500;
+const int DATA_TIMEOUT = 1000;
+
+JPEGCamera::JPEGCamera(PinName tx, PinName rx) : Serial(tx, rx) {
+    printf("AA\r\n");
+    baud(38400);
+    state = READY;
+}
+
+bool JPEGCamera::setPictureSize(JPEGCamera::PictureSize size, bool doReset) {
+    char buf[9] = {0x56, 0x00, 0x31, 0x05, 0x04, 0x01, 0x00, 0x19, (char) size};
+    int ret = sendReceive(buf, sizeof buf, 5);
+
+    if (ret == 5 && buf[0] == 0x76) {
+        if (doReset)
+            reset();
+        return true;
+    } else
+        return false;
+}
+
+bool JPEGCamera::isReady() {
+    return state == READY;
+}
+
+bool JPEGCamera::isProcessing() {
+    return state == PROCESSING;
+}
+
+bool JPEGCamera::takePicture(char *filename) {
+    if (state == READY) {
+        fp = fopen(filename, "wb");
+        if (fp != 0) {
+            if (takePicture()) {
+                imageSize = getImageSize();
+                address = 0;
+                state = PROCESSING;
+            } else {
+                fclose(fp);
+                printf("takePicture(%s) failed", filename);
+                state = ERROR;
+            }
+        } else {
+            printf("fopen() failed");
+            state = ERROR;
+        }
     }
+    return state != ERROR;
+}
+
+bool JPEGCamera::processPicture() {
+    if (state == PROCESSING) {
+        if (address < imageSize) {
+            char data[1024];
+            int size = readData(data, min(sizeof(data), imageSize - address), address);
+            int ret = fwrite(data, size, 1, fp);
+            if (ret > 0)
+                address += size;
+            if (ret == 0 || address >= imageSize) {
+                stopPictures();
+                fclose(fp);
+                wait(0.1); // ????
+                state = ret > 0 ? READY : ERROR;
+            }
+        }
+    }
+
+    return state == PROCESSING || state == READY;
 }
 
-if(distance<2000){
-    motorStopR();
-    motorStopL();
-    stopUS015();
-    startsb612a();
+bool JPEGCamera::reset() {
+    char buf[4] = {0x56, 0x00, 0x26, 0x00};
+    int ret = sendReceive(buf, sizeof buf, 4);
+    if (ret == 4 && buf[0] == 0x76) {
+        wait(4.0);
+        state = READY;
+    } else {
+        state = ERROR;
+    }
+    return state == READY;
+}
+
+bool JPEGCamera::takePicture() {
+    char buf[5] = {0x56, 0x00, 0x36, 0x01, 0x00};
+    int ret = sendReceive(buf, sizeof buf, 5);
+
+    return ret == 5 && buf[0] == 0x76;
+}
+
+bool JPEGCamera::stopPictures() {
+    char buf[5] = {0x56, 0x00, 0x36, 0x01, 0x03};
+    int ret = sendReceive(buf, sizeof buf, 5);
+
+    return ret == 4 && buf[0] == 0x76;
+}
+
+int JPEGCamera::getImageSize() {
+    char buf[9] = {0x56, 0x00, 0x34, 0x01, 0x00};
+    int ret = sendReceive(buf, sizeof buf, 9);
+
+    //The size is in the last 2 characters of the response.
+    return (ret == 9 && buf[0] == 0x76) ? (buf[7] << 8 | buf[8]) : 0;
+}
+
+int JPEGCamera::readData(char *dataBuf, int size, int address) {
+    char buf[16] = {0x56, 0x00, 0x32, 0x0C, 0x00, 0x0A, 0x00, 0x00,
+                    address >> 8, address & 255, 0x00, 0x00, size >> 8, size & 255, 0x00, 0x0A
+                   };
+    int ret = sendReceive(buf, sizeof buf, 5);
+
+    return (ret == 5 && buf[0] == 0x76) ? receive(dataBuf, size, DATA_TIMEOUT) : 0;
+}
+
+int JPEGCamera::sendReceive(char *buf, int sendSize, int receiveSize) {
+    while (readable()) getc();
+
+    for (int i = 0; i < sendSize; i++) putc(buf[i]);
+
+    return receive(buf, receiveSize, RESPONSE_TIMEOUT);
+}
+
+int JPEGCamera::receive(char *buf, int size, int timeout) {
+    timer.start();
+    timer.reset();
+
+    int i = 0;
+    while (i < size && timer.read_ms() < timeout) {
+        if (readable())
+            buf[i++] = getc();
+    }
+
+    return i;
+}
+    LocalFileSystem local("local");
+
+Serial pc(USBTX,USBRX);
+Serial xbee(p13, p14);
+int main(void){
+    FILE *fp;
+    base64 *bs;
+    int c;
+    
+    xbee.printf("charizard!!!\r\n");
+    bs = new base64();
+    bs->Encode("/local/PICT000.jpg","/local/d.txt");
+    
+    
+   if((fp=fopen("/local/d.txt","r"))!=NULL)
+   {
+       while ((c=fgetc(fp))!=EOF){
+           xbee.printf("%c",c);
+       }
+       fclose(fp);
+   }
+   return 0;
+}
+
+            }else{//焦電反応なしの場合
+             detected=false;
+         thermo=0;
+         Ultra=1;
+             }
+           
+}
+  //while(true)
+  }
+  return 0;
+  }
+  
 //超音波センサー反応あり
 //停止
 //超音波センサーOFF
 //焦電センサーON
-  int main()
-{
-  float th;
-  Timer tm;
-  pc.printf("start\r\n");
-  led=0;
-  bool detected=false;
-  while(true)
-  {
-    th = thermo;
-    if(th==1 && !detected) {
-      led = 1;
-      detected=true;
-      pc.printf("human\r\n");
-      tm.reset();
-      tm.start();
-    }
-    if(tm.read_ms()>10000) {
-      printf("Time out!\r\n");
-      led = 0;
-      detected=false;
-    }
-  }
-}
-   if(detected=true){
-       stopsb612a();
-       startCamera();
-       stopCamera();
-       sendSD();
-       sendPC();
        
    //焦電センサー反応あり
    //焦電センサーOFF
    //カメラ起動
    //カメラOFF
-   //データをSDカードに保存
-   //保存データをXBeeによりPCへ送信
+   //XBeeによりPCへ送信
        if(receiveOK()=true){
            printf("Unknown Creature has been descovered!\n");
            }
@@ -185,12 +336,11 @@
        //"NO"受信、ミッション再開
 
     else if(detected=false){
-        stopsb612a();
-        motorForwardL();
-        motorStopL();
-        motorForwardR();
-        motorForwardL();
-        startUS015();
+        thermo=0;
+        left=100;
+        wait(3.0);
+        right=100;
+        Ultra=1;
         }
     } 
     //焦電センサー反応無し
@@ -200,12 +350,11 @@
     //直進
 }
 else if(distance>=2000){
-    motorStopL();
-    motorStopR();
-    motorForwardL();
-    motorStopL();
-    motorForwardR();
-    motorForwardL();
+    left=0;
+    right=0;
+    left=100;
+    wait(3.0);
+    right=100;
 }
 //超音波センサー反応無し
 //停止