![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
3rd year group project. Electronic and Electrical Engineering. Heriot-Watt University. This is the code for the mbed for the Automatic Little Object Organiser (ALOO).
Dependencies: MCP23017 TCS3472_I2C WattBob_TextLCD mbed
Diff: main.cpp
- Revision:
- 29:9c0339e3c593
- Parent:
- 28:7e4d29977d72
- Child:
- 30:c0bc92d009fe
--- a/main.cpp Tue Dec 01 20:54:26 2015 +0000 +++ b/main.cpp Tue Dec 01 22:56:08 2015 +0000 @@ -33,6 +33,7 @@ int blockCount = 0; bool lastBlockHaz = false; bool recievingResponse = false; +bool isBetweenHazValues[3] = false; Commander _commander = Commander(); Commander *commander = &_commander; @@ -341,9 +342,9 @@ if (connectedToPC) { for (int i = 0; i < 3; i++) { - pc.printf("DEBUG:Percentage Error: %.5f.\n", percentageError[i]); - if ((percentageError[i] < 0 && std::abs(percentageError[i]) < kMinError[i] * errorMultiplier) || percentageError[i] == 0 || (percentageError[i] > 0 && percentageError[i] < kMaxError[i] * errorMultiplier)) - pc.printf("DEBUG:%i Pass.\n", i); + pc.printf("DEBUG:Percentage Error: %.5f. Passed?: %i\n", percentageError[i], isBetweenHazValues[i]); +// if ((percentageError[i] < 0 && std::abs(percentageError[i]) < kMinRedError[i] * errorMultiplier) || percentageError[i] == 0 || (percentageError[i] > 0 && percentageError[i] < kMaxRedError[i] * errorMultiplier)) +// pc.printf("DEBUG:%i Pass.\n", i); } pc.printf("BLOCK:Size:%i,Red:%.3f,Green:%.3f,Blue:%.3f,Haz:%i, Offsetred:%.3f, Offsetgreen:%.3f, Offsetblue:%.3f;", blockSize, adjustedValues[0], adjustedValues[1], adjustedValues[2], lastBlockHaz, percentageError[0], percentageError[1], percentageError[2]); // pc.printf("VALUE:Size:%i,Red:%i,Green:%i,Blue:%i,Clear:%i\n:VALUE", blockSize, colourValues[0], colourValues[1], colourValues[2], colourValues[3], lastBlockHaz); @@ -389,7 +390,7 @@ lcd->cls(); lcd->locate(0,0); lcd->printf("Initilizing..."); - DefaultHazBlock(); +// DefaultHazBlock(); rgbSensor.enablePowerAndRGBC(); rgbSensor.setIntegrationTime(gIntegrationTime); srand((unsigned)time(NULL)); @@ -415,7 +416,7 @@ bool checkColour(int colourValues[]) { - bool isHazColour[3] = {false, false, false }; + isBetweenHazValues[3] = {false, false, false }; memset(adjustedValues, 0, sizeof(adjustedValues)); memset(percentageError, 0, sizeof(percentageError)); @@ -425,28 +426,32 @@ percentageError[i] = (adjustedValues[i] - kAverageRedBlock[i]) / kAverageRedBlock[i]; if ((percentageError[i] < 0 && std::abs(percentageError[i]) < kMinError[i] * 2) || percentageError[i] == 0 || (percentageError[i] > 0 && percentageError[i] < kMaxError[i] * 2)) { - isHazColour[i] = true; + isBetweenHazValues[i] = true; } } */ + /* for (int i = 0; i < 3; i++) { adjustedValues[i] = (float)colourValues[i]/(float)colourValues[3]; percentageError[i] = (adjustedValues[i] - kAverageRedBlock[i]) / kAverageRedBlock[i]; - + // Don't forget to call DefaultHazBlock in init otherwise currentMin/MaxErr won't be set. if ((percentageError[i] < 0 && std::abs(percentageError[i]) < currentMinError[i] * errorMultiplier) || percentageError[i] == 0 || (percentageError[i] > 0 && percentageError[i] < currentMaxError[i] * errorMultiplier)) { isHazColour[i] = true; } } + */ + for (int i = 0; i < 3; i++) { + adjustedValues[i] = (float)colourValues[i]/(float)colourValues[3]; + percentageError[i] = (adjustedValues[i] - kAverageValues[HazBlock->colour][i]) / kAverageValues[HazBlock->colour][i]; - // for (int i = 0; i < 3; i++) { - // if (colourValues[i] < HazBlock->maxColour.components[i] && colourValues[i] > HazBlock->minColour.components[i]) { - // isHazColour[i] = true; - // } - // } + if ((percentageError[i] < 0 && std::abs(percentageError[i]) < kMinError[HazBlock->colour][i] * errorMultiplier) || percentageError[i] == 0 || (percentageError[i] > 0 && percentageError[i] < kMaxError[HazBlock->colour][i] * errorMultiplier)) { + isBetweenHazValues[i] = true; + } + } bool isHazBlock = false; - if (isHazColour[0] && isHazColour[1] && isHazColour[2]) { + if (isBetweenHazValues[0] && isBetweenHazValues[1] && isBetweenHazValues[2]) { isHazBlock = true; } else { isHazBlock = false;