Custom version for NXP cup car
Revision 1:68bb92736e14, committed 2017-06-01
- Comitter:
- Clarkk
- Date:
- Thu Jun 01 13:17:03 2017 +0000
- Parent:
- 0:ccbc44580fab
- Commit message:
- Few changes
Changed in this revision
Vision.cpp | Show annotated file Show diff for this revision Revisions of this file |
Vision.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Vision.cpp Fri Mar 25 13:05:09 2016 +0000 +++ b/Vision.cpp Thu Jun 01 13:17:03 2017 +0000 @@ -13,6 +13,9 @@ { uint8_t i; + dataAge.reset(); + dataAge.start(); + for(i=0;i<128;i++) { lineData[i] = newData[i]; @@ -96,9 +99,28 @@ } } + result.leftEdgePosition = getPixelPosition(result.leftEdgeIndex); + result.rightEdgePosition = getPixelPosition(result.rightEdgeIndex); + + result.age = dataAge; + return result; } +struct Point Vision::getPixelPosition(uint8_t pixelIndex) +{ + struct Point position; +// lensToImageDistance = lensHeightFromFloor/cos(lensAngle) +// x = lensToImageDistance*(pixelSpace+pixelWidth)/focalDistance*(pixelIndex-63.5); +// x = 8.6396*(pixelindex-63.5); +// y = tan(lensAngle)*lensHeightFromFloor+wheelLensHorizontalDistance + + position.x = 8.6396*((float)pixelIndex-63.5); + position.y = 303.266; + + return position; +} + void Vision::lineScanLightAdjust() { uint8_t i; @@ -109,7 +131,7 @@ } } -void Vision::processTasks() +bool Vision::processTasks() { if(newDataToProcess) { @@ -119,7 +141,9 @@ currentRoadData = processLine(); newDataToProcess = false; //TFC_BAT_LED3_OFF; + return true; } + return false; } struct lineScanData Vision::getRoadData()
--- a/Vision.h Fri Mar 25 13:05:09 2016 +0000 +++ b/Vision.h Thu Jun 01 13:17:03 2017 +0000 @@ -3,11 +3,19 @@ #ifndef _VISION_H #define _VISION_H +struct Point { + float x; + float y; +}; + struct lineScanData { uint8_t mostWhiteIndex; uint16_t maxLightValue; uint8_t rightEdgeIndex; uint8_t leftEdgeIndex; + struct Point rightEdgePosition; + struct Point leftEdgePosition; + Timer age; }; class Vision @@ -15,7 +23,7 @@ public: Vision(); - void processTasks(); + bool processTasks(); void saveData(uint16_t* line); struct lineScanData processLine(); bool lightCompensation; @@ -26,7 +34,9 @@ uint16_t lineData[128]; bool newDataToProcess; struct lineScanData currentRoadData; + Timer dataAge; void lineScanLightAdjust(); + struct Point getPixelPosition(uint8_t pixelIndex); }; #endif \ No newline at end of file