Infrarood 3D scanner

Afgelopen weekend ben ik bezig geweest om het prototype voor een 3d scanner te ontwerpen en te bouwen.
Het principe achter de scanner is vrij simpel. Je neemt twee servo motortjes, een voor de x en een voor de y-as, en maakt hiermee een pan/tilt module.Daarna neem je een sharp afstandsensor en die bevestig je aan het pan/tiltding.

Het geheel knoop je aan een Arduino microcontroller.

Hieronder kun je de code vinden voor de Arduino microcontroller. De code werkt zowel op de Duemilanove alsook op de Mega (beiden zijn door mij getest)

#include

int stepsize=1;
Servo servobase;
Servo servotop;

void setup() {
Serial.begin(57600);
servobase.attach(2);
servotop.attach(3);
}

void loop()
{
int x,y;
for (y=90;y<180;y=y+stepsize)
{
servotop.write(y);
for (x=25;x<160;x=x+stepsize)
{
servobase.write(x);
delay(100);
Serial.print(x);
Serial.print(' ');
Serial.print(y);
Serial.print(' ');
Serial.println(probe(0));

}
}
}

int probe(int portnr)
{

int analogValue = analogRead(portnr);
return analogValue;
}

Met de programmeertaal processing (http://processing.org) kun je de data vrij simpel visualiseren. Daarvoor heb ik het volgende script gemaakt.

import processing.serial.*;

Serial myPort; // The serial port
int maxwidth=800;
int maxheight=400;
int x=0;
int xold,yold;

void setup() {

// List all the available serial ports:
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 57600);
myPort.write(65);
background(0);
size(maxwidth,maxheight);
noStroke();
colorMode(RGB, 1024);

}

void getData()
{
int lf = 10;
int sep=32;
int i=0; int x=0; int y=0;
int value=0;
int sum=0;
int col;
byte[] inBuffer = new byte[8];

myPort.readBytesUntil(sep, inBuffer);
if (inBuffer != null) {
String myString = new String(inBuffer);
myString=myString.substring(0,3);
//myString=int(myString);
x=int(myString.trim());

}

myPort.readBytesUntil(sep, inBuffer);
if (inBuffer != null) {
String myString = new String(inBuffer);
myString=myString.substring(0,myString.length()-5);
//myString=int(myString);
y=int(myString.trim())-90;

}

myPort.readBytesUntil(lf, inBuffer);
if (inBuffer != null) {
String myString = new String(inBuffer);
myString=myString.trim();
//myString=int(myString);
value=int(myString);

}
print(x);
print (',');
print(y);
print(',');
println(value);
fill(value,value,value);
ellipse(x*5-90,maxheight-(y*4)-10,5,4);

}

void draw() {
while (myPort.available() > 0) {
int value=0;
int lf = 10;
x=x+1;
if (x>100) {x=0; }
//Expand array size to the number of bytes you expect:
getData();

}
}