Hi,
So I have tweaked a piece of colour tracking processing code with the view to using it to control a stepper motor which will control a model which will point at a person that walks around it.
The code in processing compares the angle of the person's previous location with their current location thus giving me a degree change. I want to take this angle change and convert it to steps and send it via serial link to the arduino which will then tell the stepper how many steps to turn.
I am still very new to arduino and processing, so I am not quite sure how to approach this.
class CoordsCalc
{
CoordsCalc()
{
}
void update()
{
int currX = vidW;
int currW = 0;
boolean isYAssigned = false;
boolean isWAssigned = false;
for (int j = 0; j < coloursAssigned; j++)
{
currX = vidW;
currW = 0;
isYAssigned = false;
isWAssigned = false;
for (int i = 0; i < numPixels; i++)
{
colouredPixels[abs(i / vidW)][i % vidW] = 0;
color currColor = video.pixels[i];
currR = (currColor >> 16) & 0xFF;
currG = (currColor >> 8) & 0xFF;
currB = currColor & 0xFF;
if (isColourWithinRange(j))
{
noStroke();
if (isShowPixels)
{
fill(pixelColours[j]);
rect((i % vidW), (abs(i / vidW)), 1, 1);
rect((i % vidW) * rectDivide, (abs(i / vidW)) * rectDivide, 1 * rectDivide, 1 * rectDivide);
}
if ((i % vidW) < currX)
{
currX = i % vidW;
squareCoords[j][0] = currX;
}
if (!isYAssigned)
{
isYAssigned = true;
squareCoords[j][1] = abs(i / vidW);
}
squareCoords[j][3] = (abs(i / vidW)) - squareCoords[j][1] + 1;
if ((i % vidW) > currW)
{
currW = i % vidW;
isWAssigned = true;
}
}
if (i == numPixels - 1 && isWAssigned)
{
squareCoords[j][2] = currW - squareCoords[j][0] + 1;
}
}
}
for (int i = 0; i < coloursAssigned; i++)
{
centrePoints[i][0] = (squareCoords[i][0] * rectDivide) + ((squareCoords[i][2] * rectDivide) / 2);
centrePoints[i][1] = (squareCoords[i][1] * rectDivide) + ((squareCoords[i][3] * rectDivide) / 2);
fill(0, 0, 0);
ellipse(centrePoints[i][0], centrePoints[i][1], 50, 50);
bigX = centrePoints[i][0];
bigY = centrePoints[i][1];
if ((bigX<320)&&(bigY<240)) { //Square 1
tempX = 320-bigX;
tempY = 240-bigY;
currentAngle = (180 + (90-(degrees (atan(tempX/tempY)))));
println("SQ1");
//ARM
stroke(0, 0, 0);
strokeWeight(5);
pushMatrix();
translate(width/2, height/2);
//rotate(radians(180));
rotate(radians(currentAngle));
line(0, 0, 150, 0);
println("rotation:" + currentAngle);
//println("rotation:" + currentAngle);
//tempAngle = ((90-currentAngle)-previousAngle);
tempAngle = (currentAngle - previousAngle);
println("difference is: " + tempAngle);
//previousAngle = (90-currentAngle);
previousAngle = currentAngle;
popMatrix();
}
if ((bigX<320)&&(bigY>240)) { //Square 2
tempX = 320-bigX;
tempY = bigY-240;
currentAngle = (90 +(degrees (atan(tempX/tempY))));
println("SQ2");
//ARM
stroke(0, 0, 0);
strokeWeight(5);
pushMatrix();
translate(width/2, height/2);
//rotate(radians(90));
rotate(radians(currentAngle));
line(0, 0, 150, 0);
println("rotation:" + currentAngle);
tempAngle = (currentAngle - previousAngle);
println("difference is: " + tempAngle);
previousAngle = currentAngle;
popMatrix();
}
if ((bigX>320)&&(bigY>240)) { //Square 3
tempX = bigX-320;
tempY = bigY-240;
currentAngle = degrees (atan(tempY/tempX));
println("SQ3");
//ARM
stroke(0, 0, 0);
strokeWeight(5);
pushMatrix();
translate(width/2, height/2);
rotate(radians(currentAngle));
line(0, 0, 150, 0);
println("rotation:" + currentAngle);
tempAngle = (currentAngle - previousAngle);
println("difference is: " + tempAngle);
previousAngle = currentAngle;
popMatrix();
}
if ((bigX>320)&&(bigY<240)) { // Square 4
tempX = bigX-320;
tempY = 240-bigY;
currentAngle = (270 + (90-(degrees (atan(tempY/tempX)))));
println("SQ4");
//ARM
stroke(0, 0, 0);
strokeWeight(5);
pushMatrix();
translate(width/2, height/2);
//rotate(radians(270));
rotate(radians(currentAngle));
line(0, 0, 150, 0);
//println("rotation:" + (90-currentAngle));
println("rotation:" + currentAngle);
tempAngle = (currentAngle - previousAngle);
println("difference is: " + tempAngle);
//previousAngle = (90-currentAngle);
previousAngle = currentAngle;
popMatrix();
}
}
}
boolean isColourWithinRange(int j)
{
if (currR > (colourCompareData[j][0] + colourRange) || currR < (colourCompareData[j][0] - colourRange))
{
return false;
}
if (currG > (colourCompareData[j][1] + colourRange) || currG < (colourCompareData[j][1] - colourRange))
{
return false;
}
if (currB > (colourCompareData[j][2] + colourRange) || currB < (colourCompareData[j][2] - colourRange))
{
return false;
}
return true;
}
}
Basically tempAngle is my difference, how do I get this variable over to the arduino?
Thanks for reading.