Tuesday, August 11, 2009

Processing / Arduino Pseudo-code

Listed below is the gist of how my code functions. Hope it comes in handy, the rich text editor took away all the indentations, but the curly braces should help.


The processing aspect:

main
{
setup variables for
capture devices XY, YZ //two camera objects to track the position
brightest X, Y, Z //values to track which pixel is the brightest
myX, myY, myZ //user's position
serial port //for communicating with your arduino board

draw primitives //place objects in the world
get world cordinates of objects //store your objecrts' world cordinates as opposed to
//cordinates of their own transform matrix
//these will be used in the hit test function

}

loop
{
start capture devices //turn on both cameras and load images into buffer
load capture buffer into an array //must happen twice for each capture device
loop //from start to finish of array
{
set first pixel as brightest by default
move to next
compare each pixel to previous value and check if it is brighter
if yes
{
set new brightest value //myX, myY, myZ, depending on the plane
}
else
{
move to next
}

}

draw primitives //objects you want displayed in your world
//you will have to do this in a loop to keep refreshing their
//cordinates with respect to your movement

set camera values as myX, myY, myZ //the camera function in processing
//takes the following arguments as params (x,y,z, and eyeX, eyeY, eyeZ)
//x, y, z are the camera's world cordinates and eyeX, eyeY, eyeZ
//simply tell the camera where to look
//i just add a few pixels to myX, myY, myZ and set them as the eye values
//making the camera point forward


checkHit (myPos, myObjspos)
{
check to see if i am hittin and object
if yes
{
send trigger via serial port to arduino board
}
}
}


The arduino aspect:

main
{
setup variables for
serial port
pins for pager motors
}
loop
{
listen for trigger via serial port
if yes
{
set pin to high //this causes your glove to vibrate when
//the hittest function is triggerd
delay(1000) //wait for a second
set pin to low //turn off the motors again or else they'll keep vibrating
//don't worry if your glove hits something again, the motors will come back on
}

}

No comments:

Post a Comment