Just trying to update ccode.

Dependencies:   mbed

Fork of coolcarsuperfast by E=MC

Revision:
8:e126c900c89d
Parent:
6:f1d948d2d6c1
Parent:
7:6d5ddcf12cf3
Child:
9:ad08181ad1cc
--- a/main.cpp	Tue Mar 31 22:56:01 2015 +0000
+++ b/main.cpp	Fri Apr 03 00:34:57 2015 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
 #include "stdlib.h"
-
+#include <vector>
 //Outputs
 DigitalOut led1(LED1);
 DigitalOut clk(PTD5);
@@ -41,6 +41,13 @@
 float currDir;
 float prevDir;
 
+// All linescan data for the period the car is running on. To be printed after a set amount of time
+//std::vector<std::vector<int> > frames;
+const int numData = 1000;
+int lineCenters [numData] = {0};
+int times [numData] = {0};
+int loopCtr = 0;
+
 //End of Line Tracking Variables -------------------------
 
 //Encoder and Motor Driver Variables ---------------------
@@ -72,6 +79,8 @@
 
 Timer t;
 Timer servoTimer;
+Timer printTimer; //after printTimer reaches a certain value the main loop will terminate and print the frames
+const float printTime = 5.0f;
 
 //Observed average speeds for each duty cycle
 const float DESIRED_SPEED = 1;
@@ -298,9 +307,34 @@
     break1 = 0;
     break2 = 0;
     
+
+    t.start();
+    printTimer.start();
+    //wait(5);
+
     while(1) {
-            
+
         if(integrationCounter % 151== 0){            
+
+        //break out of main loop if enough time has passed;    
+        if(loopCtr >= numData){
+            break;
+        }
+        if(integrationCounter % 151== 0){
+            //Disable interrupts
+            interrupt.fall(NULL);
+            interrupt.rise(NULL);
+          
+            /*
+            // copy frame into the vector to be printed  
+            std::vector<int> temp;
+            temp.reserve(128); //performance
+            for(int i=0; i<128; i++){
+                temp.push_back(ADCdata[i]);
+            }
+            frames.push_back(temp);
+            */
+
             //Send start of integration signal
             si = 1;
             clk = 1;
@@ -351,7 +385,9 @@
                 currDir = prevDir;
             } else {
                 approxPos = (float)maxAccum/(float)maxCount;
-                //approxPos = find_track(ADCdata);
+
+                lineCenters[loopCtr] = approxPos;
+                times[loopCtr] = printTimer.read_ms();
                 currDir = hardLeft + approxPos/((float) 127)*(hardRight-hardLeft);
             }
             
@@ -396,7 +432,20 @@
 
         //clk = 0;
         integrationCounter++;
+        loopCtr++;
         //camData.
         
     }
+    
+    //print frame data
+    pc.printf("printing frame data\n\r");
+    //int frameSize = frames.size();
+    //pc.printf("%i",frameSize);
+    pc.printf("[");
+    for(int i=0; i<numData; i++){
+        if(lineCenters > 0){
+            pc.printf("%i %i,",lineCenters[i], times[i]);
+        }
+    }
+    pc.printf("]\n\r");
 }