Michael Romain
/
coolcarsuperfast
Just trying to update ccode.
Fork of coolcarsuperfast by
Diff: main.cpp
- Revision:
- 10:e40ad924e935
- Parent:
- 9:ad08181ad1cc
diff -r ad08181ad1cc -r e40ad924e935 main.cpp --- a/main.cpp Fri Apr 03 05:06:01 2015 +0000 +++ b/main.cpp Mon Apr 06 19:28:45 2015 +0000 @@ -27,15 +27,18 @@ float maxVal; int maxLoc; +//Data Collection +bool dataCol = false; + //Line Crossing variables int prevTrackLoc; -int spaceThresh = 5; +int spaceThresh = 3; bool space; //Servo turning parameters float straight = 0.00155f; float hardLeft = 0.0010f; -float hardRight = 0.0021f; +float hardRight = 0.00195f; //Servo Directions float currDir; @@ -71,7 +74,7 @@ int numInterrupts = 0; -float pulsewidth = 0.15f; +float pulsewidth = 0.25f; // Hardware periods float motorPeriod = .0025; @@ -80,7 +83,6 @@ 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; @@ -307,31 +309,27 @@ break1 = 0; break2 = 0; - int loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime = 0; - t.start(); - printTimer.start(); - //wait(5); + //t.start(); + + if(dataCol){ + int loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime = 0; + printTimer.start(); + } while(1) { - //break out of main loop if enough time has passed; - if(loopCtr >= numData){ - break; + if(dataCol){ + //break out of main loop if enough time has passed; + if(loopCtr >= numData && dataCol){ + 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; @@ -378,21 +376,24 @@ } //Line Crossing Checks - if (maxCount >= 15 || space) { + if (space) { currDir = prevDir; } else { approxPos = (float)maxAccum/(float)maxCount; - if(loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime%3==0){ - lineCenters[loopCtr] = approxPos; - times[loopCtr] = printTimer.read_ms(); - loopCtr++; + if(dataCol){ + if(loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime%3==0){ + lineCenters[loopCtr] = approxPos; + times[loopCtr] = printTimer.read_ms(); + loopCtr++; + } } + currDir = hardLeft + approxPos/((float) 127)*(hardRight-hardLeft); } - + //Change speed when turning at different angles /*if(approxPos > 0 && approxPos <= 45){ motor1.pulsewidth(motorPeriod*(pulsewidth/2)); @@ -434,21 +435,24 @@ //clk = 0; integrationCounter++; - loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime++; + if(dataCol){ + loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime++; + } //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]); + if (dataCol){ + //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"); } - pc.printf("]\n\r"); }