Michael Romain
/
coolcarsuperfast
Just trying to update ccode.
Fork of coolcarsuperfast by
Diff: main.cpp
- Revision:
- 7:6d5ddcf12cf3
- Parent:
- 5:20223464f7aa
- Child:
- 8:e126c900c89d
--- a/main.cpp Mon Mar 30 20:07:39 2015 +0000 +++ b/main.cpp Fri Apr 03 00:21:13 2015 +0000 @@ -1,6 +1,6 @@ #include "mbed.h" #include "stdlib.h" - +#include <vector> //Outputs DigitalOut led1(LED1); DigitalOut clk(PTD5); @@ -42,6 +42,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; @@ -273,16 +282,29 @@ break2 = 0; t.start(); - + printTimer.start(); //wait(5); while(1) { + //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; @@ -344,6 +366,8 @@ currDir = prevDir; } else { approxPos = (float)maxAccum/(float)maxCount; + lineCenters[loopCtr] = approxPos; + times[loopCtr] = printTimer.read_ms(); currDir = hardLeft + approxPos/((float) 127)*(hardRight-hardLeft); } @@ -387,7 +411,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"); }