Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MODSERIAL telemetry-master
Fork of coolcarsuperfast by
Diff: main.cpp
- Revision:
- 15:55e9fffc653a
- Parent:
- 14:888495814f3c
- Child:
- 16:79106efd7a57
--- a/main.cpp Thu Apr 09 21:05:01 2015 +0000 +++ b/main.cpp Fri Apr 10 00:35:16 2015 +0000 @@ -25,7 +25,7 @@ float maxCount; float approxPos; float prevApproxPos; -int trackWindow = 10; +int trackWindow = 30; int startWindow; int endWindow; float maxVal; @@ -42,14 +42,14 @@ //Line Crossing variables int prevTrackLoc; -int spaceThresh = 2; +int spaceThresh = 1; int widthThresh = 10; bool space; //Servo turning parameters float straight = 0.00155f; float hardLeft = 0.0011f; -float hardRight = 0.00185f; +float hardRight = 0.0021f; //float hardLeft = 0.0010f; //float hardRight = 0.00195f; @@ -88,7 +88,7 @@ int numInterrupts = 0; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PWM & Integration Time ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -float pulsewidth = 0; +float pulsewidth = 0.14f; int intTimMod = 0; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Hardware periods @@ -316,7 +316,7 @@ // Servo Initialization servo.period(servoPeriod); - + servo.pulsewidth(hardRight); wait(3); motor1.pulsewidth(motorPeriod*pulsewidth); @@ -384,10 +384,10 @@ } for (int c = 10; c < 118; c++) { - if (ADCdata[c] <= maxVal && maxVal - ADCdata[c] < 0.025f){ + if (ADCdata[c] <= maxVal && maxVal - ADCdata[c] < 0.007f){ maxAccum += c; maxCount++; - if (c > prevTrackLoc + spaceThresh){ + if (c > prevTrackLoc + spaceThresh || maxCount > widthThresh){ space = true; } prevTrackLoc = c; @@ -414,15 +414,12 @@ } for (int c = startWindow; c < endWindow; c++) { - if (ADCdata[c] <= maxVal && maxVal - ADCdata[c] < 0.025f){ + if (ADCdata[c] <= maxVal && maxVal - ADCdata[c] < 0.007f){ maxAccum += c; maxCount++; - if (c > prevTrackLoc + spaceThresh){ + if (c > prevTrackLoc + spaceThresh || maxCount > widthThresh){ space = true; } - if (maxCount > 60){ - firstTime = true; - } prevTrackLoc = c; } } @@ -441,13 +438,9 @@ //Line Crossing Checks if (space) { currDir = prevDir; - //firstTime = true; + firstTime = true; } else { - approxPos = (float)maxAccum/(float)maxCount - 10; - - if (approxPos < 0){ - approxPos = 0; - } + approxPos = (float)maxAccum/(float)maxCount; if(dataCol){ if(loopCounterForModdingSoThatWeCanIncreaseTheRecordingTime%3==0){ @@ -457,7 +450,7 @@ } } - currDir = hardLeft + (approxPos - 10)/((float) 108)*(hardRight-hardLeft); + currDir = hardLeft + (approxPos)/((float) 127)*(hardRight-hardLeft); prevApproxPos = approxPos; }