Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
Small request, can you post the code for the AVRcam processing sequence?
QuoteSmall request, can you post the code for the AVRcam processing sequence?Same request from me. Thanks in advance!
// Cam Related Variables// These needs to be written while reading bufferbyte objNum;byte objColour[8]; // Refer to sensordef.h// These are used by the robotic functionsboolean noObj;byte objXCenter[8];byte objYCenter[8];byte objWidth[8];byte objHeight[8];byte objSize[8]; // Average between width and height used for ranging purposesbyte objShape[8]; // 0 for null, 1 for square, 2 for tall, 3 for wideboolean objFound;byte objAtt; // in view and right shape and colourboolean objInterestFound;byte objInterested; // not the right shape, but right colour on the edge of viewbyte wantedColour = 1; // What colour you are looking forboolean waitACK(){ boolean incomeValid = true; while(Serial.available() < 4); if(Serial.read() != 65) { incomeValid = false; } if(Serial.read() != 67) { incomeValid = false; } if(Serial.read() != 75) { incomeValid = false; } if(Serial.read() != 13) { incomeValid = false; } return incomeValid;}void getObj(){ byte objXMin[8]; byte objXMax[8]; byte objYMin[8]; byte objYMax[8]; byte waittimeout = 0; byte temp; Serial.println("ET"); while(waitAck() == false) { Serial.println("ET"); } while((Serial.available() == 0) && (waittimeout != 10)) { delay(1); waittimeout++; } if(Serial.available() == 0) { noObj = true; objNum = 0; Serial.println("DT"); while(waitAck() == false) { Serial.flush(); Serial.println("DT"); } } else { temp = Serial.read(); // useless byte while(Serial.available() == 0); objNum = Serial.read(); noObj = false; } waittimeout = 0; if(noObj == false) { for(temp = 0; temp < objNum; temp++) { while(Serial.available() == 0); objColour[temp] = Serial.read(); while(Serial.available() == 0); objXMin[temp] = Serial.read(); while(Serial.available() == 0); objYMin[temp] = Serial.read(); while(Serial.available() == 0); objXMax[temp] = Serial.read(); while(Serial.available() == 0); objYMax[temp] = Serial.read(); } } Serial.println("DT"); delay(100); // there might be some junk left over, wait for finish // for robots who need constant servo pulses, replace delay with // for loops that sends the pulses for a similar amount of time // 100 is only an estimate Serial.flush(); // clear buffer objFound = false; objInterestFound = false; if(noObj == false) { for(temp = 0; temp < objNum + 1; temp++) { objWidth[temp] = objXMax[temp] - objXMin[temp]; objHeight[temp] = objYMax[temp] - objYMin[temp]; objXCenter[temp] = objXMin[temp] + (objWidth[temp] / 2); objYCenter[temp] = objYMin[temp] + (objWidth[temp] / 2); objShape[temp] = 0; if(similarTo(objWidth[temp], objHeight[temp])) { objShape[temp] = 1; } if(objShape[temp] != 1) { objShape[temp] = 2; if(objWidth[temp] > objHeight[temp]) objShape[temp] = 3; } objSize[temp] = averageWH(objWidth[temp], objHeight[temp]); if(objShape[temp] == 1) { if(objColour[temp] == wantedColour) { objAtt = temp; objFound = true; } } else { if(objColour[temp] == wantedColour) { objInterested = temp; objInterestFound = true; } } } }}
boolean similarTo(byte varAa, byte varBb) // used to compare length and width of objects to find shape{ float varA = varAa; float varB = varBb; boolean isSimilar = 0; if((varA < varB + (varA / 3)) && (varA > varB - (varA / 3))) { isSimilar = 1; } if((varB < varA + (varB / 3)) && (varB > varA - (varB / 3))) { isSimilar = 1; } return isSimilar;}boolean similarTo(int varAa, int varBb) // used to compare length and width of objects to find shape{ float varA = varAa; float varB = varBb; byte divider = 10; boolean isSimilar = 0; if((varA < varB + (varA / divider)) && (varA > varB - (varA / divider))) { isSimilar = 1; } if((varB < varA + (varB / divider)) && (varB > varA - (varB / divider))) { isSimilar = 1; } return isSimilar;}byte averageWH(byte varAa, byte varBb){ float varA = varAa; float varB = varBb; byte avgSize; varA = (varA + varB) / 2; avgSize = varA; return avgSize;}
it acts as an invisible wire, but only for digital signals (so only binary 0 and 1s, nothing in between), but it can't handle more than 2400 changes per second.ALSO you must change the input to the transmitter every second or else the receiver starts to output junk, apparently this is not needed if you run the transmitter at 12V, but I didn't try that yet.To use it for a serial connection, just connect the transmitter to the TX pin on your microcontroller, and the receiver to the RX pin on another microcontroller, and set the baud rate on both microcontrollers to 2400 baud.The black and white answer is Yes, but with the above limitations you must look out for.Dirt cheap compared to SparkFun, eh? Costs less than plain wire for that distance.