Monday, June 27, 2011

Second Head

You may remember my previous effort to have a head track you using PIR sensors.

Well, it turns out the PIR sensors are great for detecting someone - at first. Then they are useless for 10 seconds. Which doesn't make them great for tracking. So I ended up giving up.

Then I was reading somewhere on the Interwebzors about someone trying to use a Bluetooth-enabled solid state gyro board for controlling a halloween head. I started thinking, there has to be an easier way. Then I thought about Synn Labs augmented reality work, and hit upon the idea: stick a fiduciary mark on your head:



The concept is simple: use ARToolkit to track the pan angle of a fiduciary mark, convert to serial data, send to Arduino, have the Arduino set the servo angle of the Robotzone DDP155 pan table.

Here is my tweak to ARToolkit's simpleLite.c example, a few lines I added to the "if (gPatt_found)" block of the "Display" function:

FILE *head=fopen("/dev/cu.usbserial-A4000QBg","w");
char head_turn=90-50*gPatt_trans[2][0];
fprintf(head,
"%c",head_turn);
printf(
"%d:%c:\n",head_turn,head_turn);
fclose(head);

And here is the short Arduino program:

#include <Servo.h>

Servo myservo;

void setup() {
myservo.attach(
9);
Serial.begin(
9600);
}

void loop() {
int value=40;
if (Serial.available() > 0)
{
value
= Serial.read(); //reads the incoming byte
myservo.write(value);
}
}



No comments: